<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Vishal Mehta's weblog</title>
	<atom:link href="http://algoesalgo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://algoesalgo.wordpress.com</link>
	<description>my mental dump</description>
	<lastBuildDate>Fri, 05 Aug 2011 21:49:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='algoesalgo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Vishal Mehta's weblog</title>
		<link>http://algoesalgo.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://algoesalgo.wordpress.com/osd.xml" title="Vishal Mehta&#039;s weblog" />
	<atom:link rel='hub' href='http://algoesalgo.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Experiments with Postgis2.0 rasters</title>
		<link>http://algoesalgo.wordpress.com/2011/07/21/experiments-with-postgis2-0-rasters/</link>
		<comments>http://algoesalgo.wordpress.com/2011/07/21/experiments-with-postgis2-0-rasters/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 22:24:02 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[geodata]]></category>
		<category><![CDATA[geodata utilities]]></category>
		<category><![CDATA[Bangalore]]></category>
		<category><![CDATA[India]]></category>
		<category><![CDATA[postgis2.0]]></category>
		<category><![CDATA[postgresql9.0]]></category>
		<category><![CDATA[raster]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=99</guid>
		<description><![CDATA[These are  my notes on understanding/evaluating raster support in Postgis 2.0 . Platform Windows 7 PostgreSQL9.0 Postgis2.0 Key Resources Installation on Windows: Jorge Arevalo&#8217;s notes are key. (But expect &#8216;minor&#8217; variations based on your own system&#8217;s configurations, esp. with gdal) Loading rasters into postgis tables and getting some understanding of it Pierre Racine&#8217;s WKT Raster [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=99&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>These are  my notes on understanding/evaluating raster support in Postgis 2.0 .<strong></strong></p>
<h2>Platform</h2>
<ul>
<li>Windows 7</li>
<li>PostgreSQL9.0</li>
<li>Postgis2.0</li>
</ul>
<h2><strong><br />
Key Resources </strong></h2>
<ol>
<li>Installation on Windows:<a href="http://gis4free.wordpress.com/2011/03/10/how-to-install-and-configure-postgis-raster-on-windows/" target="_blank"><br />
Jorge Arevalo&#8217;s notes</a> are key. (But expect &#8216;minor&#8217; variations based on your own system&#8217;s configurations, esp. with gdal)</li>
<li>Loading rasters into postgis tables and getting some understanding of it
<ul>
<li><a href="http://trac.osgeo.org/postgis/wiki/WKTRasterTutorial01" target="_blank">Pierre Racine&#8217;s WKT Raster tutorial</a>  (Replace gdal2wktraster.py with raster2pgsql.py)</li>
<li><a href="http://gis4free.wordpress.com/2011/03/10/how-to-install-and-configure-postgis-raster-on-windows/" target="_blank">Jorge Arevalo&#8217;s notes</a></li>
<li><a href="http://fuzzytolerance.info/code/postgis-raster-ftw/" target="_blank">This example from Fuzzy Tolerance</a></li>
</ul>
</li>
<li>Working with postgis raster: intersections with vector datasets
<ul>
<li><a href="http://trac.osgeo.org/postgis/wiki/WKTRasterTutorial01" target="_blank">Pierre Racine&#8217;s WKT Raster tutorial</a></li>
<li><a href="http://fuzzytolerance.info/code/postgis-raster-ftw/" target="_blank">This example from Fuzzy Tolerance</a></li>
<li><a href="http://www.postgis.org/documentation/manual-svn/RT_reference.html" target="_blank">Postgis raster manual page<br />
</a></li>
</ul>
</li>
</ol>
<h2>1. Example data i used</h2>
<ul>
<li>SRTM for southern India downloaded from <a title="SRTM download from CGIAR" href="http://srtm.csi.cgiar.org/">here</a>, clipped in QGIS using gdaltools plugin, called srtm_clip.tif</li>
<li>A vector layer i had of administrative boundaries, called wards</li>
</ul>
<h2 style="text-align:justify;">2. Loading an elevation raster into Postgis2.0</h2>
<h3>a. Using <em>raster2pgsql.py</em>, in a command line, like so:</h3>
<blockquote><p>raster2pgsql.py -r srtm_clip.tif -s 4326 -I -t srtm_table -k 700&#215;700 -o srtm_clip.sql</p></blockquote>
<p>where</p>
<ul>
<li>srtm_clip.tif is the input elevation raster</li>
<li>4326 is the EPSG code for lat-long, wgs 84 coordinate system</li>
<li>-I tells it to make a spatial index</li>
<li>-k 700&#215;700 is the size of each tile to break the input raster into</li>
<li>srtm_sql is the output file that will contain the sql commands that creates the raster table in the database that has previously been set up</li>
</ul>
<h3>b.Load the sql file</h3>
<p>Use pgAdminIII&#8217;s sql editor to open the &#8216;srtm_clip.sql&#8217; the above step created, and run it.</p>
<p>FYI this is what the generated sql file looked like. (and i could not get the psql command line option for loading the sql file to work). It ran in less than a second.</p>
<blockquote><p><em>BEGIN;</em><br />
<em>CREATE TABLE &#8220;public&#8221;.&#8221;srtm_table&#8221; (rid serial PRIMARY KEY);</em><br />
<em>SELECT AddRasterColumn(&#8216;public&#8217;,'srtm_table&#8217;,'rast&#8217;,4326, ARRAY['16BSI'], false, true, null, 0.000833333333333, -0.000833333333333, 700, 700, ST_Envelope(ST_SetSRID(&#8216;POLYGON((77.256195534800000 13.681944121300001,77.256195534800000 12.561944121300002,78.131195534800000 13.681944121300001,78.131195534800000 12.561944121300002,77.256195534800000 13.681944121300001))&#8217;::geometry, 4326)));</em><br />
<em>INSERT INTO &#8220;public&#8221;.&#8221;srtm_table&#8221; ( rast ) VALUES ( (&#8217;01000001004F1BE8&#8230;.&#8217;)::raster );</em><br />
<em>INSERT INTO &#8220;public&#8221;.&#8221;srtm_table&#8221; ( rast ) VALUES ( (&#8217;01000001004F1BE8&#8230;.&#8217;)::raster );</em><br />
<em>INSERT INTO &#8220;public&#8221;.&#8221;srtm_table&#8221; ( rast ) VALUES ( (&#8217;01000001004F1BE8&#8230;.&#8217;)::raster );</em><br />
<em>INSERT INTO &#8220;public&#8221;.&#8221;srtm_table&#8221; ( rast ) VALUES ( (&#8217;01000001004F1BE8&#8230;.&#8217;)::raster );</em><br />
<em>CREATE INDEX &#8220;srtm_table_rast_gist_idx&#8221; ON &#8220;public&#8221;.&#8221;srtm_table&#8221; USING GIST (st_convexhull(rast));</em><br />
<em>END;</em></p></blockquote>
<h3>c. What do you get?</h3>
<ul>
<li>Refresh the database and you&#8217;ll see a new table called srtm_table.</li>
<li>It has two columns rid and rast, and 4 rows. each row is for a rid, which i guess is a tile id.</li>
<li>Each rid references one tile &#8211; choosing k=700&#215;700 caused the input raster to be split into 4 tiles</li>
<li>Smaller tiles are generally better &#8211; but i did run into one issue (you&#8217;ll see in just a bit)</li>
</ul>
<p>Viewing the tiles (in OpenJump, because Qgis 1.6 does not work with Postgis2.0, even for non-rasters).</p>
<div id="attachment_98" class="wp-caption alignnone" style="width: 293px"><a href="http://algoesalgo.files.wordpress.com/2011/07/tiles.jpg"><img class="size-medium wp-image-98" title="Tiles" src="http://algoesalgo.files.wordpress.com/2011/07/tiles.jpg?w=283&#038;h=300" alt="" width="283" height="300" /></a><p class="wp-caption-text">4 srtm tiles (overlaid over administrative boundaries)</p></div>
<ul>
<li>
<h3>Useful commands at this point</h3>
</li>
</ul>
<blockquote><p>&#8211; postgis versions<br />
select postgis_full_version(), postgis_raster_lib_build_date(), postgis_raster_lib_version();</p>
<p>&#8211; raster formats<br />
SELECT short_name, long_name<br />
FROM st_gdaldrivers();</p>
<p>&#8211;metadata<br />
SELECT (md).*, (bmd).*<br />
FROM (SELECT ST_Metadata(rast) AS md,<br />
ST_BandMetadata(rast) AS bmd<br />
FROM srtm_table LIMIT 1<br />
) foo;<br />
&#8211; no data value was not set even though i did put it into the QGIS-gdal plugin application</p>
<p>&#8211;size<br />
SELECT pg_size_pretty(pg_total_relation_size(&#8216;srtm_table&#8217;));<br />
&#8211;gives 1.8mb<br />
&#8211;<br />
&#8211;no-data value setting<br />
UPDATE srtm_table SET rast = ST_SetBandNoDataValue(rast,-32768);<br />
vacuum analyze srtm_table;</p>
<p>&#8211;summary stats (mean) of the raster</p>
<p>SELECT ST_Quantile(rast, 0.5) As value<br />
FROM srtm_table;<br />
&#8211; this seems to give me the median of each rid <strong>(but i want the median of the entire raster)</strong></p></blockquote>
<blockquote><p>1;886<br />
2;339<br />
3;857<br />
4;0</p></blockquote>
<h2>2. Intersecting raster with vector layers</h2>
<h3>a. performing the intersection</h3>
<p>This below worked, creating 70,503 rows<strong> &#8211; but it took 80 minutes!!!</strong></p>
<blockquote><p>create table srtm_wards_inter as<br />
select<br />
ward_name,ward_id, (gv).geom As the_geom,(gv).val<br />
FROM (Select ward_name, ward_id,ST_Intersection(rast,geom) As gv<br />
From srtm_table, wardscleanattributes<br />
WHERE geom &amp;&amp; rast<br />
and ST_Intersects(rast, geom)) foo;</p></blockquote>
<h3>b. extracting area-weighted mean elevations per ward polygon (sorted by mean elevation)</h3>
<blockquote><p> SELECT ward_id,ward_name,<br />
sum(ST_Area(ST_Transform(the_geom, 32643)) * val) /<br />
sum(ST_Area(ST_Transform(the_geom, 32643))) AS meanelev<br />
FROM srtm_wards_inter<br />
GROUP BY ward_id, ward_name<br />
ORDER BY meanelev, ward_id;</p></blockquote>
<p>&#8211;gives me the ward id&#8217;s, names and mean elevations for all 198 wards</p>
<blockquote><p>159;&#8221;Kengeri&#8221;;792.638912308088<br />
131;&#8221;Nayandahalli&#8221;;821.362355078139<br />
130;&#8221;Ullalu&#8221;;828.12323070928<br />
198;&#8221;Hemmigepura&#8221;;831.628739711782<br />
&#8230;<br />
67;&#8221;Nagapura&#8221;;921.610375368031<br />
46;&#8221;Jayachamarajendra Nagar&#8221;;922.392379372865<br />
179;&#8221;Shakambarinagar&#8221;;922.91608088907<br />
62;&#8221;Ramaswamy Palya&#8221;;923.071218071726<br />
9;&#8221;Vidyaranyapura&#8221;;923.304108544661<br />
16;&#8221;Jalahalli&#8221;;924.921270389213<br />
63;&#8221;Jayamahal&#8221;;926.957157345059<br />
93;&#8221;Vasanthnagar&#8221;;928.315490103474<br />
194;&#8221;Gottigere&#8221;;931.443435808278<br />
34;&#8221;Gangenahalli&#8221;;932.719869810253<br />
45;&#8221;Malleshwaram&#8221;;932.814742613641<br />
35;&#8221;Aramanenagar&#8221;;935.117666378835</p></blockquote>
<h2>Major Questions</h2>
<ol>
<ol>
<ol>
<li>Why did the intersection take so long (see 2a above)</li>
<li>How can i get raster statistics irrespective of rid?</li>
</ol>
<ol>
<ol>
<ol>
<li>example: quantile stats for the raster are split by rid (i.e tile)</li>
<li>example: if i get median elevation by ward like so:</li>
<ol>SELECT ward_id,ward_name,ST_Quantile(rast,0.5) As median</ol>
</ol>
</ol>
</ol>
</ol>
</ol>
<ol>
<ol>
<ol>
<ol>
<ol>
<ol>    FROM srtm_table,wardscleanattributes</ol>
</ol>
</ol>
</ol>
</ol>
</ol>
<ol>
<ol>
<ol>
<ol>
<ol>
<ol>        WHERE ST_Intersects(rast,geom)</ol>
</ol>
</ol>
</ol>
</ol>
</ol>
<ol>
<ol>
<ol>
<ol>
<ol>
<ol>ORDER BY ward_id, median;</ol>
</ol>
</ol>
</ol>
</ol>
</ol>
<p>I STILL get multiple entries per ward, if (i) the ward crosses two or more rid (tiles), or (ii) the ward is split into 2 polygons</p>
<p>If anyone can help with the above, I can update my post soon.<br />
Thanks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=99&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2011/07/21/experiments-with-postgis2-0-rasters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2011/07/tiles.jpg?w=283" medium="image">
			<media:title type="html">Tiles</media:title>
		</media:content>
	</item>
		<item>
		<title>GHCN data in a Postgis database</title>
		<link>http://algoesalgo.wordpress.com/2010/05/05/ghcn-data-in-a-postgis-database/</link>
		<comments>http://algoesalgo.wordpress.com/2010/05/05/ghcn-data-in-a-postgis-database/#comments</comments>
		<pubDate>Wed, 05 May 2010 18:35:33 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[geodata]]></category>
		<category><![CDATA[geodata utilities]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[climate]]></category>
		<category><![CDATA[GHCN]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[Uganda]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=82</guid>
		<description><![CDATA[Goal I&#8217;m continuing my experiments with postgresql/postgis databases, using the Global Historical Climate Network (GHCN v2)  dataset of monthly precipitation and temperature data from around the world. I&#8217;m going to create and query a database out of GHCN data, downloaded here on May 4, 2010. Tips Read the metadata on the site, because the format [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=82&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Goal</h1>
<p>I&#8217;m continuing my experiments with postgresql/postgis databases, using the Global Historical Climate Network (GHCN v2)  dataset of monthly precipitation and temperature data from around the world. I&#8217;m going to create and query a database out of GHCN data, downloaded <a title="GHCN data from NCDC" href="ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/v2/" target="_blank">here</a> on May 4, 2010.</p>
<h2>Tips</h2>
<p>Read the metadata on the site, because the format is a bit tedious.The main things to note are:</p>
<ul>
<li>i had to convert the station list table v2.precip.inv to a csv file before i could copy it into a postgres table</li>
<li>i had to import the ~80Mb datafile (v2.prcp) as a postgres table of text rows, and then parse the actual columns out (see sql below) into a new table</li>
<li>the code in the stations list table has one digit less than that in the data table &#8211; a code for whether there are data duplicates or not (read the metadata file online)</li>
<li>i&#8217;ve used the raw data here. there is a separate quality-controlled table of data that is MUCH smaller &#8211; i have not used that here.</li>
<li>-9999 represents null data, -8888 respresents trace precipitation</li>
</ul>
<h2>Code</h2>
<p>&#8211;create GHCN station table</p>
<p>&#8211; drop table ghcn_stations;</p>
<p style="padding-left:30px;">create table ghcn_stations (code numeric primary key not null, name varchar(40), country varchar(25), latitude float, longitude float, elevation integer) with OIDS;</p>
<p>&#8211;load from text file</p>
<p style="padding-left:30px;">copy ghcn_stations FROM &#8216;E:/gisdata/World/GHCNv2/v2.prcp.inv.csv&#8217; CSV;</p>
<p>&#8211;select stations in Uganda</p>
<p style="padding-left:30px;">select * from ghcn_stations where country = &#8216;UGANDA&#8217;;</p>
<p>&#8211;make a geometry column out of lat and longitude</p>
<p style="padding-left:30px;">Alter table ghcn_stations add column the_geom geometry;</p>
<p>&#8211;populate with lat and long and 4326 srid</p>
<p style="padding-left:30px;">Update ghcn_stations</p>
<p style="padding-left:30px;">SET the_geom = PointFromText(&#8216;Point(&#8216;||longitude||&#8221;||latitude||&#8217;)',4326);</p>
<p><strong>&#8211;above did not work</strong></p>
<p style="padding-left:30px;">Update ghcn_stations</p>
<p style="padding-left:30px;">SET the_geom = ST_Point(longitude,latitude);</p>
<p><strong>&#8211;above worked but srid not yet set</strong></p>
<p style="padding-left:30px;">Update ghcn_stations</p>
<p style="padding-left:30px;">SET the_geom = St_SETSRID(the_geom,4326);</p>
<p>&#8211;above set the SRID</p>
<p>&#8211;</p>
<p>&#8211;now add spatial index</p>
<p style="padding-left:30px;">create index idx_ghcn_stations on ghcn_stations using GIST(the_geom);</p>
<p style="padding-left:30px;">VACUUM ANALYZE;</p>
<p>&#8211;test out how to extract select characters from a numeric field, below worked</p>
<p style="padding-left:30px;">select country, substring(cast(code as text) from 1 for 5)) from ghcn_stations</p>
<p style="padding-left:30px;">where country = &#8216;UGANDA&#8217; OR country = &#8216;TANZANIA&#8217; or country = &#8216;KENYA&#8217;;</p>
<p>&#8211;load from text file</p>
<p style="padding-left:30px;">copy precip FROM &#8216;E:/gisdata/World/GHCNv2/v2.prcp.csv&#8217;;</p>
<p>&#8211;does not work well, reading each line as one long text string</p>
<p>&#8211;also could not load big file in excel to convert to csv</p>
<p>&#8211;so tried reading it as individual text lines to parse later</p>
<p style="padding-left:30px;">select * from precip limit 5;</p>
<p style="padding-left:30px;">select substring(codeyr from 1 for 16) from precip limit 10;&#8211;this extracts the station code and year i.e. column1</p>
<p style="padding-left:30px;">select substring(codeyr from 17 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of jan</p>
<p style="padding-left:30px;">select substring(codeyr from 22 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of feb</p>
<p style="padding-left:30px;">select substring(codeyr from 27 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of mar</p>
<p style="padding-left:30px;">select substring(codeyr from 32 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of apr</p>
<p style="padding-left:30px;">select substring(codeyr from 37 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of may</p>
<p style="padding-left:30px;">select substring(codeyr from 42 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of jun</p>
<p style="padding-left:30px;">select substring(codeyr from 47 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of july</p>
<p style="padding-left:30px;">select substring(codeyr from 52 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of aug</p>
<p style="padding-left:30px;">select substring(codeyr from 57 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of sep</p>
<p style="padding-left:30px;">select substring(codeyr from 62 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of oct</p>
<p style="padding-left:30px;">select substring(codeyr from 67 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of nov</p>
<p style="padding-left:30px;">select substring(codeyr from 72 for 5)::numeric from precip limit 100;&#8211;this extracts i think the month of dec</p>
<p>&#8211; so now create a new table with the data parsed right</p>
<p style="padding-left:30px;">create table newprecip as</p>
<p style="padding-left:30px;">select substring(codeyr from 1 for 11)::numeric as code,</p>
<p style="padding-left:30px;">substring(codeyr from 12 for 1)::integer as duplicates,</p>
<p style="padding-left:30px;">substring(codeyr from 13 for 4)::integer as year,</p>
<p style="padding-left:30px;">substring(codeyr from 17 for 5)::integer as m1,</p>
<p style="padding-left:30px;">substring(codeyr from 22 for 5)::integer as m2,</p>
<p style="padding-left:30px;">substring(codeyr from 27 for 5)::integer as m3,</p>
<p style="padding-left:30px;">substring(codeyr from 32 for 5)::integer as m4,</p>
<p style="padding-left:30px;">substring(codeyr from 37 for 5)::integer as m5,</p>
<p style="padding-left:30px;">substring(codeyr from 42 for 5)::integer as m6,</p>
<p style="padding-left:30px;">substring(codeyr from 47 for 5)::integer as m7,</p>
<p style="padding-left:30px;">substring(codeyr from 52 for 5)::integer as m8,</p>
<p style="padding-left:30px;">substring(codeyr from 57 for 5)::integer as m9,</p>
<p style="padding-left:30px;">substring(codeyr from 62 for 5)::integer as m10,</p>
<p style="padding-left:30px;">substring(codeyr from 67 for 5)::integer as m11,</p>
<p style="padding-left:30px;">substring(codeyr from 72 for 5)::integer as m12</p>
<p style="padding-left:30px;">from precip</p>
<p style="padding-left:30px;">;</p>
<p>&#8211;check first 12 rows, looks ok</p>
<p style="padding-left:30px;">select * from newprecip limit 12;</p>
<p style="padding-left:60px;"><em>code|duplicates|year|m1|m2|m3|m4|m5|m6|m7|m8|m9|m10|m11|m12|gid<br />
20743086004|1|1962|0|0|0|833|0|663|3005|1658|2470|419|548|786|1<br />
20743086004|1|1963|0|0|0|-9999|-9999|-9999|1061|2422|-9999|736|0|0|2<br />
20743086004|1|1964|0|0|0|0|0|971|-9999|1963|-9999|86|20|0|3<br />
20743086004|1|1965|0|0|38|84|0|450|2039|1397|1896|0|0|0|4<br />
20743086004|1|1966|1194|0|30|73|128|1011|5265|2544|3710|981|780|240|5<br />
20743086004|1|1967|60|0|380|0|0|2020|3310|2161|1641|0|0|887|6<br />
20743086004|1|1968|340|150|10|30|100|1046|3319|893|2096|729|70|60|7<br />
20743086004|1|1969|330|0|30|0|270|1100|2209|1647|3933|140|150|160|8<br />
20743086004|1|1970|215|0|-9999|40|520|2014|1325|1734|1748|116|0|0|9<br />
20743086005|1|1951|0|0|610|38|259|1473|2974|2136|1186|424|0|0|10<br />
20743086005|1|1952|155|0|10|107|102|889|2532|1994|2624|396|0|0|11<br />
20743086005|1|1953|165|0|0|356|0|4389|3406|5570|3129|922|0|0|12</em></p>
<p>&#8211; add primary key note that it needs to be unique so i have to add a serial first</p>
<p style="padding-left:30px;">alter table newprecip add column gid serial not null;</p>
<p style="padding-left:30px;">create unique index uidx_newprecip_gid on newprecip using btree(gid);</p>
<p>&#8211;</p>
<p style="padding-left:30px;">alter table newprecip add constraint</p>
<p style="padding-left:30px;">pkey__newprecip_code PRIMARY KEY(gid);</p>
<p>&#8211;try out some select queries like extracting data for Masaka, Uganda</p>
<p style="padding-left:30px;">select newprecip.*, ghcn_stations.name, ghcn_stations.code</p>
<p style="padding-left:30px;">from</p>
<p style="padding-left:30px;">ghcn_stations join newprecip</p>
<p style="padding-left:30px;">on ghcn_stations.code = newprecip.code</p>
<p style="padding-left:30px;">where ghcn_stations.country = &#8216;UGANDA&#8217;</p>
<p style="padding-left:30px;">order by name;</p>
<p>&#8211;lets try and extract the min and max year of available data</p>
<p style="padding-left:30px;">select ghcn_stations.name,min(newprecip.year) as minyr, max(newprecip.year) as maxyr</p>
<p style="padding-left:30px;">from newprecip, ghcn_stations</p>
<p style="padding-left:30px;">where ghcn_stations.country = &#8216;UGANDA&#8217;</p>
<p style="padding-left:30px;">and newprecip.code = ghcn_stations.code</p>
<p style="padding-left:30px;">group by ghcn_stations.name</p>
<p style="padding-left:30px;">order by maxyr DESC, name;</p>
<p>&#8211; but MASAKA in Uganda does not appear in this list&#8230;why?</p>
<p>&#8211; maybe the codes in the 2 tables that i use to join above dont match?</p>
<p style="padding-left:30px;">select ghcn_stations.code as code1</p>
<p style="padding-left:30px;">from ghcn_stations</p>
<p style="padding-left:30px;">where ghcn_stations.name= &#8216;MASAKA&#8217;;</p>
<p>&#8211;</p>
<p style="padding-left:30px;">select * from ghcn_stations</p>
<p style="padding-left:30px;">where name = &#8216;MASAKA&#8217;;</p>
<p>&#8211; both of the above find Masaka</p>
<p><strong>&#8211; BUT the country name is missing for MASAKA in the ghcn_stations table</strong></p>
<p>&#8211; so lets add it</p>
<p style="padding-left:30px;">update ghcn_stations</p>
<p style="padding-left:30px;">set country = &#8216;UGANDA&#8217; where code = 15363705001;</p>
<p style="padding-left:30px;">&#8211;</p>
<p style="padding-left:30px;">VACUUM ANALYZE;</p>
<p>&#8211;now repeat earlier query</p>
<p>&#8211;lets try and extract the min and max year of available data</p>
<p style="padding-left:30px;">select ghcn_stations.name,min(newprecip.year) as minyr, max(newprecip.year) as maxyr</p>
<p style="padding-left:30px;">from newprecip, ghcn_stations</p>
<p style="padding-left:30px;">where ghcn_stations.country = &#8216;UGANDA&#8217;</p>
<p style="padding-left:30px;">and newprecip.code = ghcn_stations.code</p>
<p style="padding-left:30px;">group by ghcn_stations.name</p>
<p style="padding-left:30px;">order by name;</p>
<p style="padding-left:90px;"><em>name|minyr|maxyr<br />
ADUKA|1940|1985<br />
AGORO|1940|1983<br />
ARUA|1940|1992<br />
BUHUKA|1940|1978<br />
BULISA|1940|1985<br />
BUNDIBUGYO|1940|1975<br />
BUNYARUGURU|1940|1975<br />
BUSENYI|1940|1985<br />
BUSIKA|1940|1985<br />
BUTIABA|1904|1979<br />
BUTITI|1940|1985<br />
BWIJANGA|1940|1985<br />
ENTEBBE AIRPORT|1896|2000<br />
FT.PORTAL/SEBUTOLE|1903|1980<br />
GULU|1911|2000<br />
IHUNGU|1940|1984<br />
JINJA|1902|1992<br />
KABALE|1917|1996<br />
KABERAMAINDO|1940|1985<br />
KAKOGE|1940|1975<br />
KALANGALA|1926|1977<br />
KAMPALA|1912|1992<br />
KAPIRI|1940|1992<br />
KASESE|1972|1992<br />
KATAKWI|1927|1984<br />
KAZIBA|1940|1975<br />
KISOMORO|1940|1976<br />
KITGUM V.T.C|1914|1995<br />
KITWE|1940|1975<br />
KOTIDO|1940|1985<br />
KYENJOJO|1940|1982<br />
LIRA NGETTA|1940|1992<br />
LUGANZI|1940|1982<br />
MAGYO|1940|1985<br />
MASAFU|1940|1983<br />
MASAKA|1902|1945<br />
MASINDI|1940|1992<br />
MATIRI|1940|1985<br />
MATUNGA|1940|1992<br />
MBALE|1908|1996<br />
MBARARA|1903|1996<br />
MITYAMA|1940|1985<br />
MOYO|1940|1980<br />
MPUGWE|1940|1985<br />
MUKONO|1940|1985<br />
MUTUNGA|1940|1985<br />
NAMASAGALI/B.GOMBOLO|1915|1979<br />
NAMULONGE|1961|1992<br />
NAMWIWA|1940|1980<br />
NGORA|1940|1982<br />
NTWETWE|1940|1984<br />
SERERE|1940|1985<br />
TORORO|1961|1992<br />
WOBULENZI|1940|1979</em></p>
<p><strong>&#8211; YES! Masaka is there now. </strong>Note that Masaka has data only between 1902 and1945&#8230;</p>
<p>&#8211; Keep in mind that this was only a particular fix.</p>
<p>&#8211; There are many null values in the countries field of the original GHCN v2 stations table</p>
<p><strong>&#8211; TO DO: </strong>these should ideally be filled by a spatial point-in-polygon process&#8230;</p>
<p>&#8211; &#8230;with the help of a countries (multi)polygon spatial table&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=82&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2010/05/05/ghcn-data-in-a-postgis-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>
	</item>
		<item>
		<title>Experiments with Postgis</title>
		<link>http://algoesalgo.wordpress.com/2010/04/26/experiments-with-postgis/</link>
		<comments>http://algoesalgo.wordpress.com/2010/04/26/experiments-with-postgis/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 00:37:26 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[geodata]]></category>
		<category><![CDATA[geodata utilities]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[Yolo county]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=67</guid>
		<description><![CDATA[Notes on Postgis These are some of my notes in attempting to create a geodatabase using Postgis, for Yolo county, California. 1. Platform Windows XP PostgreSQL8.3 Postgis1.5 2. Create a new database Used the GUI to create a new database called &#8216;yolocounty&#8217; encoding UTF8 could not use  template_postgis (another database was using it) so ran [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=67&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Notes on Postgis</h1>
<p>These are some of my notes in attempting to create a geodatabase using Postgis, for Yolo county, California.<strong><br />
</strong></p>
<h2>1. Platform</h2>
<ul>
<li>Windows XP</li>
<li>PostgreSQL8.3</li>
<li>Postgis1.5</li>
</ul>
<h2 style="text-align:justify;">2. Create a new database</h2>
<ul>
<li>Used the GUI to create a new database called &#8216;yolocounty&#8217;
<ul>
<li>encoding UTF8</li>
<li>could not use  template_postgis (another database was using it)</li>
<li>so ran sql scripts &#8216;postgis.sql&#8217;, &#8216;spatial_ref_system.sql&#8217; and &#8216;comments.sql&#8217;</li>
</ul>
</li>
</ul>
<h2>3. Creating database tables for GIS layers</h2>
<h3>Tasks:</h3>
<ol>
<li>Load several GIS layers for California from shapefiles, each in different projections.</li>
<li>Re-project individual files to one consistent projection (EPSG: 3488, California Albers)</li>
<li>Create specific overlays and spatial joins</li>
</ol>
<h3>1. counties</h3>
<p style="padding-left:30px;">loading counties boundary shapefile to table &#8216;counties&#8217; :</p>
<blockquote>
<ul>
<li>used <strong><em>shp2pgsql </em></strong>piped to<strong><em> psql </em></strong>to create table called counties<strong><em><br />
</em></strong></li>
<li>its in Lat Long WGS 84 (EPSG:4326)<strong><em><br />
</em></strong></li>
</ul>
</blockquote>
<blockquote><p><strong><em>shp2pgsql -s 4326 -I -D -g the_geom &#8220;E:/xxx/yyy/zzz.shp&#8221; counties | psql -U </em></strong>user<strong> <em>-h</em> </strong>host<strong> <em>- p</em> port -<em>d yolocounty</em></strong></p></blockquote>
<blockquote>
<ul>
<li>the many flags are useful &#8211; check online for their meaning<strong><em><br />
</em></strong></li>
<li>example:<a title="useful link" href="http://casoilresource.lawr.ucdavis.edu/drupal/node/266" target="_blank"> http://casoilresource.lawr.ucdavis.edu/drupal/node/266</a></li>
<li>succesfully connected to database and visualized in UDig.</li>
</ul>
</blockquote>
<h3>2.  Groundwater basins</h3>
<blockquote>
<ul>
<li>used <strong><em>shp2pgsql </em></strong>piped to<strong><em> psql </em></strong>to create table called <em><strong>pa</strong></em><strong><em><br />
</em></strong></li>
<li>its in UTM 10N NAD 27 (EPSG:26710)<strong><em><br />
</em></strong></li>
</ul>
</blockquote>
<blockquote><p><strong><em>shp2pgsql -s 26710 -I -D -g the_geom E:/xxx/yyy/zzz.shp gwbasins | psql -U </em></strong>user<strong> <em>-h</em> </strong>host<strong> -<em>d yolocounty</em></strong></p></blockquote>
<h3 style="text-align:left;">3. DWR Planning Areas</h3>
<blockquote>
<blockquote>
<ul>
<li>used <strong><em>shp2pgsql </em></strong>piped to<strong><em> psql </em></strong>to create table called <em><strong>pa</strong></em><strong><em><br />
</em></strong></li>
<li>its in UTM 11N WGS 84(EPSG:32611)</li>
</ul>
</blockquote>
<p><strong><em>shp2pgsql -s 32611 -I -D -g the_geom E:/xxx/yyy/zzz.shp PA | psql -U </em></strong>user<strong> <em>-h</em> </strong>host<strong> -<em>d yolocounty</em></strong></p></blockquote>
<h3>4. DWR Hydrologic Regions</h3>
<blockquote>
<ul>
<li>Same procedure as for Planning Areas above</li>
<li>saved as table <strong><em>HR</em></strong></li>
</ul>
</blockquote>
<h3>5.  California Dams</h3>
<blockquote>
<ul>
<li>Same procedure as above, original data in EPSG 4269 (NAD 83, Latlong)</li>
<li>saved as table <em><strong>dams</strong></em></li>
</ul>
</blockquote>
<h3>6. major rivers</h3>
<blockquote>
<ul>
<li>Same procedure as above, original data in EPSG 4269</li>
<li>saved as table <em><strong>rivers</strong></em></li>
</ul>
</blockquote>
<li>
<h3><em><strong>7. non rivers</strong></em></h3>
<blockquote>
<ul>
<li>Same procedure as above, original data in EPSG 4269</li>
<li>saved as table <em><strong>non rivers</strong></em></li>
</ul>
</blockquote>
</li>
<p>Now I&#8217;ll perform some common geoprocessing tasks using these layers. Its best to pose some questions we want to ask. Here&#8217;s a list of plausible qns one might want to ask of this database.</p>
<h2>Questions</h2>
<p>a) How many counties are within or intersect the Sacramento Valley Hydrologic Region? What are their names?</p>
<p>b) What are the dams within Yolo, Solano and Lake counties?</p>
<p>c) How many Planning Areas are within the Sacramento Valley Hydrologic Region? What are their names?</p>
<p>d) How many Planning Areas and Hydrologic Regions does Yolo county span?</p>
<h2>Solutions</h2>
<p>First, we have to reproject all the data to a common projections. I chose California Albers, which is EPSG 3488:</p>
<blockquote>
<h3>﻿Reprojecting each layer to EPSG 3488</h3>
<p>We can add a transformed geometry column to existing spatial tables, using <em><strong>ST_TRANSFORM :<br />
</strong></em></p>
<p><em><strong>ALTER TABLE counties ADD column geom_albers geometry;</strong></em></p>
<p><em><strong>UPDATE counties SET geom_albers = ST_TRANSFORM(the_geom,3488);</strong></em></p>
<p>Now check for the transformed SRID :</p>
<p><strong><em>SELECT ST_SRID(geom_albers) from counties</em></strong>;</p>
<p>returns 3488 so ok.</p>
<p>Can also check for the original geometry column:</p>
<p>﻿<em><strong>SELECT ST_SRID(the_geom) from counties;</strong></em></p>
<p>returns 4326. this shows that 2 projections can exist for the same geometry.</p>
<p>Now repeat the transformation for the other layers.</p></blockquote>
<h3>a) How many counties are within or intersect the Sacramento Valley Hydrologic Region? What are their names?</h3>
<blockquote><p>A table of Sacramento River HR and intersecting counties can be generated :</p>
<blockquote><p><em><strong>SELECT hr_name, name</strong></em></p>
<p><em><strong>FROM hr, counties<br />
WHERE ST_Intersects(hr.geom_albers,counties.geom_albers)</strong></em></p>
<p><em><strong>AND hr.hr_name = &#8216;Sacramento River&#8217;;</strong></em></p></blockquote>
<p><span style="color:#800000;">However<em>, it seems to include counties like Mendocino that merely touch the Sacramento River HR on the outside&#8230;</em></span>﻿</p>
<p>27 counties touch the Sac R. HR</p>
<p>The same result is produced with an <strong><em>INNER JOIN</em></strong> <strong>:</strong></p>
<blockquote><p><em><strong>SELECT hr_name, name<br />
FROM counties inner join hr on<br />
ST_Intersects(hr.geom_albers,counties.geom_albers)<br />
Where hr.hr_name = &#8216;Sacramento River&#8217;;</strong></em></p></blockquote>
</blockquote>
<p>Lets take this a little further, namely</p>
<p>1. create a new spatial table out of this intersection (the above is just a tabulation)</p>
<p style="padding-left:30px;"><strong><em>CREATE TABLE AS hru_counties<br />
SELECT hr.hr_name as hr_name,counties.name as countyname,<br />
ST_Intersection(hr.geom_albers,counties.geom_albers) as geom_albers, ROUND(ST_AREA(ST_Intersection(hr.geom_albers,counties.geom_albers))/1000000,0) as area<br />
FROM hr, counties<br />
WHERE ST_Intersects(hr.geom_albers,counties.geom_albers)<br />
AND hr_hrname = &#8216;Sacramento River&#8217;;</em></strong></p>
<p>2. add indices so that it can be viewed in conventional GIS viewere (that need an OID)</p>
<p style="padding-left:60px;"><strong><em>&#8211; creating a serial index needed for viewing in regular GIS viewers<br />
</em></strong></p>
<p style="padding-left:60px;"><strong><em>ALTER table sac_counties ADD Column gid serial not null;<br />
CREATE UNIQUE INDEX uidx_sac_counties_gid on sac_counties using btree(gid);</em></strong></p>
<p style="padding-left:60px;"><strong><em>&#8211;creating a primary key on gid, note that this is deprecated (but works for now)<br />
</em></strong></p>
<p style="padding-left:60px;"><strong><em>ALTER table sac_counties ADD Constraint pkey_sac_counties_gid PRIMARY KEY(gid);</em></strong></p>
<p style="padding-left:60px;"><strong><em>&#8211;creating a spatial index</em></strong></p>
<p style="padding-left:60px;"><strong><em>CREATE Index idx_sac_counties_geom ON sac_counties using gist(geom_albers);</em></strong></p>
<p style="padding-left:60px;"><strong><em>VACUUM ANALYZE;</em></strong></p>
<p>3. calculate intersecting areas of these polygons.</p>
<p>done in <strong>1</strong> above.</p>
<p>4. update the layer to remove sliver polygons (<strong><em>TO DO)</em></strong></p>
<h3>b) What are the dams within Yolo, Solano and Lake counties?</h3>
<p style="padding-left:60px;"><em><strong>SELECT  dams.dam_name, dams.county, dams.own_name, counties.name, dams.river<br />
FROM counties, dams<br />
WHERE<br />
ST_CONTAINS(counties.geom_albers,dams.geom_albers)<br />
AND<br />
(counties.name = &#8216;Lake&#8217; OR counties.name = &#8216;Yolo&#8217;<br />
OR counties.name = &#8216;Solano&#8217;) order by dams.county;</strong></em></p>
<p>This gives a list of24 dams. Interestingly (i) there are a few dams in the dams database table that seem to incorrectly be listed in Colusa instead of Lake counties; (ii) there are 3 dykes sitting on top of each other; (iii) Monticello dam does not show up. Perhaps its in Napa county (at least as seen by the geodatabase) &#8211; check if this is actually the case. Yes, it is:</p>
<p style="text-align:left;"><a href="http://en.wikipedia.org/wiki/Monticello_Dam" target="_blank">http://en.wikipedia.org/wiki/Monticello_Dam</a></p>
<p style="text-align:left;">Now, can we extract this as a new spatial table?</p>
<p style="text-align:left;">I found this <a href="http://trac.osgeo.org/postgis/wiki/UsersWikiExamplesOverlayTables" target="_blank">link </a>useful</p>
<p style="text-align:left;">And here&#8217;s what what worked:</p>
<p style="padding-left:30px;">- create spatial table of dams within 4 counties<br />
<em>create table select_dams as<br />
select st_intersection(counties.geom_albers,dams.geom_albers) as geom_albers,<br />
dams.dam_name as dam_name, counties.name as county, dams.own_name as owner_name, dams.river as river<br />
from dams,counties<br />
where st_contains(counties.geom_albers,dams.geom_albers)<br />
and counties.name in (&#8216;Solano&#8217;,'Yolo&#8217;,'Lake&#8217;,'Colusa&#8217;,'Napa&#8217;)<br />
order by county;<br />
vacuum analyze;</em></p>
<p style="padding-left:30px;">&#8211;indices are not there, so create them<br />
&#8211;first, spatial index on geometry</p>
<p style="padding-left:30px;"><em>create index idx_gist_select_dams on select_dams using gist(geom_albers);<br />
&#8211;then adding<br />
ALTER table select_dams ADD Column gid serial not null;<br />
ALTER table select_dams ADD Constraint pkey_select_dams_gid PRIMARY KEY(gid);</em></p>
<p>To give you a visual idea, here&#8217;s what the entire California dams layer (red triangles) looks like (zoomed to the extent of the layer, and exported as an image file from QGIS.)</p>
<p><em></p>
<div id="attachment_95" class="wp-caption alignnone" style="width: 310px"><em><a href="http://algoesalgo.files.wordpress.com/2010/05/ca_dams.png"><img class="size-medium wp-image-95" title="CA_dams" src="http://algoesalgo.files.wordpress.com/2010/05/ca_dams.png?w=300&#038;h=164" alt="Dams in California" width="300" height="164" /></a></em><em>Dams in California</em></dt>
</dl>
</div>
<p></em></p>
<p>..And here&#8217;s what it looks like after selecting only the dams (pink triangles) from 4 counties (also zoomed to the extent of the newly created selection):</p>
<p><em></p>
<div class="mceTemp">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><em><a href="http://algoesalgo.files.wordpress.com/2010/05/ca_dams_select.png"><img class="size-medium wp-image-94" title="Selected Dams" src="http://algoesalgo.files.wordpress.com/2010/05/ca_dams_select.png?w=300&#038;h=164" alt="" width="300" height="164" /></a></em><p class="wp-caption-text">Selected dams within 4 counties</p></div>
<p></em></p>
<p>of course in both cases i&#8217;ve added background layers like county boundaries and drainage and watersheds of interest.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=67&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2010/04/26/experiments-with-postgis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2010/05/ca_dams.png?w=300" medium="image">
			<media:title type="html">CA_dams</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2010/05/ca_dams_select.png?w=300" medium="image">
			<media:title type="html">Selected Dams</media:title>
		</media:content>
	</item>
		<item>
		<title>specific R tricks</title>
		<link>http://algoesalgo.wordpress.com/2009/04/29/specific-r-tricks/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/29/specific-r-tricks/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 19:02:04 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=59</guid>
		<description><![CDATA[Barcharts (lattice) precip &#60;- barchart(pct_precip_diff ~ date_chunk &#124; emission, groups=model, data=x, horizontal=FALSE, auto.key=list(rectangles=TRUE,columns=3,points=FALSE,cex=0.6),origin=0,ylab=&#8221;Precipitation difference (%)&#8221;, panel=function(x,y,&#8230;){ panel.barchart(x,y,&#8230;); panel.abline(h=0,lty=2)} ) Reordering factors using transform # merge the 2 dataframes which have same headers threatdata=merge(x.threat,x.people,all=T) #rename column headers colnames(threatdata)=c(&#8220;Threat&#8221;,&#8221;Counts&#8221;,&#8221;ThreatClass&#8221;,&#8221;Percentage&#8221;) ###### &#8212;- customize from here &#8212;&#8212;&#8212;&#8212;&#8212; threatdata &#60;- transform(threatdata, Threat=factor(Threat, levels=c(&#8216;Extreme threat&#8217;, &#8216;Very High threat&#8217;, &#8216;High threat&#8217;, &#8216;Moderate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=59&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Barcharts (lattice)</h2>
<p>precip &lt;- barchart(pct_precip_diff ~ date_chunk | emission, groups=model, data=x, horizontal=FALSE, auto.key=list(rectangles=TRUE,columns=3,points=FALSE,cex=0.6),origin=0,ylab=&#8221;Precipitation difference (%)&#8221;,<br />
panel=function(x,y,&#8230;){<br />
panel.barchart(x,y,&#8230;);<br />
panel.abline(h=0,lty=2)}</p>
<p>)</p>
<h2>Reordering factors using <em>transform</em></h2>
<p># merge the 2 dataframes which have same headers<br />
threatdata=merge(x.threat,x.people,all=T)</p>
<p>#rename column headers<br />
colnames(threatdata)=c(&#8220;Threat&#8221;,&#8221;Counts&#8221;,&#8221;ThreatClass&#8221;,&#8221;Percentage&#8221;)<br />
###### &#8212;- customize from here &#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>threatdata &lt;- transform(threatdata, Threat=factor(Threat, levels=c(&#8216;Extreme threat&#8217;, &#8216;Very High threat&#8217;, &#8216;High threat&#8217;, &#8216;Moderate threat&#8217;, &#8216;Little or no threat&#8217;)))</p>
<p>p &lt;- barchart(Threat~Percentage,groups=ThreatClass, data=threatdata,auto.key=TRUE,xlab=&#8221;Percentage of Grid Cell&#8221;)</p>
<h2>time series plots using ggplot2</h2>
<p>##R commands using ggplot2 library<br />
# temp and precip ts all 6 projections individually marked<br />
temp.ts=qplot(date,mean_temp,data=x,color=emission,lty=model,geom=c(&#8220;path&#8221;),xlab=&#8221;",ylab=expression(paste(&#8220;Avg Annual Temperature (&#8220;,degree,&#8221;C)&#8221;)))<br />
precip.ts=qplot(date,sum_precip,data=x,color=emission,lty=model,geom=c(&#8220;path&#8221;),xlab=&#8221;",ylab=&#8221;Annual Precipitation (mm)&#8221;)<br />
##<br />
##How to get a ribbon plot?temperature<br />
p &lt;- ggplot(x, aes(x = date, y = mean_temp, colour = emission,fill=emission))<br />
ppp=p + stat_summary(fun = &#8220;range&#8221;, geom=&#8221;ribbon&#8221;)<br />
temp.tsribbon=ppp + opts(axis.title.x=theme_blank()) + scale_y_continuous(expression(paste(&#8220;Avg Annual Temperature (&#8220;,degree,&#8221;C)&#8221;)))<br />
####removes x axis label and renames y axis</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=59&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/29/specific-r-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>
	</item>
		<item>
		<title>oneliners</title>
		<link>http://algoesalgo.wordpress.com/2009/04/27/oneliners/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/27/oneliners/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 00:28:35 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gdal]]></category>
		<category><![CDATA[geodata]]></category>
		<category><![CDATA[GRASS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ogr2ogr]]></category>
		<category><![CDATA[starspan]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=57</guid>
		<description><![CDATA[one-line commands useful for downloading and processing large numbers of geospatial datasets<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=57&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>ogr2ogr</h1>
<p>Converts from one vector gis format to another; reproject vector gis datasets</p>
<h2>Reprojecting</h2>
<h3>##Example: Tanzania admin to Latlong, WGS84 (EPSG:4326)</h3>
<p>ogr2ogr -f &#8220;ESRI Shapefile&#8221; -t_srs &#8220;EPSG:4326&#8243; tzadmin1_LL.shp tzadmn1.shp</p>
<h2>Assign missing projection</h2>
<h3>##Example: assigning projection to final file of district level boundaries:</h3>
<p>ogr2ogr -f &#8220;ESRI Shapefile&#8221; -a_srs &#8220;EPSG:4326&#8243; tan_adm.shp</p>
<h2>kml output using ogr2ogr</h2>
<p>http://www.gdal.org/ogr/drv_kml.html</p>
<h1>useful linux utilities</h1>
<h2>wget</h2>
<h3>extract only particular files buried in folders, and not recreate folders</h3>
<p>#Example: downloading GIMMS global NDVI data at one go</p>
<p>&gt;wget -r -nd -A .gz ftp://ftp.glcf.umiacs.umd.edu/glcf/GIMMS/Geographic/</p>
<h2>Renaming files</h2>
<h3>strip out latter half of file</h3>
<p>file=06feb15a.n17-VIg_data.tif ##<br />
filename=`basename $file .n17-VIg_data.tif`</p>
<h2>tar</h2>
<h3>unzipping tar.gz files</h3>
<p>tar zxfv filename.tar.gz</p>
<h2>scp</h2>
<h3>using scp to copy from remote to local machine</h3>
<p>&gt;scp 192.aaa.x.yyy:/data/UrbanProjectionsFromLLNL/extract_urban_pop_starspan.sh Desktop/</p>
<h1>starspan</h1>
<h2>Extracting from hundreds of rasters to vector polygons</h2>
<h3># Example: Extracting Avg NDVI for each of 8 Protected areas; dump average NDVI into a csv file</h3>
<p>starspan &#8211;vector ../ProtectedAreas-Africa/Tanzania/WDPAEXtractTest_vishal.mehta@sei-us.org3_2_2009222611_PG.shp &#8211;raster *.tif &#8211;stats ndvistats.csv avg</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=57&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/27/oneliners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>
	</item>
		<item>
		<title>kml animation from vector polygons</title>
		<link>http://algoesalgo.wordpress.com/2009/04/07/kml-animation-from-vector-polygons/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/07/kml-animation-from-vector-polygons/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 23:56:47 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=51</guid>
		<description><![CDATA[About This one&#8217;s about going from GRASS thematic vector polygon data to kml animation that can be viewed on Google Earth. The image is a static screenshot taken from the output Google Earth overlay. Input Dataset California Population change into 2100. There is one column with 2000 population numbers. Columns pcyyyy refer to population percentage [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=51&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>About</h1>
<p>This one&#8217;s about going from GRASS thematic vector polygon data to kml animation that can be viewed on Google Earth. The image is a static screenshot taken from the output Google Earth overlay.</p>
<p><img class="alignnone size-medium wp-image-53" title="screenshot-GE" src="http://algoesalgo.files.wordpress.com/2009/04/screenshot-google-earth.png?w=300&#038;h=172" alt="screenshot-GE" width="300" height="172" /></p>
<h2>Input Dataset</h2>
<p>California Population change into 2100. There is one column with 2000 population numbers. Columns pc<em>yyyy</em> refer to population percentage difference from year 2000 to year <em>yyyy</em>.</p>
<p style="padding-left:30px;"><strong>v.info -c CountyPop2<br />
</strong><em>Displaying column types/names for database connection of layer 1:<br />
INTEGER|cat<br />
CHARACTER|NAME<br />
INTEGER|NUM<br />
CHARACTER|COUNTY<br />
DOUBLE PRECISION|countynum<br />
DOUBLE PRECISION|p2000<br />
DOUBLE PRECISION|pc2010<br />
DOUBLE PRECISION|pc2015<br />
DOUBLE PRECISION|pc2020<br />
DOUBLE PRECISION|pc2025<br />
DOUBLE PRECISION|pc2030<br />
DOUBLE PRECISION|pc2035<br />
DOUBLE PRECISION|pc2040<br />
DOUBLE PRECISION|pc2045<br />
DOUBLE PRECISION|pc2050<br />
DOUBLE PRECISION|pc2055<br />
DOUBLE PRECISION|pc2060<br />
DOUBLE PRECISION|pc2065<br />
DOUBLE PRECISION|pc2070<br />
DOUBLE PRECISION|pc2075<br />
DOUBLE PRECISION|pc2080<br />
DOUBLE PRECISION|pc2085<br />
DOUBLE PRECISION|pc2090<br />
DOUBLE PRECISION|pc2100</em></p>
<h2>The Script</h2>
<p>This shell/GRASS script below can be saved as v.out.kml.sh. Run it using</p>
<p>sh v.out.kml <em>inputvector</em> <em>outputkml</em></p>
<blockquote>
<p style="padding-left:30px;">#!/bin/bash<br />
############################################################################<br />
# Apr 2009. Script to create<br />
# a) sequence of GRASS thematic vector displays from one vector dataset, each layer corresponds to a column of the attribute table<br />
# b) sequence of png images from above thematic vectors<br />
# b) write images into a kml file for overlay onto Google Earth<br />
# &#8212;-Vishal K. Mehta<br />
# cmd: sh v.out.kml.sh inputvector outputkmlfilename<br />
#####################################################################<br />
#<br />
# get current region settings from thematic map of interest-input file<br />
g.region vect=$1<br />
# Store current environment<br />
OLD_GRASS_WIDTH=$GRASS_WIDTH<br />
OLD_GRASS_HEIGHT=$GRASS_HEIGHT<br />
OLD_GRASS_PNGFILE=$GRASS_PNGFILE<br />
OLD_GRASS_TRANSPARENT=$GRASS_TRANSPARENT<br />
OLD_GRASS_TRUECOLOR=$GRASS_TRUECOLOR<br />
LEGEND_WIDTH=500<br />
LEGEND_HEIGHT=500<br />
LEGEND_TEXT_COLOR=white<br />
BACKGROUND_COLOR=black<br />
#1. create a legend file<br />
#d.thematic.area -l map=CountyPop2 column=pc2100 breaks=20,40,60 colors=cyan,brown,orange,red legendfile=popchange.leg<br />
export GRASS_WIDTH=$LEGEND_WIDTH<br />
export GRASS_HEIGHT=$LEGEND_HEIGHT<br />
export GRASS_BACKGROUNDCOLOR=$BACKGROUND_COLOR<br />
export GRASS_TRANSPARENT=TRUE ##<br />
export GRASS_TRUECOLOR=TRUE ##<br />
export GRASS_PNGFILE=legend.png<br />
d.mon start=PNG<br />
d.mon select=PNG<br />
#2. use d.graph on legend file the legend file popchange.leg is created outside of this code<br />
d.graph input=popchange.leg color=$LEGEND_TEXT_COLOR<br />
#<br />
d.mon stop=PNG<br />
mogrify -transparent black legend.png<br />
# now display the vector thematic layers<br />
# define the driver settings<br />
export GRASS_WIDTH=`g.region -g | grep &#8220;cols&#8221; | cut -d= -f2`<br />
export GRASS_HEIGHT=`g.region -g | grep &#8220;rows&#8221; | cut -d= -f2`<br />
export GRASS_TRANSPARENT=TRUE ##<br />
export GRASS_TRUECOLOR=TRUE ##<br />
yr=2010<br />
while [ $yr -lt 2105 ] ; do<br />
echo &#8220;yr is $yr &#8220;<br />
#create png images<br />
export GRASS_PNGFILE=pc$yr.png<br />
d.mon start=PNG<br />
d.mon select=PNG<br />
d.thematic.area map=$1 column=pc$yr breaks=20,40,60 colors=cyan,blue,yellow,red<br />
#d.text -b text=&#8221;$yr Population&#8221; at=50,90 size=4<br />
d.mon stop=PNG<br />
# year 2095 column is non-existent so needs to be skipped<br />
if [ $yr -eq 2090 ]; then yr=$((yr+10)); else yr=$((yr+5)); fi;<br />
done</p>
<p>#<br />
# Create the kml file<br />
#TITLE=`r.info -m $GIS_OPT_INPUT | cut -d= -f2`<br />
TITLE=&#8221;Population&#8221;<br />
NORTH=`g.region -g | grep -m1 &#8220;n=&#8221; | cut -d= -f2`<br />
SOUTH=`g.region -g | grep -m1 &#8220;s=&#8221; | cut -d= -f2`<br />
EAST=`g.region -g | grep -m1 &#8220;e=&#8221; | cut -d= -f2`<br />
WEST=`g.region -g | grep -m1 &#8220;w=&#8221; | cut -d= -f2`<br />
echo &#8220;&lt;?xml version=\&#8221;1.0\&#8221; encoding=\&#8221;UTF-8\&#8221;?&gt;&#8221; &gt; $2.kml<br />
echo &#8220;&lt;kml xmlns=\&#8221;http://earth.google.com/kml/2.2\&#8221;&gt;&#8221; &gt;&gt; $2.kml<br />
# now begins stack of images<br />
echo &#8220;&lt;Folder&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;open&gt;1&lt;/open&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;name&gt;California Population Projections&lt;/name&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;description&gt;Percentage difference from 2000 Population&lt;/description&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;visibility&gt;1&lt;/visibility&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;open&gt;0&lt;/open&gt;&#8221; &gt;&gt; $2.kml<br />
# add legend first<br />
echo &#8220;&lt;ScreenOverlay&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;name&gt;Legend&lt;/name&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;Icon&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;href&gt;legend.png&lt;/href&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;/Icon&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;overlayXY x=\&#8221;0\&#8221; y=\&#8221;1\&#8221; xunits=\&#8221;fraction\&#8221; yunits=\&#8221;fraction\&#8221;/&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;screenXY x=\&#8221;0.05\&#8221; y=\&#8221;0.95\&#8221; xunits=\&#8221;fraction\&#8221; yunits=\&#8221;fraction\&#8221;/&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;rotationXY x=\&#8221;0\&#8221; y=\&#8221;0\&#8221; xunits=\&#8221;fraction\&#8221; yunits=\&#8221;fraction\&#8221;/&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;size x=\&#8221;200\&#8221; y=\&#8221;200\&#8221; xunits=\&#8221;pixels\&#8221; yunits=\&#8221;pixels\&#8221;/&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;/ScreenOverlay&gt;&#8221;  &gt;&gt; $2.kml<br />
echo &#8220;&lt;TimeSpan&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;begin&gt;2010-01&lt;/begin&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;end&gt;2100-12&lt;/end&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/TimeSpan&gt;&#8221; &gt;&gt; $2.kml<br />
# start loop for sequence of images<br />
yr=2010<br />
while [ $yr -lt 2105 ] ; do<br />
if [ $yr -eq 2090 ]; then endyr=$((yr+10));<br />
elif [ $yr -eq 2100 ]; then endyr=$((yr));<br />
else endyr=$((yr+5)); fi;<br />
echo &#8220;&lt;GroundOverlay&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;name&gt;$yr&lt;/name&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;visibility&gt;1&lt;/visibility&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;drawOrder&gt;1&lt;/drawOrder&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;TimeSpan&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;begin&gt;$((yr))-01&lt;/begin&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;end&gt;$((endyr))-12&lt;/end&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/TimeSpan&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;Icon&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;href&gt;pc$yr.png&lt;/href&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/Icon&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;LatLonBox&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;south&gt;$SOUTH&lt;/south&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;north&gt;$NORTH&lt;/north&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;west&gt;$WEST&lt;/west&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;east&gt;$EAST&lt;/east&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/LatLonBox&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/GroundOverlay&gt;&#8221; &gt;&gt; $2.kml<br />
if [ $yr -eq 2090 ]; then yr=$((yr+10)); else yr=$((yr+5)); fi;<br />
done<br />
#<br />
echo &#8220;&lt;/Folder&gt;&#8221; &gt;&gt; $2.kml<br />
echo &#8220;&lt;/kml&gt;&#8221; &gt;&gt; $2.kml<br />
# Restore the environment<br />
export GRASS_WIDTH=$OLD_GRASS_WIDTH<br />
export GRASS_HEIGHT=$OLD_GRASS_HEIGHT<br />
export GRASS_PNGFILE=$OLD_GRASS_PNGFILE<br />
export GRASS_TRANSPARENT=$OLD_GRASS_TRANSPARENT<br />
export GRASS_TRUECOLOR=$OLD_GRASS_TRUECOLOR</p>
<p style="padding-left:30px;">######END OF SCRIPT#########</p>
</blockquote>
<h1>Notes/To Do</h1>
<p>This script is not fully automated. In particular, the legend specs file is hardcoded.Getting a decent legend for GRASS thematic layers is a Major Pain.</p>
<p>Related posts &#8220;thematic maps in GRASS&#8221;; &#8220;another attempt at animated gif&#8221;.</p>
<h1>Acknowledgements</h1>
<p><a href="http://david.p.finlayson.googlepages.com/gisscripts" target="_blank">David Finlayson</a>&#8216;s r.out.kml script, to convert a single GRASS raster to kml.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=51&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/07/kml-animation-from-vector-polygons/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2009/04/screenshot-google-earth.png?w=300" medium="image">
			<media:title type="html">screenshot-GE</media:title>
		</media:content>
	</item>
		<item>
		<title>another attempt at animated gif</title>
		<link>http://algoesalgo.wordpress.com/2009/04/06/another-attempt-at-animated-gif/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/06/another-attempt-at-animated-gif/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 19:58:51 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[geodata]]></category>
		<category><![CDATA[GoogleEarth]]></category>
		<category><![CDATA[GRASS GIS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[California]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[GRASS]]></category>
		<category><![CDATA[Image Magick]]></category>
		<category><![CDATA[population]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=39</guid>
		<description><![CDATA[This one was created in Image Magick. It works alright when opened in a web browser. Does it work when uploaded on WordPress?? WHAT WORKED It worked only  by creating a link to the gif file. Not by simply inserting it as an image&#8230; WHAT IS IT? Its an animation every 5 yrs of projected [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=39&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This one was created in Image Magick. It works alright when opened in a web browser. Does it work when uploaded on WordPress??</p>
<p><a class="alignleft" title="California population into 2100" href="http://algoesalgo.files.wordpress.com/2009/04/trial.gif" target="_blank"><img class="alignnone size-medium wp-image-38" title="another attempt at an animated gif" src="http://algoesalgo.files.wordpress.com/2009/04/trial.gif?w=300&#038;h=225" alt="another attempt at an animated gif" width="300" height="225" /></a></p>
<h2>WHAT WORKED</h2>
<p>It worked only  by creating a link to the gif file. Not by simply inserting it as an image&#8230;</p>
<h2>WHAT IS IT?</h2>
<p>Its an animation every 5 yrs of projected California population data..</p>
<h2>How was it created?</h2>
<p>First, I had a sequence of .png images, extracted from GRASS GIS work (to be posted later). Then I ran a simple Image Magick utility to take the stack of .png files and create an animated gif called &#8220;trial.gif&#8221;. Its an endless loop, anda 20/100 second delay between images.</p>
<h2><span style="color:#008000;"> convert -delay 20 -loop 0 *.png trial.gif</span></h2>
<p>I learned about this useful command <a href="http://www.tjhsst.edu/~dhyatt/supercomp/n401a.html" target="_blank">here</a>.</p>
<h2>To Do</h2>
<p>1. The image files must be named in some logical order. For example if they are named file1, file 2&#8230;.file20, it wont work right. The images will be animated from file1, file10,file11&#8230;</p>
<p>So the files must be renamed correctly&#8230;I&#8217;m working on it. If you know, please comment!</p>
<p>2. In GRASS I still need to add a legend and title etc..am working on it</p>
<p>3. Then I&#8217;m going to create a kml animation..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=39&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/06/another-attempt-at-animated-gif/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2009/04/trial.gif?w=300" medium="image">
			<media:title type="html">another attempt at an animated gif</media:title>
		</media:content>
	</item>
		<item>
		<title>animated gif</title>
		<link>http://algoesalgo.wordpress.com/2009/04/04/animated-gif/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/04/animated-gif/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 03:35:15 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[GIMP]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=26</guid>
		<description><![CDATA[About This is a simple animated gif of 2 images : of watercolors. One (the happy one:) done by Debbie, the other, apocalyptic one is mine. is one the geologic past, and the other the future? Or vice-versa? it could work either way&#8230; Shucks&#8230;the animated gif works out ok if opened in a browser, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=26&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-28" title="pastfuture" src="http://algoesalgo.files.wordpress.com/2009/04/pastfuture.gif?w=300&#038;h=204" alt="pastfuture" width="300" height="204" /></p>
<h2><a class="alignleft" href="http://algoesalgo.files.wordpress.com/2009/04/pastfuture.gif" target="_self"><br />
</a></h2>
<h2>About</h2>
<p>This is a simple animated gif of 2 images : of watercolors. One (the happy one:) done by Debbie, the other, apocalyptic one is mine. is one the geologic past, and the other the future? Or vice-versa? it could work either way&#8230;</p>
<p>Shucks&#8230;the animated gif works out ok if opened in a browser, but does not seem to work up here..oh well. If anybody know how to make an animated gif work on WordPress let me know..</p>
<h2>What works</h2>
<p><a title="paintings" href="http://algoesalgo.files.wordpress.com/2009/04/pastfuture.gif" target="_blank"><strong>Linking</strong></a> to the animated gif works &#8211; because, it opens up a web browser..</p>
<p>Embedding the image file directly does not work -  this is why the topmost image is not animated on wordpress.</p>
<h2>Notes</h2>
<p>I cant embed a picasa slideshow into WordPress; and I did not like the slideshow options WordPress suggested &#8211; they were just cheesy!</p>
<p>So now i&#8217;m playing with GIMP to see if i can just post an animated gif instead. Its a pain though, to be putting up pictures separately likely this..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=26&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/04/animated-gif/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2009/04/pastfuture.gif?w=300" medium="image">
			<media:title type="html">pastfuture</media:title>
		</media:content>
	</item>
		<item>
		<title>flowers in springtime</title>
		<link>http://algoesalgo.wordpress.com/2009/04/04/flowers-in-springtime/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/04/flowers-in-springtime/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 21:31:29 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[About me]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[California]]></category>
		<category><![CDATA[Davis]]></category>
		<category><![CDATA[flowers]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/2009/04/04/flowers-in-springtime/</guid>
		<description><![CDATA[spring flowers blooming in our front and backyards here in Davis, CA!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=24&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>spring flowers blooming in our front and backyards here in Davis, CA!</p>
<div id="attachment_34" class="wp-caption alignnone" style="width: 310px"><a href="http://picasaweb.google.com/lh/photo/nMnyK7OG6o6MVHXyplNwxg?authkey=Gv1sRgCKe37Le7r8-59QE&amp;feat=directlink"><img class="size-medium wp-image-34" title="jasmine" src="http://algoesalgo.files.wordpress.com/2009/04/jasmine.jpg?w=300&#038;h=225" alt="spring flowers in our garden" width="300" height="225" /></a><p class="wp-caption-text">spring flowers in our garden</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=24&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/04/flowers-in-springtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>

		<media:content url="http://algoesalgo.files.wordpress.com/2009/04/jasmine.jpg?w=300" medium="image">
			<media:title type="html">jasmine</media:title>
		</media:content>
	</item>
		<item>
		<title>geodata for guadiana, spain</title>
		<link>http://algoesalgo.wordpress.com/2009/04/03/geodata-for-guadiana-spain/</link>
		<comments>http://algoesalgo.wordpress.com/2009/04/03/geodata-for-guadiana-spain/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 23:29:09 +0000</pubDate>
		<dc:creator>vkm2</dc:creator>
				<category><![CDATA[geodata]]></category>
		<category><![CDATA[GRASS GIS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ESRI]]></category>
		<category><![CDATA[GRASS]]></category>
		<category><![CDATA[guadiana]]></category>
		<category><![CDATA[spain]]></category>

		<guid isPermaLink="false">http://algoesalgo.wordpress.com/?p=19</guid>
		<description><![CDATA[Lower Guadiana basin, Spain This is my work area on geodata collection for Guadiana, Spain. In support of visiting scholar Irene Blanco ####Soils ###Sources 1. European Soils Database Link:http://eusoils.jrc.ec.europa.eu/data.html Resolution: Format: vector; also raster files of 70+ properties in ESRI GRID format, Lambert Azimuthal coordinates; Issues: Status: pending; ####Rivers ###Sources 1. Hydro1K dataset for Europe [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=19&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Lower Guadiana basin, Spain</h1>
<blockquote><p>This is my work area on geodata collection for Guadiana, Spain. In support of visiting scholar Irene Blanco</p></blockquote>
<h2 style="background-color:#ff9900;">####Soils</h2>
<h3>###Sources</h3>
<h4 style="background-color:#00ff00;">1. European Soils Database</h4>
<p><strong>Link</strong>:http://eusoils.jrc.ec.europa.eu/data.html<br />
<strong>Resolution:</strong><br />
<strong>Format:</strong> vector; also raster files of 70+ properties in ESRI GRID format, Lambert Azimuthal coordinates;<br />
<strong>Issues:</strong><br />
<strong>Status: </strong>pending;</p>
<h2 style="background-color:#ff9900;"><strong>####Rivers</strong></h2>
<h3><strong>###Sources</strong></h3>
<h4>1. Hydro1K dataset for Europe</h4>
<p><strong>Link</strong>:http://edc.usgs.gov/products/elevation/gtopo30/hydro/eu_streams.html<br />
<strong>Resolution:</strong> NA<br />
<strong>Format</strong>: shapefile<br />
<strong>Issues:</strong> This is based on flow accumulation analysis on GTOPO elevation data<br />
<strong>Status:</strong> archive downloaded. unprocessed.</p>
<h4>2. Digital Chart of the World</h4>
<p><strong>Link</strong>:http://www.maproom.psu.edu/dcw/<br />
<strong>Resolution:</strong> NA<br />
<strong>Format:</strong> arc info format (.eoo);Latlong Clarke1866<br />
<strong>Issues:</strong> must be reprojected; dataset is old<br />
<strong>Status:</strong> selected archive for Spain downloaded &#8211; drainage, also <strong>landcover, roads, populated places</strong>. unprocessed<br />
<strong>Scripts:<br />
#converting the drainage into shapefiles and also reprojecting to wgs84<br />
</strong>ogr2ogr -f &#8220;ESRI Shapefile&#8221; -t_SRS EPSG:4326 DCW_drainage dnnet.e00<br />
&lt;ERROR 6: Can&#8217;t create fields of type IntegerList on shapefile layers.&gt;<br />
what is this?? try importing directly in Manifold/Arcview/ArcGIS</p>
<h4>3.</h4>
<p>http://dataservice.eea.europa.eu/dataservice/metadetails.asp?id=1053</p>
<h4 style="background-color:#00ff00;">4. European Commission Joint Research Center</h4>
<p><strong>Link</strong>:http://desert.jrc.ec.europa.eu/action/php/index.php?action=view&amp;id=24<br />
<strong>Resolution:</strong>NA<br />
<strong>Format: </strong>Latlongwgs84; ESRI ArcGIS geodatabase; cannot use in GRASS, must switch to ArcGIS<br />
<strong>Issues:</strong> archive downloaded for &#8220;SouthWest&#8221; tile which includes Spain. unprocessed; handover to Irene to continue in ArcGIS.</p>
<h2 style="background-color:#ff9900;">####DEM</h2>
<h3>###Sources</h3>
<h4>1. GTOPO30</h4>
<p><strong>Link</strong>:http://eros.usgs.gov/products/elevation/gtopo30/gtopo30.html<br />
<strong>Resolution</strong>: 30 arc seconds (~1km)<br />
<strong>Format:</strong> Binary, 16bit integer, Motorola MSB<br />
<strong>Issues:</strong> Failed to import using several software; 2 tiles needed to cover lower Guadiana basin<br />
<strong>Status:</strong> 2 tiles raw data downloaded, unprocessed</p>
<h4>2. SRTM</h4>
<p><strong>Link</strong>:http://eros.usgs.gov/products/elevation/gtopo30/gtopo30.html<br />
<strong>Resolution:</strong> 3 arc seconds (~90m)<br />
<strong>Format</strong>: SRTM DEM format<br />
<strong>Issues:</strong> Will need 20-30 tiles downloaded, imported and mosaiced<br />
<strong>Status:</strong> 2 tiles raw data downloaded by Irene; unprocessed; abandoned for &#8211; no need for such high resolution for WEAP work</p>
<h4 style="background-color:#00ff00;">3. GLOBEDEM</h4>
<p><strong>Link</strong>:http://www.ngdc.noaa.gov/mgg/topo/<br />
<strong>Resolution:</strong> 30 arc seconds (~1km)<br />
<strong>Format:</strong> Binary, 16bit integer, Motorola MSB<br />
<strong>Issues:</strong> Boundary coordinates fed to download rectangular region for most of Spain<br />
<strong>Status:</strong> Successfully processed in GRASS; and also output to ESRI Ascii grid format which can be used in ArcGIS and Arcview.<br />
<strong>Scripts:</strong><br />
###GRASS GIS<br />
##March 31 Guadiana basin DEM work<br />
#import GlobeDEM using r.in.bin (http://grass.itc.it/gdp/html_grass63/r.in.bin.html)<br />
#r.in.gdal did not work</p>
<p>r.in.bin -sb input=Vishal_Guadiana.bin output=GlobeDEM north=44.0 south=35.9 east=2.0 west=-9.3 r=972 c=1356 bytes=2 anull=-500</p>
<p># creating watershed at 1000km2 threshold<br />
r.watershed GlobeDEM thresh=1000 accum=FlowAccum1000 drain=draindir1000 basin=basin_1000 stream=rivers1000</p>
<p>#creating and displaying shaded relief<br />
r.shaded.relief GlobeDEM shadedmap=GlobeShaded<br />
d.his h=elevation i=GlobeShaded</p>
<p># clean up border bad watersheds<br />
r.mapcalc basins=basin_1000</p>
<p>r.null map=basins setnull=98,100,102,104,106,108,110,112,114,116,118,120,662,660,798,1082,800,802,1078,804,936,944,1060,1068,1072,1100,1106,1110,1114,1118,1122,1126,1130,1166,1168,1170</p>
<p>r.null map=basins setnull=4,6,8,10,12,14,16,20,22,24,26,28,30,416,414,640,644,648,652,650,656,654</p>
<p># convert basins to vector<br />
r.to.vect -s basins out=basins feature=area<br />
#display vector watersheds map<br />
d.vect -c basins<br />
#export to shapefile; -ep flags generate .prj and convert lines to polygons respectively.<br />
v.out.ogr -ep input=basins type=area dsn=Watersheds.shp format=ESRI_Shapefile<br />
v.info basins</p>
<p># convert GlobeDEM into Esri Ascii grid; also the partially cleaned up &#8216;basins&#8217; watersheds raster layer. the basins will need to be converted to vector and cleaned up later in Manifold/Arcview or ArcGIS<br />
r.out.gdal format=AAIGrid input=GlobeDEM output=GlobeDEM.asc nodata=-9999<br />
r.out.gdal format=AAIGrid input=basins output=basins.asc nodata=-9999<br />
#</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/algoesalgo.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/algoesalgo.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/algoesalgo.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=algoesalgo.wordpress.com&amp;blog=7198393&amp;post=19&amp;subd=algoesalgo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://algoesalgo.wordpress.com/2009/04/03/geodata-for-guadiana-spain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4638953c4559b097a2664794e34126d2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vkm2</media:title>
		</media:content>
	</item>
	</channel>
</rss>
