<?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; GIS</title>
	<atom:link href="http://info.bycycle.org/category/gis/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>
	</channel>
</rss>

