<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">

<channel>
	<title>jduck.net</title>
	
	<link>http://jduck.net</link>
	<description />
	<lastBuildDate>Fri, 02 Jul 2010 13:01:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/jducknet" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="jducknet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>42.037108</geo:lat><geo:long>-88.107199</geo:long><item>
		<title>Getting to know PostGIS Part II</title>
		<link>http://jduck.net/2009/01/30/getting-to-know-postgis-part-ii/</link>
		<comments>http://jduck.net/2009/01/30/getting-to-know-postgis-part-ii/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 19:27:36 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[geospatial]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://jduck.net/?p=131</guid>
		<description>So its been over six months since I made my first tutorial post about PostGIS. I now use PostGIS on a regular basis and thought it would be good to update the tutorial with some meat on how to use PostGIS. Get some data and import it Grab populated places points wget http://edcftp.cr.usgs.gov/pub/data/nationalatlas/citiesx020.tar.gz Grab US [...]</description>
			<content:encoded><![CDATA[<p>So its been over six months since I made <a href="http://jduck.net/2007/11/06/getting-to-know-postgis/">my first tutorial</a> post about PostGIS.  I now use PostGIS on a regular basis and thought it would be good to update the tutorial with some meat on how to use PostGIS.</p>
<h3>Get some data and import it</h3>
<h4>Grab populated places points</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>edcftp.cr.usgs.gov<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>nationalatlas<span style="color: #000000; font-weight: bold;">/</span>citiesx020.tar.gz</pre></div></div>

<p>Grab US counties map:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>edcftp.cr.usgs.gov<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>nationalatlas<span style="color: #000000; font-weight: bold;">/</span>countyp020.tar.gz</pre></div></div>

<p>Lots more data available in the <a href="http://www.nationalatlas.gov/atlasftp.html">National Atlas</a><br />
<span id="more-131"></span></p>
<h4>Extract shapefiles from the two archives</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> citiesx020.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span>  countyp020.tar.gz</pre></div></div>

<h4>Ogrinfo the files to have a look at them</h4>
<pre>
ogrinfo citiesx020.shp
INFO: Open of `citiesx020.shp'
      using driver `ESRI Shapefile' successful.
1: citiesx020 (Point) 

ogrinfo countyp020.shp
INFO: Open of `countyp020.shp'
      using driver `ESRI Shapefile' successful.
1: countyp020 (Polygon)
</pre>
<p>Notice that the cities shapefile is a point layer and the county layer is a polygon layer.</p>
<h4>Import the two shape files into your PostGIS db </h4>
<p>To get started with PostGIS see my <a href="http://jduck.net/2007/11/06/getting-to-know-postgis/">first tutorial</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ogr2ogr <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;PostgreSQL&quot;</span> -s_srs EPSG:<span style="color: #000000;">4269</span> <span style="color: #ff0000;">&quot;PG:dbname=mydbname&quot;</span> countyp020.shp <span style="color: #660033;">-nln</span> us_counties
ogr2ogr <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;PostgreSQL&quot;</span> -s_srs EPSG:<span style="color: #000000;">4269</span> <span style="color: #ff0000;">&quot;PG:dbname=mydbname&quot;</span> citiesx020.shp <span style="color: #660033;">-nln</span> us_cities</pre></div></div>

<p>Make sure you change mydbname to your database&#8217;s name.</p>
<li>-f &#8220;PostgreSQL&#8221; says that our destination &#8220;file type&#8221; is a PostgreSQL database</li>
<li>The -s_srs sets the source spatial reference system for the shapefiles.  Shapefiles from the National Atlas do not have a .prj file which defines their projection, so I looked in the .txt file which came with each archive from the National Atlas and found that the they are in <a href="http://spatialreference.org/ref/epsg/4269/">NAD83</a>, or EPSG:4269</li>
<li>&#8220;PG:dbname=mydbname&#8221; tells ogr2ogr what your destination is (in this case a PostGIS server).  More options are possible in the <a href="http://gdal.org/ogr/drv_pg.html">OGR driver</a></li>
<li>the shapfile name specifies the source</li>
<li>-nln specifies a new layer name which will be the name of the table in our database</li>
<h4>Checking the Import</h4>
<pre>
psql mydbname
mydbname# \d us_cities
                                   Table "public.us_cities"
    Column    |       Type       |                          Modifiers
--------------+------------------+-------------------------------------------------------------
 ogc_fid      | integer          | not null default nextval('us_cities_ogc_fid_seq'::regclass)
 wkb_geometry | geometry         |
 citiesx020   | double precision |
 feature      | character(27)    |
 name         | character(48)    |
 pop_range    | character(21)    |
 pop_2000     | numeric(8,0)     |
 fips55       | character(5)     |
 county       | character(55)    |
 fips         | character(5)     |
 state        | character(2)     |
 state_fips   | character(2)     |
 display      | numeric(1,0)     |
Indexes:
    "us_cities_pk" PRIMARY KEY, btree (ogc_fid)
    "us_cities_geom_idx" gist (wkb_geometry)
Check constraints:
    "enforce_dims_wkb_geometry" CHECK (ndims(wkb_geometry) = 2)
    "enforce_geotype_wkb_geometry" CHECK (geometrytype(wkb_geometry) = 'POINT'::text OR wkb_geometry IS NULL)
    "enforce_srid_wkb_geometry" CHECK (srid(wkb_geometry) = -1)
</pre>
<p>You can see that ogr2ogr has imported the shapefile, created a primary key (ogc_fid) and created a spatial index. What you can&#8217;t see is that ogr2ogr was also nice enough to add an entry to the geometry_columns table so that postgis tools know that there is a geometry column (wkb_geometry) in this table.</p>
<h4>Looking at the Data</h4>
<p>Lets fire off <a href="http://www.qgis.org/">qgis</a> and see what we have<br />
<a href="http://jduck.net/blog/blog/wp-content/uploads/2009/01/city_county.png"><img src="http://jduck.net/blog/blog/wp-content/uploads/2009/01/city_county-300x132.png" alt="city_county" title="city_county" width="300" height="132" class="aligncenter size-medium wp-image-151" /></a></p>
<p>Next time, querying with spatial predicates&#8230;.I promise it won&#8217;t take six months for the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2009/01/30/getting-to-know-postgis-part-ii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install MacPorts in Local Home Directory</title>
		<link>http://jduck.net/2008/12/12/install-macports-in-local-home-directory/</link>
		<comments>http://jduck.net/2008/12/12/install-macports-in-local-home-directory/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 15:26:40 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[macosx]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://jduck.net/?p=142</guid>
		<description>I was needing to install MacPorts on a multi-user system where I didn&amp;#8217;t have root access. Here is what I did. mkdir ${HOME}/macports cd ${HOME}/macports wget http://svn.macports.org/repository/macports/downloads/MacPorts-1.6.0/MacPorts-1.6.0.tar.gz tar -xzvf MacPorts-1.6.0.tar.gz cd MacPorts-1.6.0 ./configure --prefix=${HOME}/macports --with-tclpackage=${HOME}/macports/tcl \ --with-install-user=${USER} --with-install-group=${USER} make make install You will now have a macports directory in your home directory: $ ls macports [...]</description>
			<content:encoded><![CDATA[<p>I was needing to install MacPorts on a multi-user system where I didn&#8217;t have root access.  Here is what I did.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #800000;">${HOME}</span><span style="color: #000000; font-weight: bold;">/</span>macports
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #800000;">${HOME}</span><span style="color: #000000; font-weight: bold;">/</span>macports
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.macports.org<span style="color: #000000; font-weight: bold;">/</span>repository<span style="color: #000000; font-weight: bold;">/</span>macports<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>MacPorts-1.6.0<span style="color: #000000; font-weight: bold;">/</span>MacPorts-1.6.0.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> MacPorts-1.6.0.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> MacPorts-1.6.0
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #800000;">${HOME}</span><span style="color: #000000; font-weight: bold;">/</span>macports <span style="color: #660033;">--with-tclpackage</span>=<span style="color: #800000;">${HOME}</span><span style="color: #000000; font-weight: bold;">/</span>macports<span style="color: #000000; font-weight: bold;">/</span>tcl \
<span style="color: #660033;">--with-install-user</span>=<span style="color: #800000;">${USER}</span> <span style="color: #660033;">--with-install-group</span>=<span style="color: #800000;">${USER}</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>You will now have a macports directory in your home directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> macports
bin     etc     include lib     libexec <span style="color: #c20cb9; font-weight: bold;">man</span>     sbin    share   src     tcl     var     www</pre></div></div>

<p>Add ${HOME}/macports/bin to your path and you&#8217;ll be able to run &#8220;port install *portname*&#8221; ports you install will get installed in your home directory.  Handy for any little tools you need to have available that might not be built on the system you&#8217;re using.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/12/12/install-macports-in-local-home-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using OGR to convert GIS Vector formats</title>
		<link>http://jduck.net/2008/07/18/using-ogr-to-convert-gis-vector-formats/</link>
		<comments>http://jduck.net/2008/07/18/using-ogr-to-convert-gis-vector-formats/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 21:34:36 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[geospatial]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[oss]]></category>

		<guid isPermaLink="false">http://jduck.net/2008/07/18/using-ogr-to-convert-gis-vector-formats/</guid>
		<description>OGR is a part of GDAL and is very useful for converting between geospatial vector formats. What does that mean? When storing Vector GIS data there are a dizzying number of formats it can be stored in, some of the more popular of late, or at least well known are KML and SHP. A friend [...]</description>
			<content:encoded><![CDATA[<p><a href="http://www.gdal.org/ogr/">OGR</a> is a part of <a href="http://www.gdal.org/">GDAL</a> and is very useful for converting between geospatial <a href="http://www.gdal.org/ogr/ogr_formats.html">vector formats</a>.  What does that mean?  When storing Vector GIS data there are a dizzying number of formats it can be stored in, some of the more popular of late, or at least well known are KML and SHP.  A friend of a friend was looking to convert some SHP (Shapefiles) into KML so that he could make a Google Maps mashup and I helped him out.  Here is a workflow for how I went about performing the conversion.<br />
<span id="more-115"></span><br />
OGR can be installed on debian/ubuntu machines by installing the package gdal-bin:</p>
<pre>sudo apt-get install gdal-bin</pre>
<p>Once you have GDAL/OGR installed you get a slew of command line utilities, I&#8217;ll try to cover some others in later tutorials, but for now we&#8217;re interested in ogr2ogr.  ogr2ogr converts between the vector formats that OGR understands.</p>
<p>Example using a shapefile at the city of chicago website:<br />
Download the data</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>egov.cityofchicago.org<span style="color: #000000; font-weight: bold;">/</span>webportal<span style="color: #000000; font-weight: bold;">/</span>COCWebPortal<span style="color: #000000; font-weight: bold;">/</span>COC_ATTACH<span style="color: #000000; font-weight: bold;">/</span>TIFS2008.zip</pre></div></div>

<p>Unzip it</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">unzip</span> TIFS2008.zip</pre></div></div>

<p>Now we have to do the hard part (not really that hard, but important), look for the projection information in the metadata.  I looked in the tifs.shp.xml file and found that the projections is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">NAD_1983_StatePlane_Illinois_East_FIPS_1201_Feet</pre></div></div>

<p>Google uses WGS84 spatial reference system.<br />
Now we have to lookup EPSG codes that OGR understands for these projections.  A good spot to do this is <a href="http://spatialreference.org">spatialreference.org</a>.  EPSG codes provide a short form of expressing projection and spatial reference information.<br />
Once we have that all sorted out we&#8217;re ready to run ogr2ogr:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ogr2ogr <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;KML&quot;</span> -s_srs <span style="color: #ff0000;">&quot;EPSG:102671&quot;</span> -t_srs <span style="color: #ff0000;">&quot;EPSG:4326&quot;</span> tifs.kml tifs.shp</pre></div></div>

<p>The -f &#8220;KML&#8221; specifies that we want the output in KML.  -s_srs is the source (tifs.shp) spatial reference system and -t_srs is the target spatial reference system found at spatialreference.org, then we specify the output file tifs.kml and the input file tifs.shp.  That is it!</p>
<p>Lets shrink it down into a kmz (compressed kml) so that it takes up less disk space.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">zip</span> tifs.kmz tifs.kml</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/07/18/using-ogr-to-convert-gis-vector-formats/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Antrhopogenic RF Interference</title>
		<link>http://jduck.net/2008/03/12/antrhopogenic-rf-interference/</link>
		<comments>http://jduck.net/2008/03/12/antrhopogenic-rf-interference/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 14:52:50 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[remote sensing]]></category>
		<category><![CDATA[science]]></category>

		<guid isPermaLink="false">http://jduck.net/2008/03/12/antrhopogenic-rf-interference/</guid>
		<description>Was looking at raw AMSR-E data (a passive microwave radiometer flying on board Aqua). Can you tell where the cities are? Hmmm&amp;#8230;I wonder what one can do with this? A development indicator, surrogate for population? Very interesting. This anthropogenic interference gets in the way of soil moisture detection over land, but I wonder if it [...]</description>
			<content:encoded><![CDATA[<p>Was looking at raw <a href="http://sharaku.eorc.jaxa.jp/AMSR/index_e.htm">AMSR-E</a> data (a passive microwave radiometer flying on board <a href="http://aqua.nasa.gov/">Aqua)</a>.  Can you tell where the cities are?</p>
<p><a href='http://jduck.net/blog/blog/wp-content/uploads/2008/03/pmtbeqn29d016y080308v06sa.png' title='pmtbeqn29d016y080308v06sa.png'><img src='http://jduck.net/blog/blog/wp-content/uploads/2008/03/pmtbeqn29d016y080308v06sa.thumbnail.png' alt='pmtbeqn29d016y080308v06sa.png' /></a></p>
<p>Hmmm&#8230;I wonder what one can do with this?  A development indicator, surrogate for population?  Very interesting.  This anthropogenic interference gets in the way of soil moisture detection over land, but I wonder if it can be used creatively for something else.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/03/12/antrhopogenic-rf-interference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Small houses</title>
		<link>http://jduck.net/2008/01/08/small-houses/</link>
		<comments>http://jduck.net/2008/01/08/small-houses/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 14:49:32 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[building]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[green]]></category>

		<guid isPermaLink="false">http://jduck.net/2008/01/08/small-houses/</guid>
		<description>I have a dream of having one of these buildings (slideshow at Wired.com) in my back yard as a home office someday. Another dream is to get an acreage and scatter several of these buildings around with some paths connecting them together.</description>
			<content:encoded><![CDATA[<p>I have a dream of having one of <a href="http://www.wired.com/science/discoveries/multimedia/2008/01/modular_homes?slide=1&#038;slideView=3">these buildings (slideshow at Wired.com)</a> in my back yard as a home office someday.  Another dream is to get an acreage and scatter several of these buildings around with some paths connecting them together.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/01/08/small-houses/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Dangerous things you should let your kids do.</title>
		<link>http://jduck.net/2008/01/08/5-dangerous-things-you-should-let-your-kids-do/</link>
		<comments>http://jduck.net/2008/01/08/5-dangerous-things-you-should-let-your-kids-do/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 14:43:55 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[kids]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://jduck.net/2008/01/08/5-dangerous-things-you-should-let-your-kids-do/</guid>
		<description>Gever Tulley has a great video about the sort of dangerous things kids need to do when growing up. It is nice to see this kind of thing. Its a breath of fresh air from the fear society we live in. On a related note, kids don&amp;#8217;t get the freedom to go out walking and [...]</description>
			<content:encoded><![CDATA[<p>Gever Tulley has a <a href="http://www.ted.com/index.php/talks/view/id/202">great video</a> about the sort of dangerous things kids need to do when growing up.  It is nice to see this kind of thing.  Its a breath of fresh air from the fear society we live in.  On a related note, kids don&#8217;t get the freedom to <a href="http://www.dailymail.co.uk/pages/live/articles/news/news.html?in_article_id=462091&#038;in_page_id=1770">go out walking and exploring</a> much anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/01/08/5-dangerous-things-you-should-let-your-kids-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scanning with sane’s scanimage from an ADF scanner to PDF and OCRed Text</title>
		<link>http://jduck.net/2008/01/05/ocr-scanning/</link>
		<comments>http://jduck.net/2008/01/05/ocr-scanning/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 17:34:21 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scanning]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://jduck.net/2008/01/05/ocr-scanning/</guid>
		<description>Using libsane and tesseract, you can scan from an ADF (or non ADF) scanner in Ubuntu 7.10 to a PDF and OCR&amp;#8217;ed text document with a few easy steps. First we need to make sure we have the necessary packages installed. apt-get install tesseract-ocr sane-utils The tesseract-ocr package gives us a utility called tesseract which [...]</description>
			<content:encoded><![CDATA[<p>Using libsane and tesseract, you can scan from an ADF (or non ADF) scanner in Ubuntu 7.10 to a PDF and OCR&#8217;ed text document with a few easy steps.</p>
<p>First we need to make sure we have the necessary packages installed.</p>
<pre>
apt-get install tesseract-ocr sane-utils
</pre>
<p><span id="more-110"></span></p>
<p>The tesseract-ocr package gives us a utility called tesseract which takes a TIFF file as input and will output the OCR&#8217;d .txt file of the tiff.</p>
<pre>
tesseract my.tif output
</pre>
<p>Now we need a command line method to grab the TIFF, sane-utils comes to the rescue.  The command &#8220;scanimage&#8221; from sane will let us do that.  It is a great little utility that I recommend reading up on to learn more about its features and options, as they may vary based on the type of scanner you have.  My scanner has an Auto Document Feeder (ADF) so be aware that my instructions are specific to an ADF scanner.</p>
<p>This example is for scanning a letter sized piece of paper in batch mode saving output in the format of a TIFF</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">scanimage <span style="color: #660033;">-y</span> <span style="color: #000000;">279.4</span> <span style="color: #660033;">-x</span> <span style="color: #000000;">215.9</span> <span style="color: #660033;">--batch</span> <span style="color: #660033;">--format</span>=tiff <span style="color: #660033;">--mode</span> Lineart <span style="color: #660033;">--resolution</span> <span style="color: #000000;">300</span> <span style="color: #660033;">--source</span> ADF</pre></div></div>

<p>This will output a new TIFF for each page that is scanned.</p>
<p>The below script combines several steps to output a single PDF document and .txt file for a scan job.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">outname</span>=<span style="color: #007800;">$1</span>
<span style="color: #007800;">startdir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">tmpdir</span>=scan-<span style="color: #007800;">$RANDOM</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$tmpdir</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$tmpdir</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;################## Scanning ###################&quot;</span>
scanimage <span style="color: #660033;">-y</span> <span style="color: #000000;">279.4</span> <span style="color: #660033;">-x</span> <span style="color: #000000;">215.9</span> <span style="color: #660033;">--batch</span> <span style="color: #660033;">--format</span>=tiff <span style="color: #660033;">--mode</span> Lineart <span style="color: #660033;">--resolution</span> <span style="color: #000000;">300</span> <span style="color: #660033;">--source</span> ADF
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;################### OCRing ####################&quot;</span>
<span style="color: #007800;">i</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">for</span> page <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.tif<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Page: <span style="color: #007800;">$i</span> - &quot;</span>
        <span style="color: #666666; font-style: italic;">#run tesseract on each page and combine the outputs in a single file with a .txt extension.</span>
        tesseract <span style="color: #007800;">$page</span> <span style="color: #007800;">$page</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;---BEGIN PAGE: <span style="color: #007800;">$i</span> ---&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$outname</span>.txt
        <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$page</span>.txt <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$outname</span>.txt
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;---END PAGE: $1 ---&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$outname</span>.txt
        <span style="color: #007800;">i</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$i</span> + <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$outname</span>.txt <span style="color: #007800;">$startdir</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;############## Converting to PDF ##############&quot;</span>
<span style="color: #666666; font-style: italic;">#Use tiffcp to combine output tiffs to a single mult-page tiff</span>
tiffcp <span style="color: #660033;">-c</span> lzw out<span style="color: #000000; font-weight: bold;">*</span>.tif output.tif 
<span style="color: #666666; font-style: italic;">#Convert the tiff to PDF</span>
tiff2pdf output.tif <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$startdir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$outname</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;################ Cleaning Up ################&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$tmpdir</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$startdir</span></pre></div></div>

<p>I name the above script &#8220;scandoc&#8221; and it can be run by typing &#8220;scandoc myoutput.pdf&#8221; which will drop a pdf file (called myoutput.pdf) and a .txt (called myoutput.pdf.txt) file in the current directory with all the pages from the ADF.  Very handy!</p>
<p><strong>EDIT:</strong><br />
I&#8217;ve added Joe&#8217;s contributions in the comments to a <a href="http://gist.github.com/311548">gist</a> at github. </p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2008/01/05/ocr-scanning/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>ntfsundelete</title>
		<link>http://jduck.net/2007/12/20/ntfsundelete/</link>
		<comments>http://jduck.net/2007/12/20/ntfsundelete/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 20:06:54 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/12/20/ntfsundelete/</guid>
		<description>Just did a stupid thing and deleted a whole tree of file on a windows partition. Never fear&amp;#8230;ntfsundelete is here. sudo ntfsundelete -u -d /destination/directory -f -m *.jpg /dev/sda1 Run without the -u option and -d options to show what can be recovered. On ubuntu/debian to install it do: apt-get install ntfsprogs</description>
			<content:encoded><![CDATA[<p>Just did a stupid thing and deleted a whole tree of file on a windows partition.  Never fear&#8230;ntfsundelete is here.</p>
<pre>
sudo ntfsundelete -u -d /destination/directory -f -m *.jpg /dev/sda1
</pre>
<p>Run without the -u option and -d options to show what can be recovered.</p>
<p>On ubuntu/debian to install it do:</p>
<pre>
apt-get install ntfsprogs
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/12/20/ntfsundelete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting to know PostGIS</title>
		<link>http://jduck.net/2007/11/06/getting-to-know-postgis/</link>
		<comments>http://jduck.net/2007/11/06/getting-to-know-postgis/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 14:45:13 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/11/06/getting-to-know-postgis/</guid>
		<description>I am making the plunge to get more informed with how to use PostGIS. It is pretty impressive so far. Here is a quick tutorial which shows you how to get started and loading in a shapefile to play around with some fun SQL querying. I assume a basic understanding of the linux command line [...]</description>
			<content:encoded><![CDATA[<p>I am making the plunge to get more informed with how to use PostGIS.  It is pretty impressive so far.  Here is a quick tutorial which shows you how to get started and loading in a shapefile to play around with some fun SQL querying.  I assume a basic understanding of the linux command line and some basic SQL skills. </p>
<p>To get started in ubuntu 7.04 (should work in 7.10 and debian too):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> postgis postgresql-<span style="color: #000000;">8.1</span>-postgis</pre></div></div>

<p>Next we&#8217;ll start setting up the PostGIS environment.<br />
<span id="more-104"></span></p>
<p>Then we need to set up a new database, I called mine geodb:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ createdb geodb</pre></div></div>

<p>We then need to bind it to the PostGIS libs with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ createlang plpgsql geodb</pre></div></div>

<p>And finally add the PostGIS Tables:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ psql <span style="color: #660033;">-d</span> mytestdb <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql-<span style="color: #000000;">8.1</span>-postgis<span style="color: #000000; font-weight: bold;">/</span>lwpostgis.sql
$ psql <span style="color: #660033;">-d</span> mytestdb <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql-<span style="color: #000000;">8.1</span>-postgis<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql</pre></div></div>

<p>Phew&#8230;.that was a bit of work.</p>
<p>Now we&#8217;re ready to go.  We have a database called geodb and we&#8217;ve told PostgreSQL that it is a PostGIS database.</p>
<p>So now we can use the shp2pgsql command to import a shapefile into the db:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ shp2pgsql <span style="color: #660033;">-W</span> LATIN1 <span style="color: #660033;">-D</span> <span style="color: #660033;">-I</span> myshapefile.shp mytablename <span style="color: #000000; font-weight: bold;">|</span> psql geodb</pre></div></div>

<p>-W is for setting the encoding type, I had problems with many shapefiles as my locale is UTF8 and PostgreSQL seems to default to the locale.  For me LATIN1 has been working better.</p>
<p>-D sets the SQL output to be in dump format for insertion into the database.</p>
<p>-I flags it to compute the spatial indexing upon import.  For large complex vector features this can take awhile, so use with discretion.</p>
<p>All of this is piped to </p>
<p>This gives us a new table called &#8220;tablename&#8221;, which we can see by doing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ psql geodb
Welcome to psql 8.1.8, the PostgreSQL interactive terminal.
&nbsp;
Type:  \\copyright <span style="color: #000000; font-weight: bold;">for</span> distribution terms
       \\h <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span> with SQL commands
       \\? <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span> with psql commands
       \\g or terminate with semicolon to execute query
       \\q to quit
&nbsp;
<span style="color: #007800;">geodb</span>=<span style="color: #666666; font-style: italic;">#</span></pre></div></div>

<p>At the PostgreSQL prompt you can enter various SQL commands including queries.  </p>
<pre>geodb=# \\d mytablename</pre>
<p>shows the columns and data types of the data in the table.</p>
<p>Notice the column called: the_geom</p>
<p>This is where the <a href="http://postgis.refractions.net/docs/ch04.html#RefObject">GIS Objects</a> are stored.</p>
<p>The sample query there would show all the data in the shapefile&#8217;s associated .dbf as well as a column called </p>
<p>Next time we&#8217;ll launch into some querying fun.</p>
<p><a href="http://jduck.net/2009/01/30/getting-to-know-postgis-part-ii/">Onward to Part II&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/11/06/getting-to-know-postgis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A bundle of links…</title>
		<link>http://jduck.net/2007/11/06/a-bundle-of-links/</link>
		<comments>http://jduck.net/2007/11/06/a-bundle-of-links/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 14:44:20 +0000</pubDate>
		<dc:creator>Jonah</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://jduck.net/2007/11/06/a-bundle-of-links/</guid>
		<description>Some neat things found on the web recently: Ponoko &amp;#8211; Custom Laser cutting of Plexiglas and plywood. Make your circuit boards in china for cheap CouchDB simple database for content management systems. Mabel&amp;#8217;s Labels &amp;#8211; Got kids? Need to label their stuff, these look neat.</description>
			<content:encoded><![CDATA[<p>Some neat things found on the web recently:</p>
<li><a href="http://ponoko.com">Ponoko</a> &#8211; Custom Laser cutting of Plexiglas and plywood.</li>
<li>Make your <a href="http://www.nearfuturelaboratory.com/?p=337">circuit boards in china</a> for cheap</li>
<li><a href="http://couchdb.org">CouchDB</a> simple database for content management systems.</li>
<li><a href="http://www.mabel.ca/mabel.php">Mabel&#8217;s Labels</a> &#8211; Got kids?  Need to label their stuff, these look neat.</li>
]]></content:encoded>
			<wfw:commentRss>http://jduck.net/2007/11/06/a-bundle-of-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
