ERROR 1: Failed to open datasource `PG:host=127.0.0.1 user=postgres dbname=gis password=passw0rd tables=parcels_20140829_pmerc'.
I believe the VRT is fine, because it not only works with ogrinfo directly, but as stated above, the OGR-related code in the Python file also works.
While I'm pretty confident the VRT isn't the issue, for those who might ask, the VRT I tried looks like this. I know there's some redundant stuff in there, but that's because I thought maybe Mapnik was looking for something specific, so I was adding any node I could think of which might be relevant:
<OGRVRTDataSource> <OGRVRTLayer name="parcels_20140829_pmerc"> <SrcDataSource>PG:host=127.0.0.1 user=postgres dbname=gis password=passw0rd tables=parcels_20140829_pmerc</SrcDataSource> <SrcLayer>parcels_20140829_pmerc</SrcLayer> <LayerSRS>EPSG:3857</LayerSRS> <SrcSQL>SELECT ST_AsBinary(wkb_geometry) as geomm, tms, owner_name, the_wkt FROM parcels_20140829_pmerc</SrcSQL> <GeometryField encoding="WKB" field="geomm"></GeometryField> <Field name="tms" src="tms" type="String"/> <Field name="owner_name" src="owner_name" type="String"/> <Field name="the_wkt" src="the_wkt" type="String"/> </OGRVRTLayer> </OGRVRTDataSource>
I eventually got past the problem by passing in an OGR PostgreSQL connection string, parsing over that, and then pushing the values into a
mapnik.PostGIS() constructor. Sure, this solves my immediate problem, but it's not quite as generic/universal as I would like.
So I'm wondering, since I can't get Mapnik to like my VRT, if it's possible to reference the existing
ogr.Open() datasource object from Mapnik and avoid having to use something like
mapnik.Ogr() in the first place.
To get this idea, this is kind of how I imagine it..
import mapnik import ogr # create_utfgrids.py uses shapefiles, hence "shppath". # But for this exercise it represents a path to a VRT. ds = ogr.Open(shppath) # A bunch of OGR stuff here. # This is where I want the magic to happen, # pushing the OGR dataset into Mapnik.. ds = mapnik.Ogr(ds) # And then Mapnik stuff follows.