I've not been able to resolve this issue yet, but this post is just an
update as to different things I've tried that haven't worked ;)

 

Firstly, just to confirm my Mapnik and OGR installations are working
correctly, I created the most simple of CSV files, containing a single
Polygon:

ID,WKT

1,"POLYGON((0 52, 4 52, 4 60, 0 60, 0 52))"

 

Then I created an OGR VRT file to point at this CSV file, as follows:

<OGRVRTDataSource>

  <OGRVRTLayer name="test">

    <SrcDataSource>test.csv</SrcDataSource> 

    <LayerSRS>WGS84</LayerSRS>

    <GeometryType>wkbPolygon</GeometryType>

    <GeometryField encoding="WKT" field="WKT"/>

  </OGRVRTLayer>

</OGRVRTDataSource>

 

Tested the CSV file using OGRINFO:

ogrinfo -al csv.vrt

INFO: Open of `csv.vrt'

      using driver `VRT' successful.

Layer name: test

Geometry: Polygon

Feature Count: 1

Extent: (0.000000, 52.000000) - (4.000000, 60.000000)

Layer SRS WKT:

GEOGCS["WGS 84",

    DATUM["WGS_1984",

        SPHEROID["WGS 84",6378137,298.257223563,

            AUTHORITY["EPSG","7030"]],

        TOWGS84[0,0,0,0,0,0,0],

        AUTHORITY["EPSG","6326"]],

    PRIMEM["Greenwich",0,

        AUTHORITY["EPSG","8901"]],

    UNIT["degree",0.0174532925199433,

        AUTHORITY["EPSG","9108"]],

    AUTHORITY["EPSG","4326"]]

ID: String (0.0)

WKT: String (0.0)

OGRFeature(test):1

  ID (String) = 1

  WKT (String) = POLYGON((0 52, 4 52, 4 60, 0 60, 0 52))

  POLYGON ((0 52,4 52,4 60,0 60,0 52))

 

And successfully plotted the polygon feature from this VRT using Mapnik:

import sys

import mapnik

m = mapnik.Map(600,800,"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs")

m.background = mapnik.Color('blue')

# Create the layer from VRT

test_lyr = mapnik.Layer('Test layer')

test_lyr.srs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

test_lyr.datasource = mapnik.Ogr(file="csv.vrt", layer="test")

# Define a simple fill

test_style = mapnik.Style()

test_rule = mapnik.Rule()

test_rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('red')))

test_style.rules.append(test_rule)

# Apply the style

m.append_style('test-style', test_style)

test_lyr.styles.append('test-style')

m.layers.append(test_lyr)

# Set the initial extent of the map

m.zoom_to_box(mapnik.Envelope(-1252344,6261721,626172,8140237)) 

# Render and save the map image

im = mapnik.Image(m.width,m.height)

mapnik.render(m, im)

im.save('demo.png', 'png') # true-colour RGBA

 

 

Having established that's all working, I now tried exactly the same polygon,
but selected via a SQL Server query. Note that I'm doing this all in a
simple inline query so there's no dependency on any tables existing - it
just requires a successful connection to SQL Server. I made no other changes
to the VRT file:

<OGRVRTDataSource>

  <OGRVRTLayer name="test">

 
<SrcDataSource>MSSQL:server=zangief\DENALICTP3;database=TempDB;</SrcDataSour
ce>

    <SrcSQL>SELECT geography::STPolyFromText('POLYGON((0 52, 4 52, 4 60, 0
60, 0 52))', 4326).STAsText() AS WKT</SrcSQL>

    <LayerSRS>EPSG:4326</LayerSRS>

    <GeometryType>wkbPolygon</GeometryType>

    <GeometryField encoding="WKT" field="WKT"/>

  </OGRVRTLayer>

</OGRVRTDataSource>

 

OGRINFO reports *exactly the same* as it did using the CSV source:

ogrinfo -al mssql.vrt

INFO: Open of `mssql.vrt'

      using driver `VRT' successful.

Layer name: test

Geometry: Polygon

Feature Count: 1

Extent: (0.000000, 52.000000) - (4.000000, 60.000000)

Layer SRS WKT:

GEOGCS["WGS 84",

    DATUM["WGS_1984",

        SPHEROID["WGS 84",6378137,298.257223563,

            AUTHORITY["EPSG","7030"]],

        AUTHORITY["EPSG","6326"]],

    PRIMEM["Greenwich",0,

        AUTHORITY["EPSG","8901"]],

    UNIT["degree",0.0174532925199433,

        AUTHORITY["EPSG","9122"]],

    AUTHORITY["EPSG","4326"]]

ID: Integer (10.0)

WKT: String (0.0)

OGRFeature(test):0

  ID (Integer) = 1

  WKT (String) = POLYGON ((0 52, 4 52, 4 60, 0 60, 0 52))

  POLYGON ((0 52,4 52,4 60,0 60,0 52))

 

However, Mapnik fails with the error described previously - "Failed to open
datasource". 

I ought to mention that both OGR2OGR and QGIS do load this VRT without any
problems, so I'm confident that the connection string and query are correct.

 

I also tried changing the VRT to connect to SQL Server via ODBC:

<OGRVRTDataSource>

  <OGRVRTLayer name="test">

    <SrcDataSource>ODBC:Driver={SQL
Server};Server=zangief\DENALICTP3;Database=tempdb;UID=;PWD=</SrcDataSource> 

    <SrcSQL>SELECT 1 AS ID, geography::STPolyFromText('POLYGON((0 52, 4 52,
4 60, 0 60, 0 52))', 4326).STAsText() AS WKT</SrcSQL>

    <LayerSRS>EPSG:4326</LayerSRS>

    <GeometryType>wkbPolygon</GeometryType>

    <GeometryField encoding="WKT" field="WKT"/>

  </OGRVRTLayer>

</OGRVRTDataSource>

 

Exactly the same result as previously - OGR2OGR and QGIS will load the
features from this VRT without any problem, but Mapnik won't. So I'm
inclined to agree that this is a problem somewhere in the Mapnik OGR plugin,
which for some reason is affecting a SQL Server connection but perhaps not
other OGR sources (including CSV). I'm not sure what the significance of
opening a datasource in SHARED mode is, so I don't know if that's the likely
cause or not. 

 

I appreciate that there probably aren't that many Mapnik users who have
tried to use SQL Server (in fact, from looking around the internet, it
appears that I might be the only one!) or, in fact, whether anybody has been
successful in doing so yet, but native SQL Server support would be a massive
bonus for people trying to use Mapnik on windows, where SQL Server Express
is generally a more prevalent DB than PostGIS, say.

 

Is there anything else I can do to help identify/fix the root cause of this
problem?

 

Thanks,

 

a.

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to