<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Scratching Surfaces &#187; GIS</title>
	<atom:link href="http://www.surfaces.co.il/?cat=3&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.surfaces.co.il</link>
	<description>Open Source - GIS - Thoughts</description>
	<lastBuildDate>Fri, 13 Aug 2010 12:06:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Fedora 13 and FOSS GIS: new gotchas and workarounds</title>
		<link>http://www.surfaces.co.il/?p=746</link>
		<comments>http://www.surfaces.co.il/?p=746#comments</comments>
		<pubDate>Fri, 13 Aug 2010 12:06:18 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=746</guid>
		<description><![CDATA[With each new version of FOSS operating systems come new possibilities and new problems. Such is the case with Fedora 13. Fedora developers decided to no longer release statically compiled binaries, only dynamically linked. I won&#8217;t pretend to understand all the considerations which lead to this decision. But I&#8217;ve found that it floats to the [...]]]></description>
			<content:encoded><![CDATA[<p>With each new version of FOSS operating systems come new possibilities and new problems. Such is the case with Fedora 13. Fedora developers <a href="http://fedoraproject.org/wiki/Packaging/Guidelines#Packaging_Static_Libraries">decided</a> to no longer release statically compiled binaries, only dynamically linked. I won&#8217;t pretend to understand all the considerations which lead to this decision. But I&#8217;ve found that it floats to the surface some changes when trying to compile the GIS toolkit. So if you want to do the wizardry to setup your freshly installed F13 box as a GIS workstation, then follow the yellow brick road&#8230;</p>
<p><span id="more-746"></span>First off, if you haven&#8217;t yet, get the basic packages for compiling software, etc. (I enter my username into the sudoers file, similar to Ubuntu, so that sudo works, without being &#8216;root&#8217; all the time)</p>
<pre>~$ <strong>sudo yum install gcc gcc-c++ gcc-gfortran flex byacc cmake ccmake \</strong></pre>
<pre><strong>           ncurses-devel bison </strong><strong>wget gsl gsl-devel expat-devel</strong></pre>
<p>Next add the available geospatial packages, as well as several python and Qt libraries that we&#8217;ll need for GRASS and QGIS packages that we can install without compiling:</p>
<pre><strong>~$sudo yum install proj proj-epsg proj-devel geos libgeotiff libgeotiff-devel \
     wxGTK wxGTK-devel swig python-psycopg2 numpy \
     PyQt4 PyQt4-devel sip sip-devel wxPython wxPython-devel</strong></pre>
<p><span style="font-weight: normal;">My goal is to have available in GRASS and QGIS both Spatialite based GIS layers and ECW compressed rasters. These libraries are not available on Fedora, so I&#8217;ll need to add them by hand and then compile GDAL to include support for these formats. Next I&#8217;ll need to work my way up the toolchain, compiling both GRASS and QGIS to use this new GDAL. We begin with spatialite. Get the source:</span></p>
<pre><strong>~$ wget http://www.gaia-gis.it/spatialite-2.3.1/libspatialite-amalgamation-2.4.0.tar.gz
~$ tar xvzf libspatialite-amalgamation-2.4.0.tar.gz
~$ cd libspatialite-amalgamation-2.4.0</strong></pre>
<p>At this point we already bump into a problem with the lack of static binaries in Fedora packaging. Spatialite requires the  geos and proj packages. But it looks for *.la files which are missing from all Fedora libraries now. It seems that libtool reads these *.la text files to find what libraries should be linked. In the absence of a suitable *.la file, when we try to compile spatialite, libtool causes a failure. So here&#8217;s the workaround I used. I just create three text files with the definitions needed, and then spatialite happily compiles. In /usr/lib you&#8217;ll need libgeos_c.la, libgeos.la, and libproj.la. Thanks to Sandro Furieri on the <a href="http://groups.google.com/group/spatialite-users/browse_thread/thread/919283f738293849">SpatiaLite Users Forum</a> for this tip.  They should look like this:</p>
<pre><strong>~$ sudo vi /usr/lib/libgeos_c.la
          dlname='libgeos_c.so'
          library_names='libgeos_c.so'
          inherited_linker_flags=''
          dependency_libs=' -L/usr/lib /usr/lib/libgeos.la'
          weak_library_names=''
          current=7
          age=6
          revision=2
          installed=yes
          shouldnotlink=no
          dlopen=''
          dlpreopen=''
          libdir='/usr/lib'
</strong></pre>
<p>For each of the additional *.la files change the &#8216;dlname=&#8217; and &#8216;library_names=&#8217;  entries as required.<br />
Now go ahead and</p>
<pre><strong>~$./configure
~$make &amp;&amp; sudo make install</strong></pre>
<p>.<br />
Next step is the ECW libraries.  This has been faily well <a href="http://www.qgis.org/wiki/Installation_Guide#Step_2:_compile_and_install_the_ecw_libraries">documented</a> already. First you&#8217;ll have to register on the ERDAS site to download their SDK, then compile and install it. What you will need, after compiling the ECW library, is to add a *.conf file in /etc/ld.so.conf.d so that ldconfig will &#8220;find&#8221; the new library.</div>
<pre style="padding: 0px; margin: 0px;">~$<strong>sudo vi /etc/ld.so.conf.d/gdal.conf</strong></pre>
<pre style="padding: 0px; margin: 0px;"><span style="padding: 0px; margin: 0px;">      <strong> /usr/local/lib</strong>
<strong>~$sudo ldconfig</strong></span></pre>
<p>Now we&#8217;re ready for GDAL, etc.  First download the sources:</p>
<pre><strong>~$wget http://download.osgeo.org/gdal/gdal-1.7.2.tar.gz
~$wget http://grass.osgeo.org/grass64/source/grass-6.4.0RC6.tar.gz</strong></pre>
<p> (or a more recent source from svn) </p>
<pre><strong>~$wget http://download.osgeo.org/qgis/src/qgis_1.5.0.tar.gz</strong></pre>
<p>Unzip each tarball and, beginning with GDAL we trip over the next change in Fedora. Along with the &#8220;no static binaries&#8221; policy, the linker &#8216;ld&#8217; no longer links libraries that are not explicitly listed in the gcc compile statement. Previously, if one binary linked to a second that linked to a third, then there was &#8220;implicit&#8221; linking that brought in the third binary. This is no longer the case. The error that pops up with gdal concerns the pthread library. GDAL doesn&#8217;t use this inherently, but it is used somewhere along the compile chain. Again as a &#8220;quick and dirty&#8221; workaround I stuck in statements to have GDAL explicitly link to pthread as follows:</p>
<pre><strong>~$ cd gdal-1.7.2
~$LIBS="-lpthread" LDFLAGS="-lpthread" ./configure --with-geos=yes --with-sqlite3 --with-ecw=/usr/local --with-python --with-spatialite=/usr/local
~$make
~$sudo make install</strong></pre>
<p>With this done, we&#8217;re ready for a straightforward compile of GRASS and QGIS:</p>
<pre><strong>~$ cd ../grass-6.4.svn_src_snapshot_2010_08_07 </strong></pre>
<p> (or whatever svn snapshot you downloaded&#8230;) </p>
<pre><strong>./configure --prefix=/usr/local/grass-6.4 \
     --with-proj-share=/usr/share/proj \
     --with-postgres --enable-largefile  --with-sqlite \
     --with-freetype  --with-freetype-includes=/usr/include/freetype2 \
     --with-python --with-wxwidgets --with-cxx
make &amp;&amp; sudo make install
sudo ln -s /usr/local/grass-6.4/bin/grass64 /usr/bin/</strong></pre>
<p>You most likely will also want the gdal-grass package:</p>
<pre><strong>~$wget http://download.osgeo.org/gdal/gdal-grass-1.4.3.tar.gz
~$/configure --with-grass=/usr/local/grass-6.4/grass-6.4.0svn --with-gdal=/usr/local/bin/gdal-config
~#make &#038;&#038; sudo make install</strong></pre>
<p>Before moving on to QGIS, we&#8217;ll get the R statistics package setup.</p>
<pre><strong>~$sudo yum install R-core rpy R-devel xml2 libxml2 libxml2-devel</strong></pre>
<p>I&#8217;ll now add the spatial packages to R. I like to keep all R packages under the system directory /usr/lib/R. However this directory is read only. Since this is my machine, I allow myself to change permissions, and then I can install additional packages without creating a separate R package directory in my home dir.</p>
<pre><strong>~$sudo chgrp -R &lt;my username&gt; /usr/lib/R
~$sudo chmod -R g+w /usr/lib/R</strong></pre>
<p>Now open an R session and run:</p>
<pre><strong>~$R
&gt; install.packages('sp', dependencies='true')
&gt; install.packages('spgrass6', dependencies='true')
&gt;q()</strong></pre>
<p>Next, for the rgdal package. R needs to locate the grass libraries. The R rpm packages which I installed above assume that the grass libs are in /usr/local/lib. But I installed GRASS myself elsewhere, so a quick soft link solves that issue:</p>
<pre><strong>~$sudo ln -s /usr/local/grass-6.4/grass-6.4.0svn/lib/libgrass_* /usr/local/lib
~$wget http://cran.r-project.org/src/contrib/rgdal_0.6-28.tar.gz
~$R CMD INSTALL rgdal_0.6-28.tar.gz -l /usr/lib/R/library/</strong></pre>
<p>and that&#8217;s done.</p>
<p>And finally QGIS:</p>
<pre><strong>~$ cd ../qgis-1.5.0
~$mkdir build; cd build
~$cmake -DCMAKE_INSTALL_PREFIX:PATH="/usr/local/qgis-1.5.0"  -DGRASS_PREFIX:PATH="/usr/local/grass-6.4/grass-6.4.0svn" -L ..</strong></pre>
<p>(Take note of the &#8216;..&#8217; at the end of the cmake line). The -L option to cmake outputs a list of the config options. Scan thru it to make sure everything is located on your system. Then:</p>
<pre><strong>make &#038;&#038; sudo make install
sudo ln -s /usr/local/qgis-1.5.0/bin/qgis /usr/bin</strong></pre>
<p>At this point you should be back in Kansas <img src='http://www.surfaces.co.il/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=746</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>GIS Basics with Quantum GIS</title>
		<link>http://www.surfaces.co.il/?p=733</link>
		<comments>http://www.surfaces.co.il/?p=733#comments</comments>
		<pubDate>Mon, 26 Jul 2010 07:30:11 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=733</guid>
		<description><![CDATA[In several GIS training seminars I&#8217;ve used a collection of spatial data and exercises to demonstrate and practice some basic GIS operations using Quantum GIS. If you&#8217;d like to try out one of the popular open source GIS programs, download this zipped file. (100 MB, and compressed with 7zip). It contains a directory of documents, [...]]]></description>
			<content:encoded><![CDATA[<p>In several GIS training seminars I&#8217;ve used a collection of spatial data and exercises to demonstrate and practice some basic GIS operations using <a href="http://www.qgis.org/">Quantum GIS</a>. If you&#8217;d like to try out one of the popular open source GIS programs, download this <a href="http://www.surfaces.co.il/dl/GIS_Training.7z">zipped file</a>. (100 MB, and compressed with <a href="http://www.7-zip.org/">7zip</a>). It contains a directory of documents, including the list of exercises, a directory of geospatial data, and several presentations.<span id="more-733"></span>Under the Docs directory are, in addition to the exercises, some manuals and other training material in pdf format. The Geodata directory contains spatial data from naturalearthdata.org, Open Street Map, the European Environment Agency, as well as raster tiles from NASA&#8217;s ASTER DEM and the Landsat programs.  Each of the exercises will require loading different data layers.  All data have been clipped to the area of Croatia, and Bosnia-Hercegovina, and all are licensed so as to be freely usable.  Finally, under the Presentations directory are the slides used to explain various aspects of basic cartography and GIS theory.</p>
<p>If you find this learning material worthwhile, or have any comments for improvement, please let me know. I expect that I&#8217;ll continue polishing up the material, adding new presentations, and perhaps additional data sources. So check back.</p>
<p>Licensing details:</p>
<p><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img style="border-width: 0;" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" alt="Creative Commons License" /></a><br />
<span>GIS Training with QGIS</span> by <a rel="cc:attributionURL" href="http://www.surfaces.co.il">Micha Silver</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=733</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Using OSM data as a basemap for a Garmin GPS</title>
		<link>http://www.surfaces.co.il/?p=682</link>
		<comments>http://www.surfaces.co.il/?p=682#comments</comments>
		<pubDate>Sun, 06 Jun 2010 19:45:21 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=682</guid>
		<description><![CDATA[Of all the collaborative efforts driven by Internet technology today, OpenStreetMap (OSM) is, next to Wikipedia or Youtube , arguably one of the most impressive and widely used.  Thousands of GPSniks wander around the streets and trails of the world, capturing tracks and waypoints, and then rush home to upload the new data. The agility [...]]]></description>
			<content:encoded><![CDATA[<p>Of all the collaborative efforts driven by Internet technology today, OpenStreetMap (OSM) is, next to Wikipedia or Youtube , arguably one of the most impressive and widely used.  Thousands of GPSniks wander around the streets and trails of the world, capturing tracks and waypoints, and then rush home to upload the new data. The agility and motivation of contributors was proved beyond a doubt with the unprecedented <a href="http://www.youtube.com/watch?v=kFwdtp52MS4&amp;feature=related">response</a> in mapping Port-au-Prince during the Haiti earthquake disaster.</p>
<p><span id="more-682"></span></p>
<p>All GPS manufacturers sell, in addition to the unit itself, basemaps for many places around the world together with a proprietary software program to upload the maps to the GPS. But with the vast and detailed coverage of OSM why not use this data as a background map in your GPS? Well, in fact you can, and it&#8217;s <strong>all doable with open source</strong> software.  There are tool chains available for both Windows and Linux.  The OSM Wiki has a detailed <a href="http://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin#Software">table</a> of software for each OS.  I&#8217;m going to focus on Ubuntu Linux and two software packages: the java based <a href="http://www.mkgmap.org.uk/index.html">mkgmap</a> and GPS interface software <a href="http://www.qlandkarte.org/">QLandKarte GT</a> .</p>
<p>On the <a href="http://www.openstreetmap.org/">OpenStreetMap</a> website you can search for and download data using the &#8220;Export&#8221; tab, and choose &#8220;OpenStreetMap XML data&#8221; as the format. However you&#8217;re limited to rather small areas &#8211; usually less than 50 km. squared. If you know the longitude/latitude of the area you&#8217;re interested in, you can download larger regions directly from the Information Freeway website using wget. Here&#8217;s an example:</p>
<pre>~/geodata/OSM$ wget -O bosnia.osm http://www.informationfreeway.org/api/0.6/map?bbox=17,42.5,19,44</pre>
<p>The format after the &#8220;map?bbox=&#8221; is West,South,East,North in decimal degrees.</p>
<p>Now that you have your *.osm file, what&#8217;s the next step? I chose the mkgmap utility to process OSM files into a format that Garmin GPS can use. Ubuntu has this application in its repository so it was a quick</p>
<pre>~/geodata/OSM$ sudo apt-get install mkgmap</pre>
<p>to get it installed.  And it works fine with Ubuntu&#8217;s default Open-JDK. To use this tool you can either type all the options on the command line, or create a config file with the options entered, one per line. The configuration file looks like this:</p>
<pre>~/geodata/OSM$ cat template.txt
mapname: 05042010
description: Bosnia&amp;Herzegovina
country-name: Bosnia
country-abbr: BH
region: Sarajevo
gmapsupp
tdbfile
latin1</pre>
<p>All the mkgmap options are well explained in the <a href="http://wiki.openstreetmap.org/wiki/Mkgmap">OSM Wiki.</a> If you&#8217;re going to upload several OSM maps to the GPS  string them onto the command. And the tdbfile option will be required in the next step.  Now just run:</p>
<pre>~/geodata/OSM$ mkgmap -c template.txt bosnia.osm</pre>
<p>and you get a *.tdb file (along with the *.img files) which will be needed for upload to the GPS.</p>
<p>Next, to connect to my Garmin etrex Legend, I used the QLandKarte GT application.  While there&#8217;s an Ubuntu deb available for this software, it seems that it&#8217;s a minor version behind, and the latest version 0.18 has some fixes specifically for Garmin. So rather than use the binary from Ubuntu,  I downloaded both <a href="http://www.qlandkarte.org/index.php?option=com_content&amp;view=article&amp;id=3&amp;Itemid=4">QLandKarte GT</a> and their <a href="http://www.qlandkarte.org/index.php?option=com_content&amp;view=article&amp;id=15&amp;Itemid=17">Garmin Drivers</a> from their svn repository. For compiling, you&#8217;ll need cmake, qt4, and both proj4 and gdal,  all available from the regular Ubuntu and the UbuntuGIS repositories. You can compile following <a href="http://sourceforge.net/apps/mediawiki/qlandkartegt/index.php?title=Compiling_QLandkarte_GT_on_Kubuntu">these </a> instructions. I found one &#8220;gotcha&#8221; that needs to be fixed by hand. On Ubuntu 10.04 we already have gdal 1.7.2. But the cmake script that searches for GDAL only looks for versions up to 1.6.0. So I did a quick edit of the file:</p>
<pre>&lt;your download location&gt;/QLandkarteGT/cmake/Modules/FindGDAL.cmake</pre>
<p>and added the line:</p>
<pre>gdal1.7.0</pre>
<p>to the find_library(GDAL_LIBRARY)  section after line 47.</p>
<p>I didn&#8217;t need to change any other of the cmake defaults, and</p>
<pre>make &amp;&amp; sudo make install</pre>
<p>ran successfully. Next I did cmake for the Garmin drivers, and also make &amp;&amp; sudo make install, without any problems. It deserves mention that Ubuntu (and other distros) come with a kernel driver for garmin called garmin_gps, which apparently<span style="text-decoration: underline;"> doesn&#8217;t</span> work well. This kernel module needs to be removed and blacklisted. (Many distros by default have it blacklisted). So if you ask:</p>
<pre>~/geodata/OSM$ lsmod | grep garmin
~/geodata/OSM$</pre>
<p>If lsmod returns nothing, you&#8217;re OK. If, on the other hand, the module is loaded, then do</p>
<pre>~/geodata/OSM$ sudo rmmod garmin_gps</pre>
<p>and furthermore, edit your /etc/modprobe.d/blacklist.conf. Make sure it has a line</p>
<pre>blacklist garmin_gps</pre>
<p>We&#8217;re now ready to startup the QLandKarte application, and from the menu File-&gt;Load Map, choose the tdb file created earlier by mkgmap. You will then get a window asking which &#8220;basemap&#8221; to load. This will be the map name of 8 digits that you entered in the mkgmap configuration file earlier. The map will load (click Map-&gt;Center Map or F3 if it doesn&#8217;t appear). Next go into Setup-&gt;General-&gt;Device &amp; Xfer to select your GPS make and model. Now from the Map menu choose Select Submap (or F5) and drag the mouse over the tiles you need.</p>
<p>On the bottom left should be the &#8220;Selected Maps&#8221; pane. Click on gmapsupp and then click the &#8220;Export&#8221; button. In the &#8220;Create gmapsupp&#8221; window first click the &#8220;browse&#8221; button on the right, and choose a destination directory on your computer, then click Export (creating this local copy makes the upload faster).</p>
<div id="attachment_689" class="wp-caption alignright" style="width: 186px"><a href="http://www.surfaces.co.il/wp-content/uploads/2010/06/sarajevo.bmp"><img class="size-full  wp-image-689 " style="margin: 10px;" title="sarajevo" src="http://www.surfaces.co.il/wp-content/uploads/2010/06/sarajevo.bmp" alt="Garmin screen shot" width="176" height="220" /></a><p class="wp-caption-text">Screen shot of Garmin GPS with OSM layers as basemap</p></div>
<p>Finally, it&#8217;s time to fire up your GPS, and connect the USB cable to the computer. In the GPS Main menu, choose Setup-&gt;Interface. It should say USB (GARMIN format) and &#8220;Connected&#8221;. Now press the rocker button on the GPS, and you&#8217;ll see a blue screen with an image of a computer and GPS connected by a cable. You&#8217;re now in &#8220;Data Transfer&#8221; mode. Back in QLandKarte GT, in the Main window, click the Export button in the lower left corner again. But this time when you click the browse button go to the directory /media. You&#8217;ll see a directory named something like /media/6634-3422. That&#8217;s the Micro SD in your Garmin. You must put the gmapsupp.img into a subdirectory &#8220;garmin&#8221; on the Micro SD card.  If there&#8217;s no &#8220;garmin&#8221; directory, you should be able to open the Micro SD from Ubuntu&#8217;s &#8220;Places&#8221; and just create the dir. Then, from QLandKarte, use the Export button to place the gmapsupp.img file there.</p>
<p>Now close QLandKarte,  disconnect the GPS, and restart it. When the GPS comes back up you should have the new basemap available from the Setup-&gt;Map screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=682</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Manipulating PostGIS layers from GRASS</title>
		<link>http://www.surfaces.co.il/?p=645</link>
		<comments>http://www.surfaces.co.il/?p=645#comments</comments>
		<pubDate>Sat, 24 Apr 2010 16:56:15 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=645</guid>
		<description><![CDATA[GRASS users realize, right from the start, that GRASS maintains its own internal format for vector and raster layers. Whenever you want to use GRASS modules on GIS layers from some other source you first must import the data layers into GRASS, then run your analysis, and if necessary, export back to a required format. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://grass.osgeo.org/">GRASS</a> users realize, right from the start, that GRASS maintains its own internal format for vector and raster layers. Whenever you want to use GRASS modules on GIS layers from some other source you first must import the data layers into GRASS, then run your analysis, and if necessary, export back to a required format.</p>
<p>But suppose you need to manipulate attributes of a vector layer that&#8217;s already stored in a <a href="http://www.postgis.org/">PostGIS</a> spatial database. A typical example: I have a GIS layer of rain gauges, stored in PostGIS. I need to add a column to the layer&#8217;s attribute table for elevation, and then get the elevation for each gauge from a <span style="text-decoration: underline;">GRASS based</span> DEM (Digital Elevation Model) raster. <span id="more-645"></span></p>
<p>There are three approaches. For this post I&#8217;ll call them:</p>
<ol>
<li><strong>Import-Export:</strong> The usual, long but straight-forward way</li>
<li><strong>Duplicate table</strong>: Also somewhat long, but saves having two layers in PostGIS</li>
<li><strong>Hop Skip and Jump</strong>: This suggestion I owe to <a href="http://jduck.net/">Jonah Duckles</a>. A bit harder to follow, but it avoids any duplication of layers or attribute tables.</li>
</ol>
<p>The conventional <strong>Import-Export</strong> method involves importing the point vector from PostGIS into GRASS, adding the required attribute column and updating its values in GRASS, then exporting back out to PostGIS. But you end up with a second PostGIS vector layer, equivalent to the first with the addition of the required elevation column. Now you must use PostgreSQL tools to drop the original table and rename the new one to the original name.</p>
<p>Briefly&#8230;</p>
<p>(we&#8217;ll assume a PostGIS vector called <em>gauges</em>, and the GRASS elevation raster called <em>dem</em>)</p>
<p># Set up the data source  details</p>
<pre style="padding-left: 30px;">export HOST=&lt;Your PostGIS hostname&gt;</pre>
<pre style="padding-left: 30px;">export DB=&lt;Your PostGIS database name&gt;</pre>
<pre style="padding-left: 30px;">export USER=&lt;Your PostGIS administrator name&gt;</pre>
<pre style="padding-left: 30px;">export PASS=&lt;Your PostGIS admin password&gt;</pre>
<pre style="padding-left: 30px;">export DSN="PG:host=${HOST} dbname=${DB} user=${USER} password=${PASS}"</pre>
<pre style="padding-left: 30px;">v.in.ogr dsn=${DSN} layer=gauges out=gauges_tmp</pre>
<p># We now have a duplicate of the original PostGIS vector stored totally (geometry and attributes) in GRASS</p>
<p># Add the new column for <em>elevation</em> values</p>
<pre style="padding-left: 30px;">v.db.addcol gauges_tmp col="elevation double precision"</pre>
<p># check attribute table</p>
<pre style="padding-left: 30px;">v.info -c gauges</pre>
<p># Now get the elevation values from the raster</p>
<pre style="padding-left: 30px;">v.what.rast vect=gauges_tmp rast=dem col=elevation</pre>
<p># check elevation values:</p>
<pre style="padding-left: 30px;">v.db.select gauges_tmp col=gauge_id,elevation</pre>
<p>If everything looks good, export back to PostGIS:</p>
<pre style="padding-left: 30px;">v.out.ogr in=gauges_tmp dsn=$DSN type=point format=PostgreSQL</pre>
<p>Now you should have in PostGIS two point layers, with the same features, and the <em>gauges_tmp</em> table should have the additional elevation column. What&#8217;s left is to drop (or rename) the original table and rename the new one to the original name. (Double check that the new <em>gauges_tmp</em> table contains all the features before continuing!)</p>
<pre style="padding-left: 30px;">psql -h ${HOST} -d ${DB} -U ${USER} -c "ALTER TABLE gauges RENAME TO gauges_orig"
psql -h ${HOST} -d ${DB} -U ${USER} -c "ALTER TABLE gauges_tmp RENAME TO gauges"</pre>
<p>In PostGIS spatial tables also appear in the <em>geometry_columns</em> table so be sure to rename the <em>gauges_tmp</em> table to exactly the same name as the original.</p>
<p>Now on to the second <strong>Duplicate table</strong> method.<br />
This way involves setting the database connection in GRASS to store attribute tables straight in PostgreSQL, then import as before the original <em>gauge</em>s layer. This will create a GRASS vector in which the geometry is in GRASS (as always) but the attributes are kept right in PostgreSQL. Then run the v.what.rast command, and the new elevation values are updated right into the new PostGIS table. The final step is to copy those elevation values from this new attribute table to the original <em>gauges</em> layer. Here are the steps:</p>
<p># First check current database connection and take note of the settings. We&#8217;ll need these parameters to revert to this database connection after the procedure.</p>
<pre style="padding-left: 30px;">db.connect -p &gt;&gt; connection.txt
db.connect driv=pg database="host=${HOST},dbname=${DB}"
db.login user=${USER} password=${PASS}</pre>
<p># and import the original <em>gauges</em> just like before</p>
<pre style="padding-left: 30px;">v.in.ogr dsn=${DSN} layer=gauges out=gauges_tmp</pre>
<p># This creates a GRASS vector, but the attribute table is now stored right in your PostGIS database. We&#8217;re ready to add the required elevation column and get values from the GRASS dem.</p>
<pre style="padding-left: 30px;">v.db.addcol gauges_tmp col="elevation double precision"
v.what.rast vect=gauges_tmp rast=dem col=elevation
</pre>
<p>All that remains now is to run two PostgreSQL commands: add an elevation column to the original table and update its values from the <em>gauges_tmp</em> table:</p>
<pre style="padding-left: 30px;">psql -h ${HOST} -d ${DB} -U ${USER} -c "ALTER TABLE gauges ADD COLUMN elevation float"
psql -h ${HOST} -d ${DB} -U ${USER} -c "UPDATE gauges SET elevation=gauges_tmp.elevation FROM gauges_tmp WHERE gauges_tmp.gauge_id=gauges.gauge_id"</pre>
<p>The &#8220;WHERE&#8221; clause insures that the correct elevation values are entered into the permanent <em>gauges</em> layer based on the <em>gauge_id</em> column. Finish by removing the <em>gauges_tmp</em> layer (Its accompanying database attribute table will also be dropped).</p>
<pre style="padding-left: 30px;">g.remove vect=gauge_tmp</pre>
<p>And don&#8217;t forget to reset the database connection back to the original values (We saved the parameters into the file connection.txt):</p>
<pre style="padding-left: 30px;">cat connection.txt
db.connect driv=... database=...</pre>
<p>On to the <strong>Hop Skip and Jump</strong> method.</p>
<p>First I should note that this trick works only for point vectors. If you need to update attribute values for PostGIS based line or area features, this won&#8217;t work. Use one of the first two ways.</p>
<p>The process involves three routines that can be chained into a one-line command. First we take advantage of the GRASS v.external module to have access to externally stored vectors. This modules gives us a<span style="text-decoration: underline;"> read-only</span> representation in GRASS of an externally stored vector. Then, with the v.out.ascii command we get a list of the X-Y coordinates for all the points in this vector. These coordinates are piped as input to the r.what module which outputs the raster value at each of the input point locations. The output from this raster command is then fed into a psql statement to update the original database directly. <span style="text-decoration: underline;">No interim tables</span> are needed at all. Here we go:</p>
<pre style="padding-left: 30px;">v.external dsn=${DSN} layer=gauges out=gauges_tmp</pre>
<p># Now the one-liner</p>
<pre style="padding-left: 30px;">v.out.ascii in=gauges_tmp fs=" " columns="gauge_id" | \
r.what in=dem fs=" " | \
sed '/\*/d' | \
awk '{print "UPDATE gauges SET elevation="$5 " WHERE gauge_id="$4}' &gt;&gt; update_gauges.sql</pre>
<p>Here&#8217;s the &#8220;play by play&#8221;:</p>
<p>As I mentioned, v.out.ascii creates a list of X-Y coordinates, including the GRASS <em>cat</em> values, and also the <em>gauge_id</em>, added by the <em>columns=</em> parameter. This list is input to r.what which just adds at the end of each line the raster value at that X-Y location. But r.what will output an asterisk &#8216;*&#8217; when no value is available (i.e for points outside the region of the raster). We don&#8217;t want these lines in the output, so the sed command deletes them.</p>
<p>The resulting list gets piped thru the awk command to create a list of PostgreSQL UPDATE commands, where the <em>elevation</em> values are taken from column 5 in the input, and the <em>gauge_id </em>is from column 4. (Columns 1,2 are the coords, column 3 the cat value. Thus column 4 is the gauge_id and column 5 the raster value).</p>
<p># Check the results carefully for any anomolies&#8230;</p>
<pre style="padding-left: 30px;">less update_gauges.sql</pre>
<p># If all is OK, just run this file through psql:</p>
<pre style="padding-left: 30px;">
<pre style="padding-left: 30px;">psql -h ${HOST} -d ${DB} -U ${USER} -c "ALTER TABLE gauges ADD COLUMN elevation float"
psql -h ${HOST} -d ${DB} -U ${USER} -f update_gauges.sql</pre>
</pre>
<p>Quick and elegant. If you&#8217;re confident that the above string of commands creates correct sql UPDATE statements, you can even do away with the <em>update_gauges.sql</em> file and pipe the list straight into psql.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=645</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Welcome, Gerardus</title>
		<link>http://www.surfaces.co.il/?p=631</link>
		<comments>http://www.surfaces.co.il/?p=631#comments</comments>
		<pubDate>Sat, 27 Mar 2010 17:08:33 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=631</guid>
		<description><![CDATA[MS: Hello Mr. Mercator. It&#8217;s an honor to host you here in the twenty first century. GM: I&#8217;m quite excited to be here. MS: We have many questions for you, and much to discuss. Shall we begin with the map projection named after you, the Mercator projection? How did you come to realize that stretching [...]]]></description>
			<content:encoded><![CDATA[<p>MS: Hello Mr. Mercator. It&#8217;s an honor to host you here in the twenty first century.</p>
<p>GM: I&#8217;m quite excited to be here.</p>
<p>MS: We have many questions for you, and much to discuss. Shall we begin with the map projection named after you, the Mercator projection? How did you come to realize that stretching the spaces between parallels would aid sea navigation?<span id="more-631"></span></p>
<p>GM: Actually it was the opposite. As exploration missions expanded and reached further abroad, we were getting measurements back from navigators that were inconsistent. The more we investigated, we began to notice that navigators would mark the positions of coastlines that they reached on their captain&#8217;s logs after sailing for weeks at a constant compass direction. But a rhumb line on a sphere is not a straight line on a flat map. So we corrected that with our new representation of the earth.</p>
<p>MS: Did you understand at the time the severe distortion in area and size that your map projection introduced?</p>
<p>GM: I think you exaggerate. After all, distortion appears only near the poles in the far north and south. We had very little interest in these areas. What&#8217;s more, when sailing north or south, near to the meridian of departure, sea navigators could find there location quite well with the mariner&#8217;s quadrant. Only those explorers who ventured far west or east encountered difficulty in determining their location since they had no reliable chronometer.</p>
<p>MS: Why was that so important?</p>
<p>GM: Well, I&#8217;m surprised you ask.  As any beginning student of geography understands, a navigator can find his latitude very accurately by siting the angle of Polaris. However the only way he can determine his longitude is by comparing the angle of the sun or stars in the sky at his current position with the angle at some know location at exactly the same time of day. So he must know the hour precisely. And, of course, we have no instrument which could keep time accurately at sea, with the swaying of the vessel, and corrosive effects of salt spray. Perhaps some new, advanced technologies have led to a reliable, sea-worthy chronograph?</p>
<p>MS: Yes, well the first real chronometer for navigation was build by an English clock maker, John Harrison, 100 years after your death. Today we have clocks and watches that are water-proof, and stay very accurate for years. But navigation as well as map making now uses GPS.</p>
<p>GM: GP what?</p>
<p>MS: There are 24 satellites in orbit around the earth at about 11,000 km altitude. They circle the earth twice every day.</p>
<p>GM: Mijn God! You have man made instruments in the heavens! And they imprisoned  me as a heretic for drawing different maps&#8230; So what do these &#8220;satellites&#8221; do?</p>
<p>MS: They constantly send a signal which contains the satellite&#8217;s identity and the precise time.  Anyone using a simple hand-held GPS can receive those signals, and the instrument can determine your location to within 10 meters.</p>
<p>GM: This all sounds like a fairy tale. How could such a small instrument possibly find locations so accurately?</p>
<p>MS: As I said, the instrument picks up signals from several of the satellites, and it compares the time differences from the different satellites.  From the gaps in time it calculates the distance to each of the satellites, and thus by doing a kind of triangulation of these distances, it can zero in on the current location.</p>
<p>GM: I shall not believe any of this until I see it for myself.  In any case, map makers today will still need my method to properly spread the terrestrial globe unto a planar map.</p>
<p>MS: In fact we have thousands of map projections in use today. Each country has it&#8217;s own local grid. Some have several regional grids. All are designed to ensure that surveys done in different locations are all synchronized and match. So, you see that your dream of creating a world map by combining many local, independent maps has, in a round about way, been fulfilled.</p>
<p>GM: So many different methods of projection. That must be a nightmare to transform surveys from one projection to another.</p>
<p>MS: That&#8217;s all done by computers.</p>
<p>GM: You must employ many of these computers, and they all must be highly trained in mathematics, earning respectable salaries.</p>
<p>MS: No, computers are electronic instruments that perform mathematical calculations very rapidly. These computers are programmed with instructions we call &#8220;software&#8221; to carry out many, many complex calculations. In fact, today cartographers use computers to design and produce maps. All the geographical data is kept inside the computer&#8217;s memory, and the cartographer can choose which data he wants, and how to display it. Many versions of a map, at many different scales can be produced and printed in a short time.</p>
<p>GM: So you have instruments orbiting in the heavens, instruments for finding your location, instruments for doing mathematics and creating maps. This is all very fatiguing.  I must take a rest now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=631</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Two Different Graticules with QGIS</title>
		<link>http://www.surfaces.co.il/?p=616</link>
		<comments>http://www.surfaces.co.il/?p=616#comments</comments>
		<pubDate>Sat, 06 Mar 2010 20:06:09 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=616</guid>
		<description><![CDATA[Quantum GIS now has a well thought out grid feature to add a grid or graticule to your map layout. It&#8217;s implemented in the Print Composer as part of the map item. However sometimes you require two grids representing different Coordinate Reference Systems on the same map. The grid feature creates the grid in the [...]]]></description>
			<content:encoded><![CDATA[<p>Quantum GIS now has a well thought out grid feature to add a grid or graticule to your map layout. It&#8217;s implemented in the Print Composer as part of the map item. However sometimes you require <span style="text-decoration: underline;">two</span> grids representing different Coordinate Reference Systems on the same map. The grid feature creates the grid in the project&#8217;s current CRS. In order to display a second grid in some other CRS, you&#8217;ll need a trick outlined in <a href="http://www.surfaces.co.il/?p=367">this post</a>.</p>
<p><span id="more-616"></span></p>
<p><img title="More..." src="http://www.surfaces.co.il/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></p>
<p>So, suppose we want to make a map displaying both Lon-Lat geographic coordinates, and a local CRS. Begin by loading a layer covering the region of interest and setting the project CRS to EPSG:4326 (Lon-Lat, WGS84) with on-the-flye projection enabled. Now use the &#8220;Vector-&gt;Research Tools-&gt;Vector Grid&#8221; option to create a grid with the spacing and extents required. Once the grid shapefile is created, open it&#8217;s *.dbf file in Openoffice.org Calc and, following the details in the above post,  add columns for X_OFFSET, Y_OFFSET, ANGLE, and INTERVAL. The offsets you will enter refer to the <span style="text-decoration: underline;">current CRS</span> (Lon-Lat WGS84 in this case). Once you have that setup, display this new grid shapefile with labels. You&#8217;ll use the label options (as explained in the same post mentioned above) to set the angle and X and Y coordinates to get the labels placed around the edges of your map.</p>
<p>Now <span style="text-decoration: underline;">change the project&#8217;s CRS</span> to whatever the second grid should be, and maintain <span style="text-decoration: underline;">on-the-fly projection</span> enabled. You&#8217;ll notice that the first Lon-Lat grid will now be slightly &#8220;distorted&#8221; due to the reprojection.  Open the Print Composer, and add a Map element. In the Map Item configuration window, go to the Grid tab, and check &#8220;Show Grid?&#8221;. Set up the intervals, and fonts, etc for the grid. This grid will represent the project&#8217;s projected coordinate system.</p>
<p>Here&#8217;s an example. The data were obtained from the <a href="http://www.naturalearthdata.com/">Natural Earth data</a> website, and reprojected within QGIS to Jordan Transverse Mercator &#8211; EPSG:3066 (the blue lines). The red coordinate grid represents Lon-Lat geographic coordinates:</p>
<p style="text-align: center;">
<div id="attachment_618" class="wp-caption aligncenter" style="width: 852px"><a href="http://www.surfaces.co.il/wp-content/uploads/2010/03/Middle_East_JTM2.png"><img class="size-full wp-image-618 " title="Middle_East_JTM2" src="http://www.surfaces.co.il/wp-content/uploads/2010/03/Middle_East_JTM2.png" alt="Middle east map" width="842" height="595" /></a><p class="wp-caption-text">Map of Middle east, Jordan Transverse Mercator projection</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=616</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Creating contour lines directly in QGIS</title>
		<link>http://www.surfaces.co.il/?p=595</link>
		<comments>http://www.surfaces.co.il/?p=595#comments</comments>
		<pubDate>Thu, 04 Mar 2010 17:02:44 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=595</guid>
		<description><![CDATA[To follow up my last post on isohyetal lines, I want to check out the new Contours plugin authored by Lionel Roubeyrie and compare the results to contour lines created with GRASS. With no futhur ado here&#8217;s the result: The green lines are my original isohyetal lines (made with GRASS). The blue lines are based [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">
<p style="text-align: left;">To follow up my <a href="http://www.surfaces.co.il/?p=578">last post</a> on isohyetal lines, I want to check out the new Contours plugin authored by Lionel Roubeyrie and compare the results to contour lines created with GRASS. With no futhur ado here&#8217;s the result:</p>
<p style="text-align: left;"><span id="more-595"></span></p>
<div id="attachment_606" class="wp-caption aligncenter" style="width: 542px"><a href="http://www.surfaces.co.il/wp-content/uploads/2010/03/isohyets_plugin2.png"><img class="size-full wp-image-606   " title="isohyets_plugin2" src="http://www.surfaces.co.il/wp-content/uploads/2010/03/isohyets_plugin2.png" alt="" width="532" height="753" /></a><p class="wp-caption-text">Two methods for creating contour lines</p></div>
<p style="text-align: center;">
<p style="text-align: left;">The green lines are my original isohyetal lines (made with GRASS). The blue lines are based on the same rainfall data  with the Contour plugin, and choosing 12 levels of contours. The plugin doesn&#8217;t have an option to set interval, rather the number of levels. Thus the values will not be identical to the original run. In the center area the two sets of lines pretty much follow each other. What is obvious to me is the &#8220;confusion&#8221; around the edges. While the GRASS algorithm does fairly good extrapolation outside the area covered by data, the Contour plugin seems to just &#8220;cut off&#8221;. So the next test should be with a higher density of points and restricted to the region actually covered by data.</p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=595</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Creating isohyetal lines in QGIS</title>
		<link>http://www.surfaces.co.il/?p=578</link>
		<comments>http://www.surfaces.co.il/?p=578#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:01:24 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=578</guid>
		<description><![CDATA[We had a pretty extraordinary rain storm in our region some weeks ago. Accumulated rainfall over a 24 hr period was between 20-100 mm in a region where the total annual precipitation is about 50 mm.! I got rain gauge data for the event and made isohyetal lines using only tools available in Quantum GIS. [...]]]></description>
			<content:encoded><![CDATA[<p>We had a pretty extraordinary rain storm in our region some weeks ago. Accumulated rainfall over a 24 hr period was between 20-100 mm in a region where the <strong>total annual </strong> precipitation is about 50 mm.! I got rain gauge data for the event and made <a href="http://en.wikipedia.org/wiki/Isohyet#Precipitation_and_air_moisture">isohyetal lines</a> using only tools available in Quantum GIS.<br />
<span id="more-578"></span><br />
First I imported the data table including XY locations and the precipitation with the Delimited Text plugin. Then, in order to limit the analysis more or less to the area covered by the rain gauges, I made a &#8220;convex hull&#8221;, the minimum polygon enclosing all points, and buffered that polygon by 10 km. (allowing that the interpolation algorithm will give approximate values outside the area covered by the gauges).  Both of these operations are available in the Vector-&gt;Geoprocessing menu.</p>
<p>Now I fired up the GRASS plugin to do the interpolation. Using the v.in.ogr.qgis module, I loaded both the rain gauge point vector and the buffer polygon vector into a suitable GRASS Location/Mapset. First I converted the buffer polygon to a raster so that I could use it as a mask with v.to.rast. After adding the two GRASS layers to the map &#8211; the rain gauges, and the mask raster,  I pulled up the r.mask module to force the next action to be limited to the buffer region. Then I ran v.surf.rst to produce an interpolated rainfall grid. I chose, of course, the precipitation column as the attribute field for doing the interpolation. The new precipitation grid was created in a few moments, and I closed the GRASS toolbox.</p>
<p>Now I activated the new GDALTools Raster plugin. Among the tools there is &#8220;Contours&#8221;. I ran this tool, choosing the GRASS precipitation raster as input. I left the default levels value at 10, and chose an output directory where the contours shapefile will be saved. I also checked &#8220;Attribute Name&#8221; and typed in &#8220;Precip&#8221;. The contours were created and here&#8217;s my resulting map:</p>
<div id="attachment_585" class="wp-caption alignnone" style="width: 622px"><a href="http://www.surfaces.co.il/wp-content/uploads/2010/02/isohyets2.png"><img class="size-full wp-image-585 " title="isohyets2" src="http://www.surfaces.co.il/wp-content/uploads/2010/02/isohyets2.png" alt="isohyets" width="612" height="868" /></a><p class="wp-caption-text">Precipitation map - january 2010</p></div>
<div class="mceTemp">
<dl id="attachment_580" class="wp-caption alignleft" style="width: 1059px;">
<dt class="wp-caption-dt"></dt>
<dd class="wp-caption-dd">Precipitation map &#8211; Jan 2010</dd>
</dl>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=578</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>From Fedora 12 to a GIS workstation (part 3)</title>
		<link>http://www.surfaces.co.il/?p=523</link>
		<comments>http://www.surfaces.co.il/?p=523#comments</comments>
		<pubDate>Wed, 27 Jan 2010 15:16:32 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=523</guid>
		<description><![CDATA[This is my third installment on setting up a Fedora 12 GIS workstation. The procedures below for compiling the actual GIS &#8220;front-end&#8221; programs rely on the software and the way it was setup from the first and second articles. So if you want to follow step by step, go back and review those before plunging into [...]]]></description>
			<content:encoded><![CDATA[<p>This is my third installment on setting up a Fedora 12 GIS workstation. The procedures below for compiling the actual GIS &#8220;front-end&#8221; programs rely on the software and the way it was setup from the <a href="http://www.surfaces.co.il/?p=390">first</a> and <a href="http://www.surfaces.co.il/?p=468">second</a> articles. So if you want to follow step by step, go back and review those before plunging into this one.</p>
<p><span id="more-523"></span></p>
<p><span style="text-decoration: underline;"><strong>GRASS</strong></span></p>
<p>Now we&#8217;re ready (almost) for compiling GRASS. First get more pre-requisites:</p>
<pre>~/Download$ <strong>sudo yum install tcl tcl-devel tk-devel fftw2 fftw2-devel libXmu libXmu-devel</strong></pre>
<p>The Swig conundrum:  SWIG is an interface that &#8220;dresses&#8221; C/C++ programs for use in scripting languages like python. It seems that the installed version in F12, 1.3.40, has some change that makes it <a href="http://n2.nabble.com/fix-for-broken-wxGUI-on-Linux-tt3743757.html#none">incompatible</a> with certain parts of the GRASS python interface. The recommendation at this point is to roll back to an earlier version of SWIG (<em>Note: if you skip this step, GRASS will be <span style="text-decoration: underline;">fully functional </span>in both the CLI and the tcl/tk interface but some parts of the wxpython interface won&#8217;t work)</em>. You&#8217;ll have to remove the rpm and <a href="http://downloads.sourceforge.net/project/swig/swig/swig-1.3.36/swig-1.3.36.tar.gz?use_mirror=garr">download</a> the older 1.3.36 version. To successfully do the compile you need the perl devel package (and others that we&#8217;ve already added). So here are the steps:</p>
<pre>~/Download$ <strong>sudo yum install perl-devel</strong>
~/Download$<strong> sudo yum remove swig</strong>
~/Download$<strong> tar xvzf swig-1.3.36.tar.gz</strong>
~/Download$ <strong>cd swig-1.3.36</strong>
~/Download/swig-1.3.36$ <strong>./configure</strong>
~/Download/swig-1.3.36$ <strong>make &amp;&amp; make check</strong>
~/Download/swig-1.3.36$<strong> sudo make install</strong></pre>
<p>On to GRASS itself. Download the  <a href="http://grass.osgeo.org/grass64/source/grass-6.4.0RC5.tar.gz">GRASS source code</a> for version 6.4, and as always, unzip the source and go into that directory.</p>
<p>Here&#8217;s my configure line:</p>
<pre>~/Download/grass-6.4.0RC5$ <strong>./configure --prefix=/usr/local/grass-6.4  \
      --with-proj-share=/usr/share/proj  \
      --with-postgres  \
      --enable-largefile  \
      --with-sqlite  \
      --with-freetype --with-freetype-includes=/usr/include/freetype2  \
      --with-python --with-wxwidgets  \
      --with-cxx</strong></pre>
<p>The freetype include headers are in an unusual place: /usr/include/freetype2/freetype. GRASS apparently always looks in a subdir called &#8216;include&#8217;.  So in order to get GRASS to recognize the freetype headers I had to do:</p>
<pre>~/Download/grass-6.4.0RC5$ <strong>cd /usr/include/freetype2</strong>
/usr/include/freetype2$ <strong>sudo ln -s freetype include</strong></pre>
<p>then the above compile line worked. Also don&#8217;t forget to add &#8211;with-cxx, (otherwise you won&#8217;t have the python digitizer)</p>
<p>Now run make and make install</p>
<pre>/usr/include/freetype2$ <strong>cd ~/Download/grass-6.4.0RC5</strong>
~/Download/grass-6.4.0RC5$ <strong>make</strong>
~/Download/grass-6.4.0RC5$ <strong>sudo make install</strong></pre>
<p>Next we&#8217;ll be installing Quantum GIS. The path to the grass lib directory must be added to a conf file in ld.so.conf.d (for the same reason explained in the <a href="http://www.surfaces.co.il/?p=390">earlier post</a> in the ECW section). In my case I create a file  /etc/ld.so.conf.d/grass-6.4 which contains one line:</p>
<pre><strong>/usr/local/grass-6.4/grass-6.4.0RC5/lib</strong></pre>
<p>then run: $<strong>sudo ldconfig</strong></p>
<p>At this point we have one more step before moving on to Qunatum GIS. We compiled GDAL earlier without GRASS support.  That&#8217;s fine if you don&#8217;t need access to GRASS rasters when using the gdal tools. If you do want to manipulate GRASS rasters using GDAL tools, or more importantly, in order to access GRASS raster from QGIS (which depends on GDAL) then you want the <span style="text-decoration: underline;">gdal-grass plugin</span>. It&#8217;s quick and simple. Download the lastest <a href="http://download.osgeo.org/gdal/gdal-grass-1.4.3.tar.gz">version 1.4.3</a> and after opening the tar archive do the usual:</p>
<pre>~/Download/gdal-grass-1.4.3$<strong> ./configure --with-grass=/usr/local/grass-6.4/grass-6.4.0RC5</strong>
~/Download/gdal-grass-1.4.3$ <strong>make &amp;&amp; sudo make install</strong></pre>
<p><span style="text-decoration: underline;"><strong>QGIS</strong></span></p>
<p>Prepare for Quantum GIS with:</p>
<pre>~/Download$<strong> sudo yum install cmake gsl gsl-devel geos-devel expat expat-devel</strong></pre>
<p>Download the <a href="http://download.osgeo.org/qgis/src/qgis_1.4.0.tar.gz">QGIS source code</a> for version 1.4, unzip it and drop into that directory.</p>
<p>Following more or less Tim Sutton&#8217;s <a href="http://linfiniti.com/2009/11/compiling-qgis-under-ubuntu-9-10/">blog post</a> or my earlier <a href="../?p=340">instructions</a> regarding Fedora 10, invoke these commands:</p>
<pre>~/Download$ <strong>cd qgis-1.4.0/</strong>
~/Download$ <strong>mkdir build</strong>
~/Download/qgis-1.4.0$ <strong>cd build</strong>
~/Download/qgis-1.4.0/build$ <strong>cmake -L ..</strong></pre>
<p>(Be sure to add the &#8216;..&#8217; at the end of the cmake command).  Now check thru the list of cmake parameters to make sure all the dependencies were found.  You tune these paths or variables as necessary with the -D option to cmake. In my case I need to indicate where GRASS is located (note the &#8211;prefix option in my GRASS compilation previously), and I want to set the final install location to a specific directory under /usr/local for this version of QGIS, so:</p>
<pre>~/Download/qgis-1.4.0/build$ <strong>cmake -L -DGRASS_PREFIX:PATH=/usr/local/grass-6.4/grass-6.4.0RC5 -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/qgis-1.4.0 ..</strong></pre>
<p>With that set up we&#8217;re ready for:</p>
<pre>~/Download/qgis-1.4.0/build$ <strong>make</strong>
~/Download/qgis-1.4.0/build$ <strong>sudo make install</strong></pre>
<p><span style="text-decoration: underline;"><strong>R statistics</strong></span></p>
<p>No GIS workstation is complete without  R and its spatial packages.</p>
<pre>~/Download$ <strong>sudo yum install R-core rpy R-devel xml2 libxml2 libxml2-devel</strong></pre>
<p>Fire up R and run:</p>
<pre>&gt; <strong>install.packages("sp",dependencies=TRUE)</strong>
&gt; <strong>install.packages("spgrass6",dependencies=TRUE)</strong></pre>
<p>The R install.packages() function wants to put R libraries into /usr/lib/R/library and the html manuals into /usr/share/doc/R-x.x.x by default. Since these locations are writable only by root, either give yourself necessary permissions on those directories, or (preferably) in the install.packages() functions add the lib=&#8221;&#8230;&#8221; parameter to create an R library in your home dir.</p>
<p>Whew! Congratulations, you&#8217;re now the proud owner of an advanced Linux based GIS workstation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=523</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>From Fedora 12 to a GIS workstation (part 2)</title>
		<link>http://www.surfaces.co.il/?p=468</link>
		<comments>http://www.surfaces.co.il/?p=468#comments</comments>
		<pubDate>Sat, 23 Jan 2010 19:33:22 +0000</pubDate>
		<dc:creator>Micha Silver</dc:creator>
				<category><![CDATA[GIS]]></category>

		<guid isPermaLink="false">http://www.surfaces.co.il/?p=468</guid>
		<description><![CDATA[Last time I finished with a working HDF library. So at this point we should have the basic functionality to read HDF files.  Now is the time to jump over to NASA&#8217;s WIST site where one can find all sorts of juicy remote sensing data. The site requires registering, but it&#8217;s well worth the (somewhat [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.surfaces.co.il/?p=390">Last time</a> I finished with a working HDF library. So at this point we should have the basic functionality to read HDF files.  Now is the time to jump over to NASA&#8217;s <a href="https://wist.echo.nasa.gov/api/">WIST </a>site where one can find all sorts of juicy remote sensing data. The site requires registering, but it&#8217;s well worth the (somewhat long) procedure. Once you&#8217;re in, you can obtain all the Landsat TM and ETM imagery. And this is the place for grabbing the new ASTER DEM tiles. (For those who haven&#8217;t heard: it&#8217;s global elevation data at 30 m. resolution &#8211; three times better than the legendary SRTM &#8211; only lacking the bathymetric depths).  For this exercise I&#8217;ll be searching for vegetation index data from the MODIS satellite project.</p>
<p><span id="more-468"></span></p>
<p>I won&#8217;t go into the details of wading thru the search and order procedure. The site has it&#8217;s own  <a href="https://wist.echo.nasa.gov/~wist/api/Tutorial/">tutorial</a>. Once you complete the search, and get a list of &#8220;granules&#8221; of data that match your search criteria, you tick which you want, and click the &#8220;Add to cart&#8221; button. Then enter some required order details, and click &#8220;Submit order&#8221;. There are buttons to save query and personal order details to your computer. I suggest to use this feature: makes the next visit smoother.</p>
<p>Some minutes later you&#8217;ll receive three emails. The second, with a subject like: &#8220;LPDAAC ECS Order Notification&#8221; contains the ftp link to download the data you requested. I copy the link and use wget to pull down the zip file.</p>
<pre>~/geodata/MODIS_AQUA$ <strong>wget -c ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301944518RAPMac.zip</strong></pre>
<p>After unzipping the file, l have several *.hdf and *.xml files. Now I can run the hdp utility to quickly check that the file is OK.</p>
<pre>~/geodata/MODIS_AQUA$ <strong>/usr/local/hdf4.2/bin/hdp dumpsds -h MYD13A3.A2003032.h20v04.005.2008056162517.hdf</strong></pre>
<p>which should output a dump of all the headers and data in the file.  Now we&#8217;re ready for bigger and better things.</p>
<p><strong><span style="text-decoration: underline;">GDAL</span></strong></p>
<p>Compile and install GDAL. The source is available <a href="http://download.osgeo.org/gdal/gdal-1.6.3.tar.gz">here</a> for version 1.6.3. Unzip and go into the source directory.</p>
<pre>~/Download$ <strong>cd gdal-1.6.3</strong></pre>
<p>first some additional pre-requisites</p>
<pre>~/Download/gdal-1.6.3$ <strong>sudo yum install sqlite sqlite-devel</strong>
~/Download/gdal-1.6.3$ <strong>sudo yum install postgresql postgresql-devel postgresql-server postgis pgadmin3</strong></pre>
<p>It seems that the external libgeotiff include header files are in their own subdirectory.  So here&#8217;s the configure incantation I used:</p>
<pre>~/Download/gdal-1.6.3$ <strong>CPPFLAGS="-I/usr/include/libgeotiff" ./configure --with-geos --with-sqlite3 --with-ecw=/usr/local/ --with-hdf4=/usr/local/hdf4.2 --with-python</strong>
~/Download/gdal-1.6.3$ <strong>make &amp;&amp; sudo make install</strong>
~/Download/gdal-1.6.3$ <strong>sudo ldconfig</strong></pre>
<p>Now check that the formats we compiled in are indeed available with:</p>
<pre>~/Download/gdal-1.6.3$ <strong>gdalinfo --formats | egrep 'HDF|ECW'</strong>
  HDF4 (ro): Hierarchical Data Format Release 4
  HDF4Image (rw+): HDF4 Dataset
  ECW (rw): ERMapper Compressed Wavelets
  JP2ECW (rw+): ERMapper JPEG2000</pre>
<p>Good. We can now put gdal to work. First, I run gdalinfo on one of the MODIS hdf files.</p>
<pre>~/geodata/MODIS_AQUA$ <strong>gdalinfo MYD13A3.A2003032.h20v04.005.2008056162517.hdf</strong></pre>
<p>This gives me several lines that start with SUBDATASET_x_NAME (&#8216;x is the number of the dataset).  Let&#8217;s run gdal again and filter the results with egrep:</p>
<pre>~/geodata/MODIS_AQUA$ <strong>gdalinfo MYD13A3.A2003032.h20v04.005.2008056162517.hdf | egrep "SUBDATASET_[0-9]_NAME"</strong>
 SUBDATASET_1_NAME=HDF4_EOS:EOS_GRID:"MYD13A3.A2003032.h20v04.005.2008056162517.hdf":MOD_Grid_monthly_1km_VI:1 km monthly NDVI
 SUBDATASET_2_NAME=HDF4_EOS:EOS_GRID:"MYD13A3.A2003032.h20v04.005.2008056162517.hdf":MOD_Grid_monthly_1km_VI:1 km monthly EVI
 SUBDATASET_3_NAME=HDF4_EOS:EOS_GRID:"MYD13A3.A2003032.h20v04.005.2008056162517.hdf":MOD_Grid_monthly_1km_VI:1 km monthly VI Quality
 ....</pre>
<p>Looking thru the results I see that SUBDATASET_2 is the EVI data. We can now run gdalinfo on that single SUBDATASET by feeding it everything on the line after the &#8220;&#8230;_NAME=&#8221; like so:</p>
<pre>~/geodata/MODIS_AQUA/mesopotamia$ <strong>gdalinfo 'HDF4_EOS:EOS_GRID:"MYD13A3.A2003032.h20v04.005.2008056162517.hdf":MOD_Grid_monthly_1km_VI:1 km monthly EVI'</strong></pre>
<p>Note that the whole dataset string is &#8216;quoted&#8217;. The output now shows all the georeference information that gdal finds in that particular  dataset. Next step is to reach into the gdal toolbox again, and pull out gdalwarp. That will allow us to both export the data to a GeoTiff and at the same time to transform it to a CRS that we choose. The input to gdalwarp must be the full dataset name as in the last run of gdalinfo above.</p>
<pre>~/geodata/MODIS_AQUA$ <strong>gdalwarp -of GTiff -t_srs EPSG:4326 -dstnodata "-3000" -dstalpha 'HDF4_EOS:EOS_GRID:"MYD13A3.A2003032.h20v04.005.2008056162517.hdf":MOD_Grid_monthly_1km_VI:1 km monthly EVI' EVI_h20v04.tif</strong></pre>
<p>Note that I add the -dstnodata and dstalpha options to gdalwarp to set the &#8220;nodata&#8221; value in the EVI to NULL. Why &#8220;-3000&#8243; ?  The EVI dataset uses -3000 as it&#8217;s nodata value. Furthermore, a multiplier of 10,000 has been applied so that all values in the HDF are integer. More on that in the next post.</p>
<p>If you&#8217;ve downloaded several HDF files, and converted them to GeoTiff as above, then you probably want to merge them together into one. GDAL offers the gdal_merge.py utility for that:</p>
<pre>~/geodata/MODIS_AQUA$ <strong>gdal_merge.py -o EVI_mesop.tif EVI_*.tif
</strong></pre>
<p>I downloaded vegetation index files for the Tigris-Euphrates rivers drainage basin, thus I chose to name the merged tif &#8220;Mesopotamia&#8221;.</p>
<p><span style="text-decoration: underline;"><strong>HDF Java tools</strong></span></p>
<p>With that under our belt, it&#8217;s time for me to come clean: there&#8217;s an easier way to deal with HDF files. The hdfgroup has some java based utilities that make life simpler: First I&#8217;ll mention <a href="http://www.hdfgroup.org/ftp/HDF5/hdf-java/hdfview/hdfview_install_linux32.bin">HDFView</a> to select and view datasets within an HDF file. And, more importantly, NASA <a href="ftp://edhs1.gsfc.nasa.gov/edhs/HEG_Tool/hegLNXv2.10.tar.gz">offers</a> HEG, the <strong>H</strong>DF-<strong>E</strong>OS to <strong>G</strong>eoTiff conversion tool. This tool does what we did above with gdal: converts to GeoTiff, transforms to a coordinate reference system, and as an extra perk, it merges several tiles at the same time. The installation of both tools is a java binary. So once you&#8217;ve downloaded them:</p>
<pre>~/Download$ <strong>sudo sh ./hdfview_install_linux32.bin</strong></pre>
<p>The java installer is straightforward. Then run the tool  (if you installled in /usr/local) by typing: /usr/local/hdfview/hdfview.  In the java interface you can open an HDF file and drill down to a specific dataset. Then you right-click on the dataset, and choose &#8220;Open As&#8221; and select Image to display an image of the data.</p>
<p>The HEG tool is somewhat tricky. First, it requires full <span style="text-decoration: underline;">write permission</span> on the install directory. So if you are sticking with /usr/local, you must give yourself write permissions there. (Alternatively, just install in your home directory). Second, the tool does not recognize any $PATH variables. So it <span style="text-decoration: underline;">must</span> be run from the install directory.</p>
<pre>micha@hayun-13:~/Download$ <strong>tar xvzf hegLNXv2.10.tar.gz</strong>
install
heg.tar
micha@hayun-13:~/Download$ <strong>sudo ./install</strong>
micha@hayun-13:~/Download$ <strong>sudo chown -R micha /usr/local/heg</strong></pre>
<p>As part of the installation, you enter the location of the java binary, /usr/bin/java (Fedora&#8217;s &#8220;/etc/alternatives&#8221; infrastructure takes care of that), and the final installation location, /usr/local/heg. Once the installation is complete, run the program by:</p>
<pre>micha@hayun-13:~/Download$ <strong>cd /usr/local/heg/bin/</strong>
micha@hayun-13:/usr/local/heg/bin$ <strong>./HEG</strong></pre>
<p>The java interface has it&#8217;s own Help. Select a file from the File-&gt;Open menu, and a dataset in the left pane. Then the output file name and projection parameters in the center pane. Click &#8220;Accept&#8221;, and &#8220;Run&#8221; in the right hand pane. If, before clicking Run, you open other files, select a dataset, and click &#8220;Accept&#8221;, then the tiles are merged into one big GeoTiff .</p>
<p><a href="http://www.surfaces.co.il/wp-content/uploads/2010/01/mesop_evi.png"><img class="aligncenter size-full wp-image-549" title="mesop_evi" src="http://www.surfaces.co.il/wp-content/uploads/2010/01/mesop_evi.png" alt="" width="790" height="520" /></a></p>
<p>The above map was put together using the techniques above. The EVI data is from the MODIS AQUA dataset from May 2009, Monthly average vegetation Index. The vector layers come from the public domain dataset <a href="http://www.naturalearthdata.com/">Natural Earth</a>. I used a few GRASS operations to merge several tiles and get the coloring right, but that&#8217;s for the next blog&#8230; So we&#8217;ve concluded installing the foundations for GIS software. Tune in next time for compiling QGIS and GRASS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surfaces.co.il/?feed=rss2&amp;p=468</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>
