<?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/"
	>

<channel>
	<title>mobile and gis dev notes &#187; ogr2ogr</title>
	<atom:link href="http:///wordpress/tag/ogr2ogr/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Exporting from Postgres to Mapinfo</title>
		<link>/wordpress/2007/08/exporting-from-postgres-to-mapinfo/</link>
		<comments>/wordpress/2007/08/exporting-from-postgres-to-mapinfo/#comments</comments>
		<pubDate>Mon, 27 Aug 2007 12:00:36 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[mapinfo]]></category>
		<category><![CDATA[ogr2ogr]]></category>

		<guid isPermaLink="false">/wordpress/?p=108</guid>
		<description><![CDATA[I had a problem when using ogr2ogr and converting a postgres table to a road table. My postgres table containa a utf-8 road name which is all in chinese. The mapinfo road table created by ogr2ogr seems to contain the correct geometry and other fields that is in utf-8. However, all my chinese characters is [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem when using ogr2ogr and converting a postgres table to a road table. My postgres table containa a utf-8 road name which is all in chinese. The mapinfo road table created by ogr2ogr seems to contain the correct geometry and other fields that is in utf-8. However, all my chinese characters is all messed up. So, I have to export the file and open it to mapinfo.</p>
<p>1. In Postgres, to export to a file..<br />
<code><br />
cybersoftbjv1=# set client_encoding = gbk;<br />
SET<br />
cybersoftbjv1=# \o road.txt;<br />
cybersoftbjv1=# select rd_id, cn_name from roads where cn_name &lt;&gt; '';<br />
cybersoftbjv1=# \q<br />
</code></p>
<p>2. Open the file in vim, and do a &#8220;%s/ //g&#8221;. This would replace all &#8221; &#8221; to &#8220;&#8221;.<br />
Note: This is reasonable for chinese since chinese dont have spaces. However english prases and sentences differ.</p>
<p>3. Open the file in mapinfo and replace the other columns using Table -&gt; Update.</p>
<p>If anybody has any other way to specify the client encoding in ogr2ogr that would be perfect&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/08/exporting-from-postgres-to-mapinfo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OGR Quick Reference</title>
		<link>/wordpress/2007/07/ogr2ogr-quick-reference/</link>
		<comments>/wordpress/2007/07/ogr2ogr-quick-reference/#comments</comments>
		<pubDate>Mon, 09 Jul 2007 18:22:19 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[GDAL/OGR]]></category>
		<category><![CDATA[mapinfo]]></category>
		<category><![CDATA[ogr2ogr]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=73</guid>
		<description><![CDATA[Here is a list of the most widely used OGR commands I use.. OGR2OGR 1. POSTGRES -&#62; MAPINFO $ ogr2ogr -f &#34;Mapinfo File&#34; busline_buffer10m.tab PG:&#34;host=localhost user=postgres dbname=cybersoftbj&#34; -sql &#34;select * from table_name&#34; -a_srs WGS84 -nln layer_name -nlt MULTIPOLYGON 2. MAPINFO -&#62; POSTGRES ogr2ogr -f &#34;PostgreSQL&#34; PG:&#34;host=127.0.0.1 user=rupert dbname=australia password=*****&#34; AUS_ROAD.TAB -nln AUS_ROAD -a_srs EPSG:4269 -t_srs [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a list of the most widely used OGR commands I use..</p>
<p><strong>OGR2OGR</strong><br />
<strong>1. POSTGRES -&gt; MAPINFO</strong></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;Mapinfo File&quot;</span> busline_buffer10m.tab PG:<span style="color: #ff0000;">&quot;host=localhost user=postgres dbname=cybersoftbj&quot;</span> <span style="color: #660033;">-sql</span> <span style="color: #ff0000;">&quot;select * from table_name&quot;</span> -a_srs WGS84 <span style="color: #660033;">-nln</span> layer_name <span style="color: #660033;">-nlt</span> MULTIPOLYGON</pre></div></div>

<p><strong>2. MAPINFO -&gt; POSTGRES</strong></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> PG:<span style="color: #ff0000;">&quot;host=127.0.0.1 user=rupert dbname=australia password=*****&quot;</span> AUS_ROAD.TAB <span style="color: #660033;">-nln</span> AUS_ROAD -a_srs EPSG:<span style="color: #000000;">4269</span> -t_srs EPSG:<span style="color: #000000;">3857</span> <span style="color: #660033;">-skip-failures</span>
&nbsp;
ogr2ogr <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;PostgreSQL&quot;</span> PG:<span style="color: #ff0000;">&quot;host=myhost user=myloginname dbname=mydbname password=mypassword&quot;</span> mytabfile.tab <span style="color: #660033;">-nln</span> newtablename <span style="color: #660033;">-select</span> columnName</pre></div></div>

<p>Note: If you have Chinese characters, might as well do MAPINFO -&gt; SHAPE -&gt; POSTGRES<br />
<a href="http://222.128.19.19/wordpress/?p=108">http://222.128.19.19/wordpress/?p=108</a></p>
<p><strong>3. SHAPE -&gt; POSTGRES</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">shp2pgsql <span style="color: #660033;">-W</span> <span style="color: #ff0000;">&quot;gbk&quot;</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">4326</span> lbjrdnt_small_polyline roads <span style="color: #000000; font-weight: bold;">&amp;</span>gt; roads.sql</pre></div></div>

<p><strong>4. POSTGRES -&gt; SHAPE</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pgsql2shp <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-u</span> lbs <span style="color: #660033;">-P</span> tracking <span style="color: #660033;">-f</span> roads.shp databasename tablename</pre></div></div>

<p><strong>4. MAPINFO TO ORACLE</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ogr2ogr <span style="color: #660033;">-f</span> OCI OCI:username<span style="color: #000000; font-weight: bold;">/</span>password<span style="color: #000000; font-weight: bold;">@</span>orcl C:\path_to_tabfile\EMPLOYEES.TAB <span style="color: #660033;">-nln</span> employees</pre></div></div>

<p>Note: This assumes you already have Oracle 10g Client installed and &#8220;orcl&#8221; is defined as an instance in tnsnames.ora. OGR2OGR automatically updates USER_SDO_GEOM_METADATA and creates a spatial index.</p>
<p><strong>5. MAPINFO to MAPINFO but different projection. From EPSG:4326 to EPSG:3857</strong></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;MapInfo File&quot;</span> BaseMaps_3857<span style="color: #000000; font-weight: bold;">/</span>AUS_CITIES_3857.TAB BaseMaps<span style="color: #000000; font-weight: bold;">/</span>AUS_CITIES.TAB -a_srs <span style="color: #ff0000;">&quot;EPSG:4326&quot;</span> -t_srs <span style="color: #ff0000;">&quot;EPSG:3857&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/ogr2ogr-quick-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading Mapinfo table to PostGis</title>
		<link>/wordpress/2007/04/loading-mapinfo-table-to-postgis/</link>
		<comments>/wordpress/2007/04/loading-mapinfo-table-to-postgis/#comments</comments>
		<pubDate>Wed, 04 Apr 2007 21:25:06 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[GDAL/OGR]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[mapinfo]]></category>
		<category><![CDATA[ogr2ogr]]></category>

		<guid isPermaLink="false">/wordpress/?p=47</guid>
		<description><![CDATA[AFAIK, there are only two ways to load data to PostGIS: 1. Using Insert statements 2. Using Utilities. Utilities include shp2pgsql which is found in &#8220;C:\Program Files\PostgreSQL\8.2\bin\&#8221; or &#8220;/usr/local/pgsql/bin&#8221;. To load Mapinfo table, I have used the OGR utilities from FWTools for Windows. and used gdal1.3.2 (since it contains ogr) for Unix. OGR2OGR CheatSheet should [...]]]></description>
			<content:encoded><![CDATA[<p>AFAIK, there are only two ways to load data to PostGIS:<br />
1. Using Insert statements<br />
2. Using Utilities.</p>
<p>Utilities include shp2pgsql which is found in &#8220;C:\Program Files\PostgreSQL\8.2\bin\&#8221; or &#8220;/usr/local/pgsql/bin&#8221;. To load Mapinfo table, I have used the OGR utilities from <a href="http://fwtools.maptools.org/">FWTools for Windows.</a> and used <a href="www.gdal.org">gdal1.3.2</a> (since it contains ogr) for Unix.</p>
<p><a href="http://www.bostongis.com/?content_name=ogr_cheatsheet">OGR2OGR CheatSheet</a> should be a good kickstart for basic understanding. For the impatient..</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> <span style="color: #660033;">-nlt</span> LINESTRING -a_srs <span style="color: #ff0000;">&quot;EPSG:4326&quot;</span> PG:<span style="color: #ff0000;">&quot;host=localhost user=username password=mypassword dbname=mydb mytab.TAB -select columnName</span></pre></div></div>

<p>or</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> PG:<span style="color: #ff0000;">&quot;host=myhost user=myloginname dbname=mydbname password=mypassword&quot;</span> mytabfile.tab <span style="color: #660033;">-nln</span> newtablename <span style="color: #660033;">-select</span> columnName</pre></div></div>

<p>Bear in mind that you should select out the columns from your mapfile (mine is chinese) especially if you have a diffent encoding in your column which matches your database (postgres). You might get a &#8220;Terminating translation prematurely after failed translation of layer [layername]&#8221; error.  Since Mapinfo stores the text to ASCII, my workaround is to export the tabfile to a UTF-8 textfile then upload it to PostGres. Hoping the primary ids would match to make the necessary updates&#8230;</p>
<p>An alternative to load Chinese text from Mapinfo to PostGIS is the ff:<br />
1. In Mapinfo use the Universal Translator to export the table into a shape file.<br />
2. Once you have the shape file, you can directly use the <strong>shp2pgsql</strong><em>.</em></p>
<p><em>shp2pgsql -W &#8220;gbk&#8221; -s 4326 lbjrdnt_small_polyline roads &gt; roads.sql</em></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/04/loading-mapinfo-table-to-postgis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

