<?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>byCycle.org &#187; PostgreSQL</title>
	<atom:link href="http://info.bycycle.org/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.bycycle.org</link>
	<description>Get There by Cycle!</description>
	<lastBuildDate>Fri, 02 Sep 2011 07:28:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using PostGIS with SQLAlchemy</title>
		<link>http://info.bycycle.org/2007/01/29/using-postgis-with-sqlalchemy/</link>
		<comments>http://info.bycycle.org/2007/01/29/using-postgis-with-sqlalchemy/#comments</comments>
		<pubDate>Tue, 30 Jan 2007 06:35:17 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[Core]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[PostGIS]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Pylons]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Trip Planner]]></category>

		<guid isPermaLink="false">http://bycycle.org/2007/01/29/using-postgis-with-sqlalchemy/</guid>
		<description><![CDATA[The development version of the Trip Planner uses a Postgres/PostGIS backend (instead of MySQL) SQLAlchemy as the ORM (instead of raw SQL), and PCL for Python geometry types (instead of our own ugly hacked versions). Question: How do you move &#8230; <a href="http://info.bycycle.org/2007/01/29/using-postgis-with-sqlalchemy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The development version of the Trip Planner uses a Postgres/<a title="PostGIS" href="http://postgis.refractions.net/">PostGIS</a> backend (instead of MySQL) <a title="SQLAlchemy" href="http://www.sqlalchemy.org/">SQLAlchemy</a> as the ORM (instead of raw SQL), and <a title="Python Cartographic Library" href="http://trac.gispython.org/projects/PCL">PCL</a> for Python geometry types (instead of our own ugly hacked versions).</p>
<p>Question: How do you move geometries out of Postgres/PostGIS into PCL types via SQLAlchemy and vice versa?</p>
<p>Answer: Create a custom geometry column type.</p>
<p>Here&#8217;s our SQLAlchemy geometry type definition and subtypes (points, linestrings, and multilinestrings; adding other types should be trivial):</p>
<p><a title="Code: Geometry Types" href="http://project.bycycle.org/browser/Core/trunk/bycycle/core/model/data/sqltypes.py">sqltypes.py </a></p>
<p>Look here for an example of using it:</p>
<p><a title="Code: Example Usage of Geometry Types" href="http://project.bycycle.org/browser/Core/trunk/bycycle/core/model/portlandor/__init__.py">tables.py</a></p>
<p>The type is pretty simple. The only tricky part was figuring out how the database stores the geometry. It&#8217;s in ASCII hex, so we use binascii.a2b_hex to get a binary representation and feed that to the PCL fromWKB factory. In the other direction we use binascii.b2a_hex on the WKB representation of the PCL geometry.</p>
<p><em>[8/7/09: Updated links to source code. Note: latest version uses Shapely, not PCL.]</em></p>
]]></content:encoded>
			<wfw:commentRss>http://info.bycycle.org/2007/01/29/using-postgis-with-sqlalchemy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python Cartographic Library (PCL) &#8212; Installing Just the Spatial Package</title>
		<link>http://info.bycycle.org/2006/09/25/python-cartographic-library-pcl-installing-just-the-spatial-package/</link>
		<comments>http://info.bycycle.org/2006/09/25/python-cartographic-library-pcl-installing-just-the-spatial-package/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 08:26:48 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Trip Planner]]></category>

		<guid isPermaLink="false">http://bycycle.org/blog/2006/09/25/python-cartographic-library-pcl-installing-just-the-spatial-package/</guid>
		<description><![CDATA[So let&#8217;s say you need a spatial geometry library for Python. You could write your own; you could also use the PCL. The PCL includes some packages we don&#8217;t need, like one for MapServer rendering. I only installed the minimum &#8230; <a href="http://info.bycycle.org/2006/09/25/python-cartographic-library-pcl-installing-just-the-spatial-package/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So let&#8217;s say you need a spatial geometry library for Python. You <em>could</em> write your own; you could also use the <a title="Python Cartographic Library" href="http://trac.gispython.org/projects/PCL/wiki">PCL</a>. The PCL includes some packages we don&#8217;t need, like one for MapServer rendering. I only installed the minimum needed to get the spatial package working (which I&#8217;ll talk about below).</p>
<p>[Note: "geometry" refers to points, lines, polygons and other geometric forms used to represent real-world objects. Examples: intersection (point), street (line), zip code boundary (polygon).]</p>
<p>I wrote a rudimentary geometry library for the trip planner that&#8217;s been working fine, but now I need to do some more &#8220;advanced&#8221; stuff related to using PostGIS and SQLAlchemy. In particular, I want to convert database values to Python objects and vice versa.</p>
<p>The first part (database to Python) is fairly easy and our current library already does that, but it&#8217;s convoluted in that it gets the database value as well-known text (WKT), parses that, and creates a Python object. From what I can tell, the PCL can go straight from well-known binary (WKB) geometry to Python objects.</p>
<p>The second part (Python to database) is harder because it involves converting a Python object to a binary geometry value. I don&#8217;t know anything about the binary geometry format and I don&#8217;t want to know, and it looks like with the PCL I don&#8217;t need to know.</p>
<p>I&#8217;m assuming PostGIS and PCL will get along together because they both rely on the same libraries, proj4 and geos. We&#8217;ll see.</p>
<p>The installation was fairly straightforward. The PCL includes five sub-packages. We had to install two of them, PCL-Referencing and PCL-Spatial. PCL-Referencing requires proj4. PCL-Spatial requires PCL-Referencing and geos >= 2.2.2. Something in there also requires the OGR library, which is included with GDAL.</p>
<p>The basic steps are, install proj, geos, and gdal, then install PCL-Referencing, and lastly install PCL-Spatial. On Ubuntu 6.06 (Dapper), here&#8217;s what I actually did:</p>
<ul>
<li>Installed proj4 using apt-get</li>
<li>Installed libgdal using apt-get</li>
<li>Installed <a title="GEOS source code at refractions.net" href="http://geos.refractions.net/">geos 2.2.3 from source</a> into /usr/lib. I installed this over a slightly older version of geos installed using apt-get; hopefully that won&#8217;t cause any issues.</li>
<li>Checked out the PCL trunk:<br />
<code>svn co http://svn.gispython.org/gispy/PCL/trunk PCL</code></li>
<li>Installed PCL-Referencing with the usual <code>python setup.py install</code></li>
<li>Installed PCL-Spatial with the usual&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://info.bycycle.org/2006/09/25/python-cartographic-library-pcl-installing-just-the-spatial-package/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Test Driven Development, PostgreSQL, SQLAlchemy</title>
		<link>http://info.bycycle.org/2006/09/13/test-driven-development-postgresql-sqlalchemy/</link>
		<comments>http://info.bycycle.org/2006/09/13/test-driven-development-postgresql-sqlalchemy/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 04:35:51 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[Core]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://bycycle.org/blog/2006/09/13/test-driven-development-postgresql-sqlalchemy/</guid>
		<description><![CDATA[I just tried out some o&#8217; that new-fangle &#8220;Test Driven Development&#8221; (TDD) I&#8217;ve been hearing about. Yeah, it&#8217;s good stuff. At the moment, I&#8217;m in the process of migrating GIS data from MySQL to PostgreSQL so we can take advantage &#8230; <a href="http://info.bycycle.org/2006/09/13/test-driven-development-postgresql-sqlalchemy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just tried out some o&#8217; that new-fangle &#8220;Test Driven Development&#8221; (TDD) I&#8217;ve been hearing about. Yeah, it&#8217;s good stuff.</p>
<p>At the moment, I&#8217;m in the process of migrating GIS data from MySQL to PostgreSQL so we can take advantage of the PostGIS spatial extensions. I&#8217;ve also been making a bunch of related changes (AKA refactoring) in the &#8220;model&#8221;, separating things that never belonged together, and so forth.</p>
<p>I started out by rewriting the MySQL data import script. [Note: basically, the script pulls data out of a flat ESRI shapefile and normalizes it.] This wasn&#8217;t a complete, from-scratch rewrite&#8211;a lot of stuff I just copied over and tweaked a little bit. The biggest changes here were due to using SQLAlchemy instead of typing out SQL queries. I&#8217;ll just note that SQLAlchemy is &#8220;da bomb&#8221; and makes many things easier (once you get the hang of it).</p>
<p>That part was pretty straightforward, and low-level&#8211;I didn&#8217;t get into the ORM aspects of SQLAlchemy at all.</p>
<p>The next step was to modify the routine that creates adjacency matrices for routing. In the end, this was straightforward too. I ended up reusing some stuff from the new import script, which was cool. I refactored a lot during this process, adding some new modules and classes.</p>
<p>[Here's where we get to the TDD aspect.]</p>
<p>So, I was sitting there <em>(here</em> really) thinking, &#8220;Hmmm&#8230; what now?&#8221; I drew some diagrams with the new classes and associations&#8230;. OK, that&#8217;s fun&#8230;. &#8220;Wait, I know. Run the unit tests!&#8221; Doy!</p>
<p>I started with the address normalization service, since the other services both depend on it. The test suite for this service isn&#8217;t as  comprehensive as it probably should be (there are 19 tests),  but it proved to very useful for shaking out a bunch of bugs in all that refactoring. The tests also helped keep me <em>focused</em>, and that aspect might be more important than the bug-squashing aspect (maybe).</p>
<p>Today, address normalization. Tomorrow, geocoding.</p>
]]></content:encoded>
			<wfw:commentRss>http://info.bycycle.org/2006/09/13/test-driven-development-postgresql-sqlalchemy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

