<?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; postgres</title>
	<atom:link href="http:///wordpress/tag/postgres/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>freebsd + postgresql-server + plpython + postgis</title>
		<link>/wordpress/2011/11/freebsd-postgresql9-0-3-2/</link>
		<comments>/wordpress/2011/11/freebsd-postgresql9-0-3-2/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 01:41:06 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[postgis]]></category>

		<guid isPermaLink="false">/wordpress/?p=1109</guid>
		<description><![CDATA[1. Install prerequisites % cd /usr/ports/textproc/libxml2 % make % make install 2. Install python % cd /usr/ports/lang/python26 % make config #opens up blue terminal which allows to choose options % make % make install 3. Install % cd /usr/ports/databases/postgresql90-server % make % make install clean 4. Initialize % vim /etc/rc.conf postgresql_enable=YES postgresql_data=/var/db/pgsql % mkdir /var/db/pgsql [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. Install prerequisites</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>textproc<span style="color: #000000; font-weight: bold;">/</span>libxml2
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><strong>2. Install python</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>lang<span style="color: #000000; font-weight: bold;">/</span>python26
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> config <span style="color: #666666; font-style: italic;">#opens up blue terminal which allows to choose options</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><strong>3. Install</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgresql90-server
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></div></div>

<p><strong>4. Initialize</strong></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">% vim /etc/rc.conf
postgresql_enable=YES
postgresql_data=/var/db/pgsql
% mkdir /var/db/pgsql
% chown -Rf pgsql:pgsql /var/db/pgsql
% /usr/local/etc/rc.d/postgresql initdb -E utf8</pre></div></div>

<p><strong>5. Configuration</strong><br />
Allow incoming connections and set the default timezone to &#8216;UTC&#8217;</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">% vim /var/db/pgsql/postgresql.conf
listen_addresses = '*'     # what IP address(es) to listen on;
&nbsp;
timezone = 'UTC' #not necessary</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">% vim /var/db/pgsql/pg_hba.conf
# your network
host    all             all             192.168.10.0/24          trust</pre></div></div>

<p><strong>6. Start/Stop</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>postgresql start
<span style="color: #000000; font-weight: bold;">%</span> telnet 127.0.0.1 <span style="color: #000000;">5432</span></pre></div></div>

<p><strong>7. Create user. Login as root then switch to pgsql user</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% su - pgsql
[root@rupert ~]# su - pgsql
$ psql -d postgres
psql (9.0.6)
Type &quot;help&quot; for help.
&nbsp;
postgres=# CREATE ROLE rupert WITH LOGIN PASSWORD '**********' SUPERUSER INHERIT CREATEDB CREATEROLE;
CREATE ROLE
postgres=#</pre></div></div>

<p><strong>8. Install plpython</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgresql-plpython
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></div></div>

<p><em>To test if plpython is working properly, we create a testdb and loadup plpythonu and call a plpython function.</em></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">[root@rupert ~]# createdb -U rupert testdb
[root@rupert ~]# psql -d testdb -U rupert
psql (9.0.6)
Type &quot;help&quot; for help.
&nbsp;
testdb=# CREATE PROCEDURAL LANGUAGE 'plpythonu' HANDLER plpython_call_handler;
NOTICE:  using pg_pltemplate information instead of CREATE LANGUAGE parameters
CREATE LANGUAGE
testdb=# create or replace function pyver() returns text as
testdb-# $$
testdb$# import sys
testdb$# return sys.version
testdb$# $$ language 'plpythonu';
CREATE FUNCTION
testdb=# select pyver();
                   pyver                    
--------------------------------------------
 2.6.7 (r267:88850, Feb  6 2012, 13:10:39) +
 [GCC 4.2.1 20070831 patched [FreeBSD]]
(1 row)
&nbsp;
testdb=#</pre></div></div>

<p><strong>9. Install postgis</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgis
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><em>Note that ports should install proj and geos.</em></p>
<p><strong>10. Create template_postgis</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgis
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">su</span> - pgsql
$ createdb <span style="color: #660033;">-E</span> utf8 template_postgis
$ psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> postgis.sql
$ psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> spatial_ref_sys.sql</pre></div></div>

<p><strong>11. Install adminpack module</strong></p>
<p><em>This will eliminate &#8220;servers instrument error&#8221; when pgAdmin loads up postgres (default) db</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgresql90-contrib
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>contrib
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">su</span> - pgsql
$ psql <span style="color: #660033;">-U</span> pgsql <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> adminpack.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/freebsd-postgresql9-0-3-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nominatim + homebrew on OSX + OSM data + PHP = open sourced reverse geocoder</title>
		<link>/wordpress/2011/11/nominatim-on-osx/</link>
		<comments>/wordpress/2011/11/nominatim-on-osx/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 05:45:20 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">/wordpress/?p=1098</guid>
		<description><![CDATA[This installation guide (at the time of writing) was tested on SVN trunk of OSM2PGSQL and running on latest/stable Postgres/Postgis versions on OSX via homebrew. 1. Summary OSX Snow Leopard &#160; OSM2PGSQL: Head http://svn.openstreetmap.org/applications/utils/export/osm2pgsql Revision: 27034 Last Changed Author: frederik Last Changed Rev: 27030 Last Changed Date: 2011-11-09 10:57:49 +1100 (Wed, 09 Nov 2011) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This installation guide (at the time of writing) was tested on SVN trunk of OSM2PGSQL and running on latest/stable Postgres/Postgis versions on OSX via homebrew.</p>
<p><strong>1. Summary</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">OSX Snow Leopard
&nbsp;
OSM2PGSQL: 
Head http://svn.openstreetmap.org/applications/utils/export/osm2pgsql Revision: 27034
Last Changed Author: frederik
Last Changed Rev: 27030
Last Changed Date: 2011-11-09 10:57:49 +1100 (Wed, 09 Nov 2011)
&nbsp;
POSTGRES: 9.0.4
&nbsp;
POSTGIS: &quot;POSTGIS=&quot;1.5.3&quot; GEOS=&quot;3.3.1-CAPI-1.7.1&quot; PROJ=&quot;Rel. 4.7.1, 23 September 2009&quot; LIBXML=&quot;2.7.3&quot; USE_STATS&quot; # SELECT POSTGIS_FULL_VERSION();
&nbsp;
PHP: 5.3.8 (cli) (built: Nov 14 2011 14:41:52) #php -v</pre></div></div>

<p><strong>2. Installation</strong><br />
Most of the software is installed via <a href="https://github.com/mxcl/homebrew">homebrew.</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Install homebrew</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(curl -fsSL https://raw.github.com/gist/323731)</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Install postgresql</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> postgresql
<span style="color: #000000; font-weight: bold;">%</span> initdb <span style="color: #660033;">-E</span> utf8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>postgres
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>9.0.4<span style="color: #000000; font-weight: bold;">/</span>org.postgresql.postgres.plist ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">%</span> launchctl load <span style="color: #660033;">-w</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents<span style="color: #000000; font-weight: bold;">/</span>org.postgresql.postgres.plist
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>9.0.4<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>adminpack.sql
&nbsp;
<span style="color: #666666; font-style: italic;"># Install postgis</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> proj
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> geos
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> postgis
&nbsp;
<span style="color: #666666; font-style: italic;"># Create template_postgis_osm</span>
<span style="color: #000000; font-weight: bold;">%</span> createdb <span style="color: #660033;">-E</span> utf8 template_postgis_osm
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;/usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/pg_trgm.sql&quot;</span>
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>1.5.3<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>postgis.sql
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>1.5.3<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #666666; font-style: italic;"># Install osm2pgsql. Can skip this.</span>
<span style="color: #666666; font-style: italic;"># % brew install osm2pgsql</span></pre></div></div>

<p>For detail instructions on installing Postgres/Postgis via Homebrew, read this <a href="/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/">homebrew + postgresql9.0.4 + postgis.1.5.3 + proj4 + geos3.3.1 + osm2pgsql</a>.  If you are having problems installing GEOS, then read that link as it shows you how to upgrade GEOS to 3.3.1.</p>
<p>OSM2PGSQL needs GEOS as well. Note that brew only install the osm2pgsql binary. Don&#8217;t worry, we will compile this via source later. </p>
<p><strong>3. More Installation.</strong></p>
<p>We need to get PHP installed to run gazetteer <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/">http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Install PHP</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> php <span style="color: #660033;">--with-mysql</span> <span style="color: #660033;">--with-pgsql</span> <span style="color: #660033;">--with-apache</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Hookup with Apache</span>
<span style="color: #666666; font-style: italic;"># Edit httpd.conf to LoadModule</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Install PEAR DB</span>
<span style="color: #000000; font-weight: bold;">%</span> pear <span style="color: #c20cb9; font-weight: bold;">install</span> db</pre></div></div>

<p><strong>4. OSM2PGSQL</strong><br />
Read this wiki: <a href="http://wiki.openstreetmap.org/wiki/Osm2pgsql">http://wiki.openstreetmap.org/wiki/Osm2pgsql</a>. Well, we eventually need the whole OSM2PGSQL source as it contains the website (gazetteer).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.openstreetmap.org<span style="color: #000000; font-weight: bold;">/</span>applications<span style="color: #000000; font-weight: bold;">/</span>utils<span style="color: #000000; font-weight: bold;">/</span>export<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql osm2pgsql
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> osm2pgsql
<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>autogen.sh
<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># At this point there should be an osm2pgsql binary.</span></pre></div></div>

<p><em>We need to compile gazetteer for gazetteer.so which is used by gazetteer-functions.sql</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> clean
gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> 
gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;/usr/local/lib/osm2pgsql&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> ..<span style="color: #000000; font-weight: bold;">/</span>.<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/usr/local/lib/osm2pgsql&quot;</span>
 <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>libtool <span style="color: #660033;">--mode</span>=<span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span>  <span style="color: #ff0000;">'gazetteer.la'</span> <span style="color: #ff0000;">'/usr/local/lib/osm2pgsql/gazetteer.la'</span>
libtool: <span style="color: #c20cb9; font-weight: bold;">install</span>: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> .libs<span style="color: #000000; font-weight: bold;">/</span>gazetteer.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer.so
libtool: <span style="color: #c20cb9; font-weight: bold;">install</span>: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> .libs<span style="color: #000000; font-weight: bold;">/</span>gazetteer.lai <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer.la
<span style="color: #660033;">----------------------------------------------------------------------</span>
Libraries have been installed <span style="color: #000000; font-weight: bold;">in</span>:
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql
&nbsp;
If you ever happen to want to <span style="color: #c20cb9; font-weight: bold;">link</span> against installed libraries
<span style="color: #000000; font-weight: bold;">in</span> a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the <span style="color: #000000; font-weight: bold;">`</span>-LLIBDIR<span style="color: #ff0000;">'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH'</span> environment variable
     during execution
&nbsp;
See any operating system documentation about shared libraries <span style="color: #000000; font-weight: bold;">for</span>
<span style="color: #c20cb9; font-weight: bold;">more</span> information, such <span style="color: #c20cb9; font-weight: bold;">as</span> the <span style="color: #c20cb9; font-weight: bold;">ld</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> and ld.so<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> manual pages.
<span style="color: #660033;">----------------------------------------------------------------------</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;/usr/local/share/gazetteer&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> ..<span style="color: #000000; font-weight: bold;">/</span>.<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/usr/local/share/gazetteer&quot;</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'extract_countrynames.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/extract_countrynames.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-index.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-index.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-loaddata.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-loaddata.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-tables.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-tables.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_country_name.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_country_name.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_country_osm_grid.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_country_osm_grid.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_gb_postcodearea.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_gb_postcodearea.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_gb_postcode.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_gb_postcode.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_specialwords.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_specialwords.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_us_statecounty.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_us_statecounty.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_us_state.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_us_state.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_worldboundaries.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_worldboundaries.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-functions.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-functions.sql'</span></pre></div></div>

<p><strong>5. Download Data</strong><br />
You can get some regional OSM data from cloudmade. <a href="http://downloads.cloudmade.com/oceania/australia_and_new_zealand/australia/victoria">http://downloads.cloudmade.com/oceania/australia_and_new_zealand/australia/victoria</a> </p>
<p>I suggest you download a regional extract prior to downloading/testing with the whole planet-osm. If you don&#8217;t believe me that it will take long, you can read <a href="http://wiki.openstreetmap.org/wiki/Nominatim/Installation">http://wiki.openstreetmap.org/wiki/Nominatim/Installation</a></p>
<p><strong>6. Load and Index Data</strong><br />
Basically, this is the summary of commands taken from <a href="http://wiki.openstreetmap.org/wiki/Nominatim/Installation">http://wiki.openstreetmap.org/wiki/Nominatim/Installation</a> At the time of writing this, I had issues such as &#8220;planet_osm_ways&#8221; (and several tables) does not exist. So I did a pg_dump and restored the tables afterwards. Be very careful with using the script below, you can comment the indexing part just to speed up on loading and see if you have errors, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DATABASE_NAME</span>=gazetteer_vic
<span style="color: #007800;">OSM2PGSQL_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql
<span style="color: #007800;">SOURCE_DATA</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>australia<span style="color: #000000; font-weight: bold;">/</span>victoria.osm
<span style="color: #007800;">DUMP_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>pg_dumps<span style="color: #000000; font-weight: bold;">/</span>streetlookup
&nbsp;
dropdb <span style="color: #007800;">$DATABASE_NAME</span> 
<span style="color: #666666; font-style: italic;">#dropuser www-data</span>
&nbsp;
createdb <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-E</span> UTF8 <span style="color: #660033;">-T</span> template_postgis_osm
createuser <span style="color: #660033;">-SDR</span> www-data
&nbsp;
<span style="color: #666666; font-style: italic;"># This will create the planet_osm_ways, etc</span>
<span style="color: #007800;">$OSM2PGSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>osm2pgsql <span style="color: #660033;">--create</span> <span style="color: #660033;">--latlong</span> <span style="color: #660033;">--database</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--slim</span> <span style="color: #660033;">--prefix</span> planet_osm <span style="color: #660033;">--cache</span> <span style="color: #000000;">2048</span> <span style="color: #007800;">$SOURCE_DATA</span>
&nbsp;
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_ways.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_ways <span style="color: #007800;">$DATABASE_NAME</span>
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_nodes.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_nodes <span style="color: #007800;">$DATABASE_NAME</span>
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_rels.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_rels <span style="color: #007800;">$DATABASE_NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This will create the place table</span>
<span style="color: #007800;">$OSM2PGSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>osm2pgsql <span style="color: #660033;">--latlong</span> <span style="color: #660033;">-O</span> gazetteer <span style="color: #660033;">--database</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--slim</span> <span style="color: #660033;">--prefix</span> planet_osm <span style="color: #660033;">--cache</span> <span style="color: #000000;">2048</span> <span style="color: #007800;">$SOURCE_DATA</span>
&nbsp;
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_ways.backup&quot;</span>
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_nodes.backup&quot;</span>
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_rels.backup&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-Rf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #000000; font-weight: bold;">/*</span>.backup
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_country_osm_grid.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_worldboundaries.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_country_name.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_gb_postcode.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_gb_postcodearea.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_us_state.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_us_statecounty.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-functions.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-tables.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-functions.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-loaddata.sql
&nbsp;
<span style="color: #666666; font-style: italic;">#Indexing</span>
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-index.sql</pre></div></div>

<p>Save this as run.sh in <code>/Users/rupert/projects/gis/osm2pgsql/gazetteer</code></p>
<p>Where do you run this?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> run.sh</pre></div></div>

<p><strong>6. Test</strong><br />
If you are successful, <strong>you should have a &#8220;placex&#8221; table.</strong> Now that we have a postgis database running, you can now run spatial statements thru pgadmin. See the guts of <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/reverse.php">reverse.php</a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> 
<span style="color: #993333; font-weight: bold;">FROM</span> placex
<span style="color: #993333; font-weight: bold;">WHERE</span> ST_DWithin<span style="color: #66cc66;">&#40;</span> ST_SetSRID<span style="color: #66cc66;">&#40;</span>ST_Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">145.234377</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">37.856320</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> geometry<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0.0001</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AND</span> ST_GeometryType<span style="color: #66cc66;">&#40;</span>geometry<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ST_Polygon'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ST_MultiPolygon'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This one took only 21 ms.</p>
<p><strong>7. Website</strong></p>
<p>Make sure <code>www-data</code> have permissions to the tables. Rememeber to replace gazetteer_vic with your DATABASE_NAME.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> tbl <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>psql <span style="color: #660033;">-qAt</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;select tablename from pg_tables where schemaname = 'public';&quot;</span> gazetteer_vic<span style="color: #000000; font-weight: bold;">`</span> ; <span style="color: #000000; font-weight: bold;">do</span> psql <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;alter table <span style="color: #007800;">$tbl</span> owner to <span style="color: #000099; font-weight: bold;">\&quot;</span>www-data<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> gazetteer_vic; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Assuming you have PHP and PEAR DB installed. Then update the data connection settings found in <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/.htlib/settings.php">http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/.htlib/settings.php</a></p>
<p>Run the same query but using reverse.php.</p>
<p><a href="http://127.0.0.1/nominatim/reverse.php?format=xml&#038;lat=-37.856320&#038;lon=145.234377&#038;zoom=18&#038;addressdetails=1">http://127.0.0.1/nominatim/reverse.php?format=xml&#038;lat=-37.856320&#038;lon=145.234377&#038;zoom=18&#038;addressdetails=1</a></p>
<p><img src="/wordpress/wp-content/uploads/2011/11/reverse.png" alt="reverse.png" border="0" width="920" height="343" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/nominatim-on-osx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>osx + homebrew + postgresql9.0.4 + postgis.1.5.3 + proj4 + geos3.3.1 + osm2pgsql</title>
		<link>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/</link>
		<comments>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 02:02:21 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[homebrew]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1088</guid>
		<description><![CDATA[For the impatient % /usr/bin/ruby -e &#34;$(curl -fsSL https://raw.github.com/gist/323731)&#34; % brew install postgresql % initdb -E utf8 -D /usr/local/var/postgres % cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/ % launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist % psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql % brew install proj % brew install geos %you should really read below before running this % brew install postgis % [...]]]></description>
			<content:encoded><![CDATA[<p><strong>For the impatient</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.github.com/gist/323731)&quot;
% brew install postgresql
% initdb -E utf8 -D /usr/local/var/postgres
% cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
% launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
% psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql
% brew install proj
% brew install geos %you should really read below before running this
% brew install postgis
% createdb -E utf8 template_postgis
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql</pre></div></div>

<p><strong>1. Install homebrew</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%open https://github.com/mxcl/homebrew
%open https://github.com/mxcl/homebrew/wiki/Installation
%/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.github.com/gist/323731)&quot;</pre></div></div>

<p>Install python first if you need PL/Python in postgres. The &#8211;framework option tells Homebrew to compile a Framework-style Python build, rather than a UNIX-style build. Read this <a href="/wordpress/2011/12/homebrew-python/">INSTALLATION GUIDE.</a></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%brew install python --framework</pre></div></div>

<p><strong>2. Install Postgres</strong><br />
Note that postgres installation will pick up the latest Python Configuration, <strong>so it is important to ensure that we want the specific PYTHON interpreter to compile with our postgresql installation</strong>. You can turn the flag <em>-v</em> to enable verbose installation.  Watch for the configuration log output for PYTHON to check if it loads the PYTHON environment that we expect</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%PYTHON=/usr/local//bin/python brew install postgresql -v
....
checking for python... /usr/local/bin/python
checking for Python distutils module... yes
checking Python configuration directory... /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
...
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/mxcl/homebrew/issues/issue/2510
&nbsp;
To build plpython against a specific Python, set PYTHON prior to brewing:
  PYTHON=/usr/local/bin/python  brew install postgresql
See:
  http://www.postgresql.org/docs/9.0/static/install-procedure.html
&nbsp;
&nbsp;
If this is your first install, create a database with:
  initdb /usr/local/var/postgres
&nbsp;
If this is your first install, automatically load on login with:
  mkdir -p ~/Library/LaunchAgents
  cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
&nbsp;
If this is an upgrade and you already have the org.postgresql.postgres.plist loaded:
  launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
  cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
&nbsp;
Or start manually with:
  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
&nbsp;
And stop with:
  pg_ctl -D /usr/local/var/postgres stop -s -m fast
&nbsp;
&nbsp;
Some machines may require provisioning of shared memory:
  http://www.postgresql.org/docs/current/static/kernel-resources.html%SYSVIPC
&nbsp;
If you want to install the postgres gem, including ARCHFLAGS is recommended:
    env ARCHFLAGS=&quot;-arch x86_64&quot; gem install pg
&nbsp;
To install gems without sudo, see the Homebrew wiki.
==&gt; Summary
/usr/local/Cellar/postgresql/9.0.4: 2577 files, 35M, built in 3.1 minutes
brew install postgresql  188.73s user 62.38s system 106% cpu 3:55.06 total</pre></div></div>

<p><strong>3. Postgres Post Installation. Initialize DB.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% initdb -E utf8 -D /usr/local/var/postgres
The files belonging to this database system will be owned by user &quot;rupert&quot;.
This user must also own the server process.
&nbsp;
The database cluster will be initialized with locale en_AU.UTF-8.
The default text search configuration will be set to &quot;english&quot;.
&nbsp;
creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers ... 2400kB
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
&nbsp;
WARNING: enabling &quot;trust&quot; authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
&nbsp;
Success. You can now start the database server using:
&nbsp;
    postgres -D /usr/local/var/postgres
or
    pg_ctl -D /usr/local/var/postgres -l logfile start</pre></div></div>

<p><strong>4. Postgres Startup</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
% launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
%telnet 127.0.0.1 5432
Trying 127.0.0.1...
Connected to rupert-mbp.
Escape character is '^]'.
% psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql</pre></div></div>

<p>UPDATE:<br />
I have now disabled the automatic startup of Postgres as it provides me more control especially during development. Extract <a href="/wordpress/wp-content/uploads/2011/12/Postgres9.1.2.tar.gz" title="Postgres9.1.2.tar.gz">Postgres9.1.2.tar.gz</a> to /Library/StartupItems.</p>
<p>To start/stop</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/Library/StartupItems/Postgres9.1.2/Postgres9.1.2 start</pre></div></div>

<p><strong>5. Postgis</strong><br />
Note this will install dependencies, PROJ4 and GEOS. At the time of writing this, we have a problem with GEOS. Need to update GEOS formula to 3.3.1. For more info read:</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% open https://github.com/mxcl/homebrew/issues/8151
% open https://gist.github.com/1306088
% brew edit geos</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% brew install proj
% brew install geos
% brew install postgis
% createdb -E utf8 template_postgis
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql</pre></div></div>

<p><strong>6. osm2pgsql</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% brew install osm2pgsql
==&gt; Checking out http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/
==&gt; ./autogen.sh
==&gt; ./configure
==&gt; make
/usr/local/Cellar/osm2pgsql/HEAD: 6 files, 328K, built in 70 seconds</pre></div></div>

<p><strong>7. Check for loaded/configured PLPYTHON environment for POSTGRES</strong><br />
If you get import module errors, you should check your PYTHON version and if the module is loaded in your python&#8217;s site-packages.  The function below will provide which version of PYTHON is compiled with your POSTGRESQL.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURAL</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span>
<span style="color: #ff0000;">'plpythonu'</span> HANDLER plpython_call_handler;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> pyver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> returns text <span style="color: #993333; font-weight: bold;">AS</span>
$$
import sys
<span style="color: #993333; font-weight: bold;">RETURN</span> sys<span style="color: #66cc66;">.</span>version
$$ <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> pyver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #ff0000;">&quot;2.7.2 (default, Dec 30 2011, 09:25:27) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)]&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing a table_name to a postgres plpgsql function</title>
		<link>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/</link>
		<comments>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 04:32:04 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1011</guid>
		<description><![CDATA[Using a table_name in a function. The parameter p_schema_name will be passed as a string to the sql string statement processed by EXECUTE. Possible gotchas I encountered here was the FOUND variable is useless after an EXECUTE statement. EXECUTE 'UPDATE...&#34;; IF found THEN --this is not set when we use EXECUTE. END IF; CREATE OR [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Using a table_name in a function.</strong><br />
The parameter p_schema_name will be passed as a string to the sql string statement processed by EXECUTE. Possible gotchas I encountered here was the FOUND variable is useless after an EXECUTE statement.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">EXECUTE <span style="color: #ff0000;">'UPDATE...&quot;;
IF found THEN --this is not set when we use EXECUTE. 
END IF;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> dfms<span style="color: #66cc66;">.</span>upsert_ncm_execution<span style="color: #66cc66;">&#40;</span>p_schema_name text<span style="color: #66cc66;">,</span> p_fleet_id integer<span style="color: #66cc66;">,</span> p_ncm_number integer<span style="color: #66cc66;">,</span> p_version text<span style="color: #66cc66;">,</span> p_hostname text<span style="color: #66cc66;">,</span> p_process_id integer<span style="color: #66cc66;">,</span> p_execution_id integer<span style="color: #66cc66;">&#41;</span>
  RETURNS integer <span style="color: #993333; font-weight: bold;">AS</span>
$BODY$
DECLARE
  record_found <span style="color: #993333; font-weight: bold;">BOOLEAN</span>;
  execution_id INTEGER;
BEGIN
    EXECUTE <span style="color: #ff0000;">'SELECT count(*) FROM '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">INTO</span> record_found <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
    <span style="color: #993333; font-weight: bold;">IF</span> record_found THEN
      EXECUTE <span style="color: #ff0000;">'UPDATE '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions SET execution_id = execution_id + 1 WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
    ELSE
      BEGIN
        EXECUTE <span style="color: #ff0000;">'INSERT INTO '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions(fleet_id, ncm_number, version, hostname, process_id, execution_id) VALUES($1, $2, $3, $4, $5, $6)'</span> <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number<span style="color: #66cc66;">,</span> p_version<span style="color: #66cc66;">,</span> p_hostname<span style="color: #66cc66;">,</span> p_process_id<span style="color: #66cc66;">,</span> p_execution_id;
      EXCEPTION WHEN unique_violation THEN
        <span style="color: #808080; font-style: italic;">-- do nothing</span>
      END;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    EXECUTE <span style="color: #ff0000;">'SELECT execution_id FROM '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">INTO</span> execution_id <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
&nbsp;
    <span style="color: #993333; font-weight: bold;">RETURN</span> execution_id;
END;
$BODY$
  <span style="color: #993333; font-weight: bold;">LANGUAGE</span> plpgsql VOLATILE
  COST <span style="color: #cc66cc;">100</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to use a schema name in mysql2psql</title>
		<link>/wordpress/2011/08/migrating-from-mysql-to-postgres/</link>
		<comments>/wordpress/2011/08/migrating-from-mysql-to-postgres/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 02:07:23 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1009</guid>
		<description><![CDATA[Below is a summary of my experiences with migrating from MySQL to Postgres using mysql2psql &#8211; https://github.com/maxlapshin/mysql2postgres %gem install mysql2psql To migrate a &#8220;tsa&#8221; database from mysql to postgres, create a tsa.yml mysql: hostname: localhost port: 3306 socket: /tmp/mysql.sock username: dbadmin password: password database: tsa &#160; destination: # if file is given, output goes to [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a summary of my experiences with migrating from MySQL to Postgres using <strong>mysql2psql &#8211; <a href="https://github.com/maxlapshin/mysql2postgres">https://github.com/maxlapshin/mysql2postgres</a></strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql2psql</pre></div></div>

<p>To migrate a &#8220;tsa&#8221; database from mysql to postgres, create a tsa.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">mysql:
 hostname: localhost
 port: 3306 
 socket: /tmp/mysql.sock
 username: dbadmin 
 password: password
 database: tsa
&nbsp;
destination:
 # if file is given, output goes to file, else postgres
 #file: tsa.dump
 postgres:
  hostname: localhost
  port: 5432 
  database: tsa:hotels #database_name:schema_name
  username: dbadmin
  password: password
&nbsp;
# if tables is given, only the listed tables will be converted.  leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
&nbsp;
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
&nbsp;
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
&nbsp;
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false</pre></div></div>

<p>Run.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>mysql2psql tsa.yml</pre></div></div>

<p>References:<br />
<a href="http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL">http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/08/migrating-from-mysql-to-postgres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postgres8.3,8.4,9.0, Postgis1.3.3,1.4.1,2.0, pgRouting on OSX  (updated)</title>
		<link>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/</link>
		<comments>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 03:31:08 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pgRouting]]></category>

		<guid isPermaLink="false">/wordpress/?p=843</guid>
		<description><![CDATA[(Updated):Postgres9.0.3 Postgis2.0svn Before you go any further. Dump data before migrating and installing. Warning: Most of the packages listed below is installed by source. 1. Download the current postgres source. http://www.postgresql.org/ftp/source/ 8.3: $./configure --with-prefix=/usr/local/pgsql --with-python &#160; 8.4: $./configure --prefix=/usr/local/pgsql --with-python &#160; $make $sudo make install 2. Don&#8217;t delete the postgres folder. You might need this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>(Updated):Postgres9.0.3 Postgis2.0svn</strong></p>
<p>Before you go any further. <a href="/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/">Dump data before migrating and installing.</a>  <i>Warning: Most of the packages listed below is installed by source.</i></p>
<p>1. Download the current postgres source. <a href="http://www.postgresql.org/ftp/source/">http://www.postgresql.org/ftp/source/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #000000;">8.4</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>2. Don&#8217;t delete the postgres folder. You might need this later on for future compilations. See pgadmin3 admin pack below.</p>
<p>3. Add a postgres user from <strong>System Preferences &gt; Accounts</strong></p>
<p>4. Initialize the data directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data
<span style="color: #007800;">$chown</span> postgres <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">$su</span> - postgres
$<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>initdb <span style="color: #660033;">-E</span> utf8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data</pre></div></div>

<blockquote>
<pre>
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default text search configuration will be set to "english".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
</pre>
</blockquote>
<p>4. Install Geos , PROJ4, and Postgis</p>
<p><b>GEOS:</b><br/><br />
- install geos with the Kyngchaos installer</p>
<p>- installing by source</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout http:<span style="color: #000000; font-weight: bold;">//</span>svn.osgeo.org<span style="color: #000000; font-weight: bold;">/</span>geos<span style="color: #000000; font-weight: bold;">/</span>trunk trunk
<span style="color: #7a0874; font-weight: bold;">cd</span> trunk<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> autogen.sh
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>geos <span style="color: #660033;">--enable-python</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>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><b>PROJ4:</b><br/></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.osgeo.org<span style="color: #000000; font-weight: bold;">/</span>metacrs<span style="color: #000000; font-weight: bold;">/</span>proj<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>proj<span style="color: #000000; font-weight: bold;">/</span> proj
<span style="color: #7a0874; font-weight: bold;">cd</span> proj
<span style="color: #c20cb9; font-weight: bold;">sh</span> autogen.sh
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>proj4
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><b>POSTGIS:</b><br/></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geos</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #000000;">8.4</span> using Kyngchaos GEOS Framework:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>GEOS.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #000000;">9.0</span>:using Kyngchaos GEOS + PROJ framework:<span style="color: #7a0874; font-weight: bold;">&#40;</span>Update Feb <span style="color: #000000;">15</span>, <span style="color: #000000;">2011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>GEOS.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config <span style="color: #660033;">--with-projdir</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>PROJ.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--with-gettext</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gettext<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
Note: libintl.h error. You need <span style="color: #c20cb9; font-weight: bold;">gettext</span>
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-O2</span>  <span style="color: #660033;">-fno-common</span> <span style="color: #660033;">-DPIC</span>  <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-Wmissing-prototypes</span>  -DUSE_NLS <span style="color: #660033;">-DLOCALEDIR</span>=<span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>locale<span style="color: #000000; font-weight: bold;">\&quot;</span> -Iyes<span style="color: #000000; font-weight: bold;">/</span>include  <span style="color: #660033;">-c</span> shp2pgsql-core.c
In <span style="color: #c20cb9; font-weight: bold;">file</span> included from shp2pgsql-core.c:<span style="color: #000000;">15</span>:
shp2pgsql-core.h:<span style="color: #000000;">17</span>:<span style="color: #000000;">21</span>: error: libintl.h: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or di
&nbsp;
9.0.4: using src from GEOS + PROJ
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>geos<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config <span style="color: #660033;">--with-projdir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>proj4
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>If everthing is successful, you should see files in /usr/local/pgsql/share/contrib/.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span>
- legacy.sql
- postgis.sql
- postgis_upgrade_20_minor.sql
- spatial_ref_sys.sql
- uninstall_legacy.sql
- uninstall_postgis.sql</pre></div></div>

<p>5. Starting postgres on boot. Download <a href='/wordpress/wp-content/uploads/2008/05/postgresstartup.tar.gz'>postgresstartup.tar.gz</a> then extract to your /Library/StartupItems</p>
<p>6. Creating the database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createdb <span style="color: #660033;">-E</span> utf8 template_postgis
createlang plpgsql template_postgis
&nbsp;
<span style="color: #000000;">8.3</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>lwpostgis.sql
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #000000;">8.4</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis.sql 
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #000000;">9.0</span> + postgis2.0:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span><span style="color: #000000; font-weight: bold;">/</span>postgis.sql 
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span><span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql</pre></div></div>

<p>7. Install and download pgAdmin3 for MacOS X </p>
<p><a href="http://www.postgresql.org/ftp/pgadmin3/release/">http://www.postgresql.org/ftp/pgadmin3/release/</a></p>
<p>Update Feb 15, 2011: Use pgadmin1.12 to connect with postgres9. <a href="http://postgresql.1045698.n5.nabble.com/BUG-5668-initdb-failed-to-create-postgres-database-td2847489.html<br />
">Other versions (1.8.4, 1.6.3 don&#8217;t work)</a></p>
<p>8. Startup pgadmin3. You will notice there is a window stating&#8230;</p>
<blockquote><p>Server instrumentation<br />
The server lacks instrumentation functions.<br />
pgAdmin III uses some support functions that are not available by default in all PostgreSQL versions. These enable some tasks that make life easier when dealing with log files and configuration files. </p></blockquote>
<p>9. Compile the adminpack. Go to $postgresql_install_directory/contrib/adminpack</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-no-cpp-precomp</span> <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-Wmissing-prototypes</span> <span style="color: #660033;">-Wpointer-arith</span> <span style="color: #660033;">-Winline</span> <span style="color: #660033;">-Wdeclaration-after-statement</span> <span style="color: #660033;">-Wendif-labels</span> <span style="color: #660033;">-fno-strict-aliasing</span> <span style="color: #660033;">-fwrapv</span>  <span style="color: #660033;">-bundle</span> -multiply_defined suppress  adminpack.o  -L..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>port -bundle_loader ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>backend<span style="color: #000000; font-weight: bold;">/</span>postgres  <span style="color: #660033;">-o</span> libadminpack.0.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.so
&nbsp;
rupert:adminpack rupert$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
Password:
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> .<span style="color: #000000; font-weight: bold;">/</span>uninstall_adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">755</span>  libadminpack.0.0.so <span style="color: #ff0000;">'/usr/local/pgsql/lib/adminpack.so'</span></pre></div></div>

<p>10. Load the adminpack.sql into your maintenance and template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>adminpack.sql 
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
...</pre></div></div>

<p>11. Disconnect and Reconnect from pgAdmin3. You shouldn&#8217;t see the window again.</p>
<p>Continue only if you want pgRouting</p>
<p>12. Essentially we would need <a href="http://www.boost.org/">Boost Graph Library (BGL)</a> a.k.a boost, <a href="http://gaul.sourceforge.net/">Genetic Algorithm Utility Library</a> (or, GAUL for short), and GEOS (which we installed earlier when we installed postgis).</p>
<p>13. The easiest way to install boost is using MacPorts.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost-jam-3.1.16.tgz from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging boost-jam into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch make-3.81.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>ftp.gnu.org<span style="color: #000000; font-weight: bold;">/</span>gnu<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">make</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building <span style="color: #c20cb9; font-weight: bold;">gmake</span> with target all
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging <span style="color: #c20cb9; font-weight: bold;">gmake</span> into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost_1_34_1.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
...
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost</pre></div></div>

<p>Note: I encountered an error when I directly installed &#8220;sudo port install boost&#8221; on my first run. A quick workaround is to install boost-jam, then install boost afterwards. For more details:</p>
<ul>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/13714">http://trac.macosforge.org/projects/macports/ticket/13714</a></li>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/14043">http://trac.macosforge.org/projects/macports/ticket/14043</a></li>
</ul>
<blockquote><p>Error: Target org.macports.build returned: shell command &#8221; cd &#8220;/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_boost/work/boost_1_34_1&#8243; &#038;&#038; gmake all &#8221; returned error 2 Command output: Makefile:2: *** missing separator.  Stop.</p></blockquote>
<p>14. You can check if boost was successfully installed by&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-v</span> installed boost boost-jam
The following ports are currently installed:
  boost <span style="color: #000000; font-weight: bold;">@</span>1.34.1_3+darwin_9 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  boost-jam <span style="color: #000000; font-weight: bold;">@</span>3.1.16_0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>15. For GAUL, we don&#8217;t need slang base on <a href="http://pgrouting.postlbs.org/wiki/1.x/InstallationManual">http://pgrouting.postlbs.org/wiki/1.x/InstallationManual</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-slang</span>=no
$ <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>16. Ok, so this is the heartbreaker. I was able to get pass cmake on pgRouting on version 1.02 however, I received &#8220;undefined symbols&#8221; when linking the librouting.dylib</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Linking CXX shared library ../../lib/librouting.dylib
Undefined symbols:
  &quot;_errcode&quot;, referenced from:
      _shortest_path in dijkstra.o
      _shortest_path_astar in astar.o
      _shortest_path_shooting_star in shooting_star.o</pre></div></div>

<p>For the complete error details, see <a href='/wordpress/wp-content/uploads/2008/05/pgrouting_problem.txt'>pgrouting_problem.txt</a></p>
<p>17. Thanks to www.kyngchaos.com, we can install <a href="http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg">http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg</a> binary from http://www.kyngchaos.com/wiki/software:postgres</p>
<p>18. Now we can load the pgRouting functions to our template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp_wrappers.sql</pre></div></div>

<p>References:</p>
<p>http://developer.apple.com/internet/opensource/postgres.html</p>
<p>http://www2.russbrooks.com:8080/2007/11/4/install-postgresql-on-mac-os-x-10-5-leopard</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating postgres/postgis data (updated)</title>
		<link>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/</link>
		<comments>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 00:51:56 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=827</guid>
		<description><![CDATA[One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually. 1. pg_dump is your friend. pg_dump --help 2. I strongly suggest if you have a big dump file (mine is 500MB) to [...]]]></description>
			<content:encoded><![CDATA[<p>One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually.</p>
<p>1. pg_dump is your friend.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">--help</span></pre></div></div>

<p>2. I strongly suggest if you have a big dump file (mine is 500MB) to split the schema from the data. </p>
<p>Add &#8220;-s&#8221; to create the schema:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-C</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>Add &#8220;-a&#8221; to dump the data only:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-a</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>3. pg_dump from an 8.2 would have statically linked liblwgeom to /usr/lib/postgresql/8.2/liblwgeom. You should change that to whereever your liblwgeom resides, mine is on /usr/local/pgsql/lib/liblwgeom. Just do a simple search and replace using vim on your file_schema.sql</p>
<p>4. After editing the schema, we can now restore the structure of the database. Check for errors and manually update the schema if needs be.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>5. Ok, so now we have the structure ready, we can also check this from pgAdmin3. Have a good look on the functions and table structures if they are fully restored. </p>
<p>6. Let&#8217;s load the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_data.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postgres PostGIS CheatSheet v2</title>
		<link>/wordpress/2010/11/postgres-postgis-cheatsheet-v2-2/</link>
		<comments>/wordpress/2010/11/postgres-postgis-cheatsheet-v2-2/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 02:29:12 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=798</guid>
		<description><![CDATA[This is a quick-command list of Postres. If you want detailed instructions, please visit the Postgres Manual. How do I know the version of Postgis? SELECT POSTGIS_FULL_VERSION&#40;&#41;; How do I Show all databases? 1. Using &#8220;psql -l&#8221; 2. Using postgres=# \l List of databases Name &#124; Owner &#124; Encoding ------------------+----------+---------- postgis &#124; postgres &#124; UTF8 [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick-command list of Postres. If you want detailed instructions, please visit the Postgres Manual.</p>
<p><strong>How do I know the version of Postgis? </strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> POSTGIS_FULL_VERSION<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><strong>How do I Show all databases? </strong><br />
1. Using &#8220;psql -l&#8221;</p>
<p>2. Using</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">postgres</span>=<span style="color: #666666; font-style: italic;"># \l</span>
List of databases
Name       <span style="color: #000000; font-weight: bold;">|</span>  Owner   <span style="color: #000000; font-weight: bold;">|</span> Encoding
------------------+----------+----------
postgis          <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
postgres         <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template0        <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template1        <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template_postgis <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span> rows<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Note: Do not drop template databases if not necessary.</p>
<p><strong>How do I run a script from the prompt?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-d</span> cybersoftbj <span style="color: #660033;">-u</span> user <span style="color: #660033;">-f</span> myfile.sql</pre></div></div>

<p>Its very useful in reloading user-defined functions.</p>
<p><strong>How do I create a user/role?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> ROLE lbs <span style="color: #993333; font-weight: bold;">WITH</span> LOGIN PASSWORD <span style="color: #ff0000;">'mypassword'</span> SUPERUSER INHERIT CREATEDB CREATEROLE;</pre></div></div>

<p><strong>How do I change the password for a user/role?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> ROLE lbs PASSWORD <span style="color: #ff0000;">'mynewpassword'</span>;</pre></div></div>

<p><strong>How to provide/restrict access privileges to tables?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">TO</span> user;
<span style="color: #993333; font-weight: bold;">REVOKE</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">FROM</span> user;</pre></div></div>

<p><strong>How to dump database in a text file?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-d</span> cybersoftbjv1 <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-W</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; cybersoftbjv1.sql</pre></div></div>

<p><strong>How to dump database cleanly?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> pg_dump <span style="color: #660033;">-c</span>  <span style="color: #660033;">-d</span> <span style="color: #660033;">-E</span> UTF8 <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> platform_v1 <span style="color: #000000; font-weight: bold;">&amp;</span>gt; platform_v1.sql</pre></div></div>

<p><strong>How to rename a database?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> beijing_app <span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TO</span> beijing_app_20080801;</pre></div></div>

<p><strong>How to update using two tables?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> road_for_update u
<span style="color: #993333; font-weight: bold;">SET</span> the_geom <span style="color: #66cc66;">=</span> r<span style="color: #66cc66;">.</span>the_geom
<span style="color: #993333; font-weight: bold;">FROM</span> roads r
<span style="color: #993333; font-weight: bold;">WHERE</span> r<span style="color: #66cc66;">.</span>rd_id <span style="color: #66cc66;">=</span> u<span style="color: #66cc66;">.</span>rd_id;</pre></div></div>

<p><strong>DROP TABLE</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">&quot;my_table&quot;</span>;</pre></div></div>

<p><strong>How to change a column type with Cast?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> roads <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> class_new TYPE integer <span style="color: #993333; font-weight: bold;">USING</span> class_new::integer;</pre></div></div>

<p><strong>How to add a geometry column to a table?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> AddGeometryColumn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'public'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'poi'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'the_geom'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'POINT'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>Changing column names with spaces?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ALTER TABLE class_aroundme RENAME <span style="color: #ff0000;">&quot;level 1&quot;</span> TO level_1;</pre></div></div>

<p><strong>Setting kernel shmmax for postgres</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> sysctl <span style="color: #660033;">-w</span> kernel.shmmax=<span style="color: #000000;">134217728</span></pre></div></div>

<p>Note: For permanent changes see /etc/sysctl.cfg</p>
<p><strong>11. How to backup table(s) from pg_dump?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> pg_dump poi_beijing <span style="color: #660033;">-t</span> class <span style="color: #660033;">-t</span> poi_class <span style="color: #660033;">-f</span> <span style="color: #007800;">$BACKUPDIR</span><span style="color: #000000; font-weight: bold;">/</span>test_<span style="color: #007800;">$MYDATE</span>.sql</pre></div></div>

<p><strong>Change integer primary key to serial</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> SEQUENCE seq_job_id INCREMENT <span style="color: #cc66cc;">1</span> MINVALUE <span style="color: #cc66cc;">1000</span> MAXVALUE <span style="color: #cc66cc;">2147483648</span> START <span style="color: #cc66cc;">1000</span> CACHE <span style="color: #cc66cc;">1</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> job <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> job_id <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'seq_job_id'</span>::regclass<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> job
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'seq_job_id'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>Date and Time Function Helper: date_add</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> date_add<span style="color: #66cc66;">&#40;</span>diffType Character Varying<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> incrementValue bigint<span style="color: #66cc66;">,</span> inputDateTime timestamp without time zone<span style="color: #66cc66;">&#41;</span> RETURNS timestamp <span style="color: #993333; font-weight: bold;">AS</span> $$
DECLARE
   YEAR_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'year'</span>;
   MONTH_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'month'</span>;
   DAY_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'day'</span>;
   HOUR_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'hour'</span>;
   MIN_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'minute'</span>;
   SEC_CONST Char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'second'</span>;
&nbsp;
   dateTemp timestamp without time zone;
   intervals interval;
BEGIN
   <span style="color: #993333; font-weight: bold;">IF</span> lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>YEAR_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' year'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;
   ELSEIF lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>MONTH_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' months'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;
   ELSEIF lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>DAY_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' day'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;
   ELSEIF lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>HOUR_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' hours'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;
   ELSEIF lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>MIN_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' minutes'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;
   ELSEIF lower<span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> lower<span style="color: #66cc66;">&#40;</span>SEC_CONST<span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">SELECT</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span>incrementvalue <span style="color: #993333; font-weight: bold;">AS</span> character varying<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' seconds'</span> <span style="color: #993333; font-weight: bold;">AS</span> interval<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> intervals;            
   END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
   dateTemp:<span style="color: #66cc66;">=</span> inputDateTime <span style="color: #66cc66;">+</span> intervals;
&nbsp;
   <span style="color: #993333; font-weight: bold;">RETURN</span> dateTemp;
END;
$$ <span style="color: #993333; font-weight: bold;">LANGUAGE</span> plpgsql;</pre></div></div>

<p><strong>How to set the current timezone in postgres?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Session based only</span>
<span style="color: #993333; font-weight: bold;">SET</span> time zone <span style="color: #ff0000;">'utc'</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span>  current_setting<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'TIMEZONE'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;"># Permanent</span>
<span style="color: #808080; font-style: italic;"># Edit /usr/local/var/postgres/postgresql.conf (#postgres installed via homebrew)</span>
timezone <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTC'</span></pre></div></div>

<p><strong>Date/Time Functions</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> current_setting<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'TIMEZONE'</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #808080; font-style: italic;">--&quot;Australia/Victoria&quot;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> Now<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
timezone<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'UTC'</span><span style="color: #66cc66;">,</span> now<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
EXTRACT<span style="color: #66cc66;">&#40;</span>EPOCH <span style="color: #993333; font-weight: bold;">FROM</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
to_timestamp<span style="color: #66cc66;">&#40;</span>EXTRACT<span style="color: #66cc66;">&#40;</span>EPOCH <span style="color: #993333; font-weight: bold;">FROM</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
to_timestamp<span style="color: #66cc66;">&#40;</span>EXTRACT<span style="color: #66cc66;">&#40;</span>EPOCH <span style="color: #993333; font-weight: bold;">FROM</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>::TIMESTAMP
&nbsp;
<span style="color: #808080; font-style: italic;">--&quot;2011-11-14 09:29:14.249427+11&quot; </span>
<span style="color: #808080; font-style: italic;">--&quot;2011-11-13 22:29:14.249427&quot;</span>
<span style="color: #808080; font-style: italic;">--1321223354</span>
<span style="color: #808080; font-style: italic;">--&quot;2011-11-14 09:29:14+11&quot;</span>
<span style="color: #808080; font-style: italic;">--&quot;2011-11-14 09:29:14&quot;</span></pre></div></div>

<p><strong>How to specify the id of a sequence to prevent SQL Error: PGRES_FATAL_ERROR:ERROR:  duplicate key value violates unique constraint &#8220;gps_histories_pkey&#8221;?</strong><br />
This happens when the maximum number of records in gps_histories is not in sync with the sequence id.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SETVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'dfms_4000.gps_histories_id_seq'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MAX<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> dfms_4000<span style="color: #66cc66;">.</span>gps_histories<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/11/postgres-postgis-cheatsheet-v2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postgres PostGIS CheatSheet v2</title>
		<link>/wordpress/2008/08/postgres-postgis-cheatsheet-v2/</link>
		<comments>/wordpress/2008/08/postgres-postgis-cheatsheet-v2/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 05:10:32 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=229</guid>
		<description><![CDATA[This is a quick-command list of Postres. If you want detailed instructions, please visit the Postgres Manual. How do I Show all databases? 1. Using &#8220;psql -l&#8221; 2. Using postgres=# \l List of databases Name &#124; Owner &#124; Encoding ------------------+----------+---------- postgis &#124; postgres &#124; UTF8 postgres &#124; postgres &#124; UTF8 template0 &#124; postgres &#124; UTF8 [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick-command list of Postres. If you want detailed instructions, please visit the Postgres Manual.</p>
<p><strong>How do I Show all databases? </strong><br />
1. Using &#8220;psql -l&#8221;</p>
<p>2. Using</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">postgres</span>=<span style="color: #666666; font-style: italic;"># \l</span>
List of databases
Name       <span style="color: #000000; font-weight: bold;">|</span>  Owner   <span style="color: #000000; font-weight: bold;">|</span> Encoding
------------------+----------+----------
postgis          <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
postgres         <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template0        <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template1        <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
template_postgis <span style="color: #000000; font-weight: bold;">|</span> postgres <span style="color: #000000; font-weight: bold;">|</span> UTF8
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span> rows<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Note: Do not drop template databases if not necessary.</p>
<p><strong>How do I run a script from the prompt?</strong><br />
<code>psql -d cybersoftbj -u user -f myfile.sql</code></p>
<p>Its very useful in reloading user-defined functions.</p>
<p><strong>How do I create a user/role?</strong><br />
<code><br />
CREATE ROLE lbs WITH LOGIN PASSWORD 'mypassword' SUPERUSER INHERIT CREATEDB CREATEROLE;<br />
</code></p>
<p><strong>How do I change the password for a user/role?</strong><br />
<code><br />
ALTER ROLE lbs PASSWORD 'mynewpassword';<br />
</code></p>
<p><strong>How to provide/restrict access privileges to tables?</strong><br />
<code><br />
GRANT SELECT ON TABLE table TO user;<br />
REVOKE SELECT ON TABLE table FROM user;<br />
</code></p>
<p><strong>How to dump database in a text file?</strong><br />
<code><br />
pg_dump -U lbs -d cybersoftbjv1 -h 127.0.0.1 -W &gt; cybersoftbjv1.sql<br />
</code></p>
<p><strong>How to dump database cleanly?</strong><br />
<code><br />
pg_dump -c  -d -E UTF8 -h 127.0.0.1 -U lbs -W platform_v1 &gt; platform_v1.sql<br />
</code></p>
<p><strong>How to rename a database?</strong><br />
<code><br />
ALTER DATABASE beijing_app RENAME TO beijing_app_20080801;<br />
</code></p>
<p><strong>How to update using two tables?</strong><br />
<code><br />
UPDATE road_for_update u<br />
SET the_geom = r.the_geom<br />
FROM roads r<br />
WHERE r.rd_id = u.rd_id;<br />
</code></p>
<p><strong>How to change a column type with Cast?</strong><br />
<code><br />
ALTER TABLE roads ALTER COLUMN class_new TYPE integer USING class_new::integer;<br />
</code></p>
<p><strong>How to add a geometry column to a table?</strong><br />
EXAMPLE: SELECT AddGeometryColumn(&#8216;public&#8217;, &#8216;poi&#8217;, &#8216;the_geom&#8217;, 4326, &#8216;POINT&#8217;, 2)</p>
<p><strong>Changing column names with spaces?</strong><br />
<code>ALTER TABLE class_aroundme RENAME "level 1" TO level_1;</code> </p>
<p><strong>Setting kernel shmmax for postgres</strong><br />
<code>sysctl -w kernel.shmmax=134217728</code><br />
Note: For permanent changes see /etc/sysctl.cfg<strong>11. How to backup table(s) from pg_dump?</strong><br />
pg_dump poi_beijing -t class -t poi_class -f $BACKUPDIR/test_$MYDATE.sql</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/08/postgres-postgis-cheatsheet-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postgres Clients Update: Navicat and EMS</title>
		<link>/wordpress/2008/07/postgres-clients-update-navicat/</link>
		<comments>/wordpress/2008/07/postgres-clients-update-navicat/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 14:37:42 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[leopard]]></category>

		<guid isPermaLink="false">/wordpress/?p=199</guid>
		<description><![CDATA[Navicat already produced some lite (free) versions for Postgres both for Windows and Mac. Browse over the feature matrix to find out which version works for you. Note that all versions allow you to edit the record which I can&#8217;t do in pgadmin3. A quick look at EMS on Windows (VMWare) is also a note [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wordpress/wp-content/uploads/2008/07/picture-4.png" alt="Picture 4.png" border="0" width="300" height="214" /></p>
<p>Navicat already produced some lite (free) versions for Postgres both for Windows and Mac. Browse over the <a href="http://pgsql.navicat.com/feature.html">feature matrix</a> to find out which <a href="http://pgsql.navicat.com/download.html">version</a> works for you. Note that all versions allow you to edit the record which I can&#8217;t do in pgadmin3. </p>
<p><img src="/wordpress/wp-content/uploads/2008/07/picture-3.png" alt="Picture 3.png" border="0" width="600" height="338" /></p>
<p>A quick look at EMS on Windows (VMWare) is also a note worthy client. Though the MDI interface is a bit complex, one good feature is to able to see your spatial geometry as <em>text</em> and the corresponding SRID immediately&#8230;</p>
<p><img src="/wordpress/wp-content/uploads/2008/07/picture-1.png" alt="Picture 1.png" border="0" width="427" height="253" /></p>
<p><img src="/wordpress/wp-content/uploads/2008/07/picture-2.png" alt="Picture 2.png" border="0" width="600" height="186" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/07/postgres-clients-update-navicat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postgres PostGis PostInstall</title>
		<link>/wordpress/2008/06/postgres-postgis-postinstall/</link>
		<comments>/wordpress/2008/06/postgres-postgis-postinstall/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 23:34:36 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/index.php/2008/06/07/postgres-postgis-postinstall/</guid>
		<description><![CDATA[1. Edit pg_hba.conf # &#34;local&#34; is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 192.168.1.0 255.255.255.0 md5 # IPv6 local connections: #host all all ::1/128 trust 2. Edit postgres.conf 55 56 listen_addresses = '*' # what IP address(es) to listen on; [...]]]></description>
			<content:encoded><![CDATA[<p>1. Edit pg_hba.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># &quot;local&quot; is for Unix domain socket connections only</span>
<span style="color: #7a0874; font-weight: bold;">local</span>   all         all                               trust
<span style="color: #666666; font-style: italic;"># IPv4 local connections:</span>
host    all         all         127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>          md5
host    all         all         192.168.1.0 255.255.255.0       md5
<span style="color: #666666; font-style: italic;"># IPv6 local connections:</span>
<span style="color: #666666; font-style: italic;">#host    all         all         ::1/128               trust</span></pre></div></div>

<p>2. Edit postgres.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">55</span>
<span style="color: #000000;">56</span> listen_addresses = <span style="color: #ff0000;">'*'</span> <span style="color: #666666; font-style: italic;"># what IP address(es) to listen on;</span>
<span style="color: #000000;">57</span> <span style="color: #666666; font-style: italic;"># comma-separated list of addresses;</span>
<span style="color: #000000;">58</span> <span style="color: #666666; font-style: italic;"># defaults to 'localhost', '*' = all</span>
<span style="color: #000000;">59</span> <span style="color: #666666; font-style: italic;"># (change requires restart)</span></pre></div></div>

<p>4. For CentOS5.1, create symbolic links:<br />
  ln -s /usr/local/lib/libproj.so.0 /usr/lib/libproj.so.0<br />
  ln -s /usr/local/lib/libgeos_c.so.1 /usr/lib/libgeos_c.so.1<br />
  ldconfig<br />
  /etc/init.d/postgresql stop<br />
  /etc/init.d/postgresql start</p>
<p>3. Postgis Post Install</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createdb <span style="color: #660033;">-E</span> utf8 template_routing
createlang plpgsql template_routing
psql <span style="color: #660033;">-d</span> template_routing <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.3</span>-postgis<span style="color: #000000; font-weight: bold;">/</span>lwpostgis.sql 
psql <span style="color: #660033;">-d</span> template_routing <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.3</span>-postgis<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql 
psql <span style="color: #660033;">-d</span> template_routing <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>postlbs<span style="color: #000000; font-weight: bold;">/</span>routing_core.sql 
psql <span style="color: #660033;">-d</span> template_routing <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>postlbs<span style="color: #000000; font-weight: bold;">/</span>routing_core_wrappers.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/06/postgres-postgis-postinstall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postgresql, Postgis, pgRouting on Debian</title>
		<link>/wordpress/2008/05/installing-postgresql-postgis-pgrouting-on-debian/</link>
		<comments>/wordpress/2008/05/installing-postgresql-postgis-pgrouting-on-debian/#comments</comments>
		<pubDate>Sun, 25 May 2008 03:55:57 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[pgRouting]]></category>

		<guid isPermaLink="false">/wordpress/index.php/2008/05/25/installing-postgresql-postgis-pgrouting-on-debian/</guid>
		<description><![CDATA[Operating System: Debian sid Versions: postgres 8.3.1 postgis 1.3.3 pgRouting1.02 1. Install base system and ssh #vi /etc/apt/sources.list to include deb http://debian.cn99.com/debian etch main deb-src http://debian.cn99.com/debian etch main #apt-get update #apt-get upgrade libc6 2. Install the required packages for postgres8.3 and postgis1.3.3 #apt-get install sudo nmap telnet #apt-get install python2.5 python2.5-dev python-setuptools #apt-get install g++ [...]]]></description>
			<content:encoded><![CDATA[<p>Operating System: Debian sid</p>
<p>Versions:</p>
<ul>
<li>postgres 8.3.1</li>
<li>postgis 1.3.3</li>
<li>pgRouting1.02</li>
</ul>
<p>1. Install base system and ssh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#vi /etc/apt/sources.list to include</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>debian.cn99.com<span style="color: #000000; font-weight: bold;">/</span>debian etch main
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>debian.cn99.com<span style="color: #000000; font-weight: bold;">/</span>debian etch main
<span style="color: #666666; font-style: italic;">#apt-get update</span>
<span style="color: #666666; font-style: italic;">#apt-get upgrade libc6</span></pre></div></div>

<p>2. Install the required packages for postgres8.3 and postgis1.3.3</p>
<pre lang="bash" xml:lang="bash">
#apt-get install sudo nmap telnet
#apt-get install python2.5 python2.5-dev python-setuptools
#apt-get install g++
#apt-get install build-essential cmake ibboost-graph-dev
#apt-get install libreadline5 libreadline5-dev
#apt-get install zlib-bin zlib1g-dev
#apt-get install libkrb5-dev
#apt-get install libcurl3
#apt-get install libssl-dev
#apt-get install postgresql-8.3
#apt-get install postgresql-8.3-postgis
#apt-get install postgresql-server-dev-8.3
</pre>
<p>3. Installing pgRouting</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># tar -zxvf pgRouting-1.02.tgz</span>
<span style="color: #666666; font-style: italic;"># cmake .</span>
<span style="color: #666666; font-style: italic;"># make </span>
<span style="color: #666666; font-style: italic;"># make install</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/05/installing-postgresql-postgis-pgrouting-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating data from Postgres8.2 to Postgres8.3</title>
		<link>/wordpress/2008/05/migrating-data-from-postgres82-to-postgres83/</link>
		<comments>/wordpress/2008/05/migrating-data-from-postgres82-to-postgres83/#comments</comments>
		<pubDate>Wed, 07 May 2008 00:56:28 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=182</guid>
		<description><![CDATA[One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually. Here are the results: 1. I strongly suggest if you have a big dump file (mine is 500MB) to split the schema [...]]]></description>
			<content:encoded><![CDATA[<p>One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually. Here are the results:</p>
<p>1. I strongly suggest if you have a big dump file (mine is 500MB) to split the schema from the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-C</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql
pg_dump <span style="color: #660033;">-a</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>2. pg_dump from an 8.2 would have statically linked liblwgeom to /usr/lib/postgresql/8.2/liblwgeom. You should change that to whereever your liblwgeom resides, mine is on /usr/local/pgsql/lib/liblwgeom. Just do a simple search and replace using vim on your file_schema.sql</p>
<p>3. After editing the schema, we can now restore the structure of the database. Check for errors and manually update the schema if needs be.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>4. Ok, so now we have the structure ready, we can also check this from pgAdmin3. Have a good look on the functions and table structures if they are fully restored. </p>
<p>5. Let&#8217;s load the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_data.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/05/migrating-data-from-postgres82-to-postgres83/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postgres8.3,8.4, Postgis1.3.3,1.4.1, pgRouting on MacOSX Leopard</title>
		<link>/wordpress/2008/05/installing-postgres83-postgis133-pgrouting-on-macosx-leopard/</link>
		<comments>/wordpress/2008/05/installing-postgres83-postgis133-pgrouting-on-macosx-leopard/#comments</comments>
		<pubDate>Thu, 01 May 2008 08:36:57 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[pgRouting]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=173</guid>
		<description><![CDATA[References: http://developer.apple.com/internet/opensource/postgres.html http://www2.russbrooks.com:8080/2007/11/4/install-postgresql-on-mac-os-x-10-5-leopard Warning: Most of the packages listed below is installed by source. 1. Download the current postgres source. 8.3: $./configure --with-prefix=/usr/local/pgsql --with-python &#160; 8.4: $./configure --prefix=/usr/local/pgsql --with-python &#160; $make $sudo make install 2. Don&#8217;t delete the postgres folder. You might need this later on for future compilations. See pgadmin3 admin pack below. 3. [...]]]></description>
			<content:encoded><![CDATA[<p>References:</p>
<p>http://developer.apple.com/internet/opensource/postgres.html</p>
<p>http://www2.russbrooks.com:8080/2007/11/4/install-postgresql-on-mac-os-x-10-5-leopard</p>
<p><strong>Warning: Most of the packages listed below is installed by source.</strong></p>
<p>1. Download the current postgres source.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #000000;">8.4</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>2. Don&#8217;t delete the postgres folder. You might need this later on for future compilations. See pgadmin3 admin pack below.</p>
<p>3. Add a postgres user from <strong>System Preferences &gt; Accounts</strong></p>
<p>4. Initialize the data directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data
<span style="color: #007800;">$chown</span> postgres <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">$su</span> - postgres
$<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>initdb <span style="color: #660033;">-E</span> utf8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data</pre></div></div>

<blockquote>
<pre>
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default text search configuration will be set to "english".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
</pre>
</blockquote>
<p>4. Install Postgis<br />
- install geos with the standard ./configure -> make -> make install<br />
- then install postgis</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geos</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #000000;">8.4</span> using Kyngchaos GEOS Framework:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>GEOS.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>5. Starting postgres on boot. Download <a href='/wordpress/wp-content/uploads/2008/05/postgresstartup.tar.gz'>postgresstartup.tar.gz</a> then extract to your /Library/StartupItems</p>
<p>6. Creating the database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createdb <span style="color: #660033;">-E</span> utf8 template_postgis
createlang plpgsql template_postgis
&nbsp;
<span style="color: #000000;">8.3</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>lwpostgis.sql
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #000000;">8.4</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis.sql 
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql</pre></div></div>

<p>7. Install and download pgAdmin3 for MacOS X </p>
<p><a href="http://www.postgresql.org/ftp/pgadmin3/release/">http://www.postgresql.org/ftp/pgadmin3/release/</a></p>
<p>8. Startup pgadmin3. You will notice there is a window stating&#8230;</p>
<blockquote><p>Server instrumentation<br />
The server lacks instrumentation functions.<br />
pgAdmin III uses some support functions that are not available by default in all PostgreSQL versions. These enable some tasks that make life easier when dealing with log files and configuration files. </p></blockquote>
<p>9. Compile the adminpack. Go to $postgresql_install_directory/contrib/adminpack</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-no-cpp-precomp</span> <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-Wmissing-prototypes</span> <span style="color: #660033;">-Wpointer-arith</span> <span style="color: #660033;">-Winline</span> <span style="color: #660033;">-Wdeclaration-after-statement</span> <span style="color: #660033;">-Wendif-labels</span> <span style="color: #660033;">-fno-strict-aliasing</span> <span style="color: #660033;">-fwrapv</span>  <span style="color: #660033;">-bundle</span> -multiply_defined suppress  adminpack.o  -L..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>port -bundle_loader ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>backend<span style="color: #000000; font-weight: bold;">/</span>postgres  <span style="color: #660033;">-o</span> libadminpack.0.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.so
&nbsp;
rupert:adminpack rupert$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
Password:
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> .<span style="color: #000000; font-weight: bold;">/</span>uninstall_adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">755</span>  libadminpack.0.0.so <span style="color: #ff0000;">'/usr/local/pgsql/lib/adminpack.so'</span></pre></div></div>

<p>10. Load the adminpack.sql into your maintenance and template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>adminpack.sql 
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
...</pre></div></div>

<p>11. Disconnect and Reconnect from pgAdmin3. You shouldn&#8217;t see the window again.</p>
<p>Continue only if you want pgRouting</p>
<p>12. Essentially we would need <a href="http://www.boost.org/">Boost Graph Library (BGL)</a> a.k.a boost, <a href="http://gaul.sourceforge.net/">Genetic Algorithm Utility Library</a> (or, GAUL for short), and GEOS (which we installed earlier when we installed postgis).</p>
<p>13. The easiest way to install boost is using MacPorts.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost-jam-3.1.16.tgz from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging boost-jam into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch make-3.81.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>ftp.gnu.org<span style="color: #000000; font-weight: bold;">/</span>gnu<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">make</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building <span style="color: #c20cb9; font-weight: bold;">gmake</span> with target all
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging <span style="color: #c20cb9; font-weight: bold;">gmake</span> into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost_1_34_1.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
...
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost</pre></div></div>

<p>Note: I encountered an error when I directly installed &#8220;sudo port install boost&#8221; on my first run. A quick workaround is to install boost-jam, then install boost afterwards. For more details:</p>
<ul>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/13714">http://trac.macosforge.org/projects/macports/ticket/13714</a></li>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/14043">http://trac.macosforge.org/projects/macports/ticket/14043</a></li>
</ul>
<blockquote><p>Error: Target org.macports.build returned: shell command &#8221; cd &#8220;/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_boost/work/boost_1_34_1&#8243; &#038;&#038; gmake all &#8221; returned error 2 Command output: Makefile:2: *** missing separator.  Stop.</p></blockquote>
<p>14. You can check if boost was successfully installed by&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-v</span> installed boost boost-jam
The following ports are currently installed:
  boost <span style="color: #000000; font-weight: bold;">@</span>1.34.1_3+darwin_9 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  boost-jam <span style="color: #000000; font-weight: bold;">@</span>3.1.16_0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>15. For GAUL, we don&#8217;t need slang base on <a href="http://pgrouting.postlbs.org/wiki/1.x/InstallationManual">http://pgrouting.postlbs.org/wiki/1.x/InstallationManual</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-slang</span>=no
$ <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>16. Ok, so this is the heartbreaker. I was able to get pass cmake on pgRouting on version 1.02 however, I received &#8220;undefined symbols&#8221; when linking the librouting.dylib</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Linking CXX shared library ../../lib/librouting.dylib
Undefined symbols:
  &quot;_errcode&quot;, referenced from:
      _shortest_path in dijkstra.o
      _shortest_path_astar in astar.o
      _shortest_path_shooting_star in shooting_star.o</pre></div></div>

<p>For the complete error details, see <a href='/wordpress/wp-content/uploads/2008/05/pgrouting_problem.txt'>pgrouting_problem.txt</a></p>
<p>17. Thanks to www.kyngchaos.com, we can install <a href="http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg">http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg</a> binary from http://www.kyngchaos.com/wiki/software:postgres</p>
<p>18. Now we can load the pgRouting functions to our template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp_wrappers.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/05/installing-postgres83-postgis133-pgrouting-on-macosx-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PostGres8.3 and Postgis1.3.2 on Windows</title>
		<link>/wordpress/2008/03/installing-postgres83-and-postgis-on-windows/</link>
		<comments>/wordpress/2008/03/installing-postgres83-and-postgis-on-windows/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 00:15:05 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/index.php/2008/03/04/installing-postgres83-and-postgis-on-windows/</guid>
		<description><![CDATA[It seems very nice for the new PostGres8.3 installer to bundle up third party libraries installation with the new admin pack feature. Using this feature, you can install PostGis, nPgsql, etc. The installation was painless and smooth this time. I have to backup all my data though using pg_dump. To lessen the learning curve on [...]]]></description>
			<content:encoded><![CDATA[<p>It seems very nice for the new PostGres8.3 installer to bundle up third party libraries installation with the new <em>admin pack</em> feature. Using this feature, you can install PostGis, nPgsql, etc. The installation was painless and smooth this time. I have to backup all my data though using pg_dump.</p>
<p>To lessen the learning curve on installing PostGres + PostGis together, I made a <a href="http://www.gisnotes.com/wordpress/training/postgres-tut1.html" title="postgres-tut1.html">short flash movie</a> here.  There is no audio in the tutorial. The idea was to introduce PostGres to my Chinese staff.  I have to remove PostGreSQL 8.2 first before installing 8.3.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/03/installing-postgres83-and-postgis-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>CF-Postgres ODBC Connection</title>
		<link>/wordpress/2007/07/cf-postgres-odbc-connection/</link>
		<comments>/wordpress/2007/07/cf-postgres-odbc-connection/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 13:04:26 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>
		<category><![CDATA[cf]]></category>

		<guid isPermaLink="false">/wordpress/?p=75</guid>
		<description><![CDATA[Note: You need the postgresql-8.2-504.jdbc3.jar. Technote From Adobe]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/cf_postgres.png" title="CF-Postgres ODBC"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/cf_postgres.png" alt="CF-Postgres ODBC" /></a></p>
<p>Note: You need the postgresql-8.2-504.jdbc3.jar.</p>
<p><a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_18338&amp;sliceId=1">Technote From Adobe</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/cf-postgres-odbc-connection/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>Buffering points</title>
		<link>/wordpress/2007/07/buffering-points/</link>
		<comments>/wordpress/2007/07/buffering-points/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 16:52:43 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=71</guid>
		<description><![CDATA[Here is a post in buffering points and combining them using GeomUnion. Works in GEOS3.0.0, so note that your POSTGIS installation in windows contains a lower version of GEOS. DROP FUNCTION combineGeometry&#40;&#41;; &#160; CREATE FUNCTION combineGeometry&#40;&#41; RETURNS Void AS' DECLARE --define datatypes here updateCount integer DEFAULT 0; geom_record RECORD; geom_current RECORD; geom_final RECORD; mytotal integer [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a post in buffering points and combining them using GeomUnion. Works in GEOS3.0.0, so note that your POSTGIS installation in windows contains a lower version of GEOS.</p>
<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/buffer_points.png" title="Buffered Points"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/buffer_points.thumbnail.png" alt="Buffered Points" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> combineGeometry<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> combineGeometry<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS Void <span style="color: #993333; font-weight: bold;">AS</span><span style="color: #ff0000;">'
DECLARE
	--define datatypes here
	updateCount integer DEFAULT 0;
	geom_record RECORD;
	geom_current RECORD;
	geom_final RECORD;
	mytotal integer DEFAULT 0;
&nbsp;
BEGIN
&nbsp;
	--get the total
	SELECT count(*) as mycount FROM busstopv1_buffer_20_temp INTO mytotal;
&nbsp;
	-- 1,2,3,4,5
	FOR geom_record IN SELECT * FROM busstopv1_buffer_20 LOOP
&nbsp;
		--get the current geom of the record
		SELECT *
		FROM 		busstopv1_buffer_20_temp b
		WHERE 		b.gid = geom_record.gid INTO geom_current;
&nbsp;
		RAISE INFO '</span><span style="color: #ff0000;">'RECORD GID: %'</span><span style="color: #ff0000;">', geom_record.gid;
		RAISE INFO '</span><span style="color: #ff0000;">'===========TOTAL COUNT: %=============='</span><span style="color: #ff0000;">', mytotal;
&nbsp;
		--find the intersection of the current geom with other spatial entities
		--and loop through that. For each loop, update the geom.
&nbsp;
		IF geom_current IS NULL THEN
			CONTINUE;
		END IF;
		FOR geom_final IN
			SELECT GeomUnion(b0.the_geom, geom_current.the_geom ) AS geom_current_union, b0.gid
			FROM busstopv1_buffer_20_temp b0
			WHERE b0.gid &amp;lt;&amp;gt; geom_current.gid
			AND Intersects(b0.the_geom, geom_current.the_geom) = '</span><span style="color: #ff0000;">'t'</span><span style="color: #ff0000;">'
			ORDER BY gid ASC LOOP
&nbsp;
			--geom_current.gid = geom_record.gid
			UPDATE busstopv1_buffer_20_temp
			SET the_geom = GeomUnion( the_geom, geom_final.geom_current_union )
			WHERE gid = geom_current.gid;
			RAISE INFO '</span><span style="color: #ff0000;">'UPDATED GID:%'</span><span style="color: #ff0000;">', geom_current.gid;
&nbsp;
			DELETE FROM busstopv1_buffer_20_temp WHERE gid = geom_final.gid;
			RAISE INFO '</span><span style="color: #ff0000;">'DELETED GID:%'</span><span style="color: #ff0000;">', geom_final.gid;
&nbsp;
			mytotal = mytotal - 1;
&nbsp;
		END LOOP;
&nbsp;
	END LOOP;
END;'</span>
<span style="color: #993333; font-weight: bold;">LANGUAGE</span> plpgsql;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> combineGeometry<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Next step.. trying out <a href="http://www.cgal.org/">CGAL.</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/buffering-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buffering Lines</title>
		<link>/wordpress/2007/07/buffering-lines/</link>
		<comments>/wordpress/2007/07/buffering-lines/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 15:15:24 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=69</guid>
		<description><![CDATA[Here is a sample script in using buffer in Postgis. I buffered the line by 10 and 20 meters. Take note that I have to transform the geometry to the corresponding EPSG, so I could specify &#8220;meters&#8221;. DROP TABLE busline_buffer1; DELETE FROM geometry_columns WHERE f_table_name = 'busline_buffer1'; &#160; CREATE TABLE busline_buffer1&#40; gid serial, CONSTRAINT pk_buffer1 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/buffer_example.png" title="Line Buffering in Postgis"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/07/buffer_example.png" alt="Line Buffering in Postgis" /></a></p>
<p>Here is a sample script in using buffer in Postgis. I buffered the line by 10 and 20 meters. Take note that I have to transform the geometry to the corresponding EPSG, so I could specify &#8220;meters&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> busline_buffer1;
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> geometry_columns <span style="color: #993333; font-weight: bold;">WHERE</span> f_table_name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'busline_buffer1'</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> busline_buffer1<span style="color: #66cc66;">&#40;</span> gid serial<span style="color: #66cc66;">,</span> CONSTRAINT pk_buffer1 <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>gid<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span>  AddGeometryColumn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'public'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'busline_buffer1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'the_geom'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'POLYGON'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">//</span> This would display what the output of the geometry <span style="color: #993333; font-weight: bold;">IS</span><span style="color: #66cc66;">...</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> AsText<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span> ST_BUFFER<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span>v1<span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">32650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> buslinev1 v1;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> busline_buffer1<span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> transform<span style="color: #66cc66;">&#40;</span> ST_BUFFER<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span>v1<span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">32650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> buslinev1 v1;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> gid<span style="color: #66cc66;">,</span> AsText<span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> busline_buffer1;
<span style="color: #66cc66;">========================================</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> busline_buffer2;
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> geometry_columns <span style="color: #993333; font-weight: bold;">WHERE</span> f_table_name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'busline_buffer2'</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> busline_buffer2<span style="color: #66cc66;">&#40;</span> gid serial<span style="color: #66cc66;">,</span> CONSTRAINT pk_buffer2 <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>gid<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span>  AddGeometryColumn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'public'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'busline_buffer2'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'the_geom'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'POLYGON'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> AsText<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span> ST_BUFFER<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span>v1<span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">32650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> buslinev1 v1;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> busline_buffer2<span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> transform<span style="color: #66cc66;">&#40;</span> ST_BUFFER<span style="color: #66cc66;">&#40;</span> transform<span style="color: #66cc66;">&#40;</span>v1<span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">32650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> buslinev1 v1;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> gid<span style="color: #66cc66;">,</span> AsText<span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> busline_buffer2;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/buffering-lines/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

