[mapserver-users] OGR and MSSQL non-specific error

Anzel, Phil - NRCS, Fort Collins, CO Phil.Anzel at ftc.usda.gov
Sun Feb 26 14:36:25 PST 2012


Hi, Tamas,

Thanks for getting back to me so quickly. It works (with a pair of follow-up questions)!

Here’s what I used:

    CONNECTIONTYPE OGR
    CONNECTION 'MSSQL:server=xxx;database=Navigation;uid=yyy;pwd=zzz’
    PROCESSING 'CLOSE_CONNECTION=DEFER'
    DATA "select ShapeGeometry, State_Abbr from NAV_STATE
          where ShapeGeometry.STIntersects(
            geometry::STGeomFromText(
              'POLYGON((-126 22.2048396890436, -66 22.2048396890436,
                        -66 51.1696997878088, -126 51.1696997878088,
                        -126 22.2048396890436))',4269)) = 1"
    LABELITEM 'State_Abbr'

1. Note that I omitted the “tables=…” as it appears that naming a specific table would interfere with connection pooling if I’m using many layers drawing data from different tables. Do I understand the role of the “tables=…” incorrectly?

2. I added the explicit spatial filtering (STIntersects…). Is there a better way to do this?

Thanks again,

- Phil

From: Tamas Szekeres [mailto:szekerest at gmail.com]
Sent: Sunday, February 26, 2012 12:25 PM
To: Anzel, Phil - NRCS, Fort Collins, CO
Cc: mapserver-users at lists.osgeo.org
Subject: Re: [mapserver-users] OGR and MSSQL non-specific error

Phil,

You should not specify the data section in the OGR layer definition unless you would define and sql select statement preceding with the 'where' keyword. The terms 'using unique' and 'using srid' are not meaningful for the ogr driver these parameters are automatically retrieved from the geometry_columns metadata table. You should however specify the table name (and probably the geometry column name) in the connection string, something like:

 CONNECTION ' MSSQL:server=xxx;database=;uid=xxx;pwd=xxx;tables=NAV_STATE'

or

 CONNECTION ' MSSQL:server=xxx;database=;uid=xxx;pwd=xxx;tables=NAV_STATE(ShapeGeometry)'


The difference in performance may be investigated by reading large number of shapes at a given scale.
I'm also planning to improve the mapserver mssql plugin to read native SqlGeometries, but I'm now working on a QGIS mssql driver right now.

Best regards,

Tamas


2012/2/26 Anzel, Phil - NRCS, Fort Collins, CO <Phil.Anzel at ftc.usda.gov<mailto:Phil.Anzel at ftc.usda.gov>>
All,

I'm a bit confused: does MapServer 6.0.1 and OGR "officially" work with Sql Server 2008? I can see how use of the native SqlGeometry objects might be a bonus and would like to put it to the test.

MSSQL access via the plugin works with this LAYER:
 LAYER
   NAME 'States'  STATUS ON
   PROJECTION 'proj=latlong' 'ellps=GRS80' 'datum=NAD83' END
   CONNECTIONTYPE PLUGIN
   PLUGIN ...\msplugin_mssql2008.dll'
   CONNECTION 'server=xxx;database=;uid=xxx;pwd=xxx'
   PROCESSING 'CLOSE_CONNECTION=DEFER'
   DATA "ShapeGeometry from NAV_STATE as base_table using unique OBJECTID using SRID=4269"
   TYPE POLYGON
   CLASS STYLE OUTLINECOLOR '#e1dd00' WIDTH 2 END END
 END

This variant, changed to use OGR, fails:
 LAYER
   NAME 'States'  STATUS ON
   PROJECTION 'proj=latlong' 'ellps=GRS80' 'datum=NAD83' END
   CONNECTIONTYPE OGR
   CONNECTION 'MSSQL:server=xxx;database=;uid=xxx;pwd=xxx'
   PROCESSING 'CLOSE_CONNECTION=DEFER'
   DATA "ShapeGeometry from NAV_STATE as base_table using unique OBJECTID using SRID=4269"
   TYPE POLYGON
   CLASS STYLE OUTLINECOLOR '#e1dd00' WIDTH 2 END END
 END

Using shp2img (from MapServer 6.0.1 distribution for Win32/VS2010 retrieved 2011-07-18) with "-all_debug 5" yields:
 msOGRFileOpen(): OGR error.
 GetLayer(ShapeGeometry from NAV_STATE as base_table using unique OBJECTID using SRID=4269)
 failed for OGR connection `MSSQL:server=xxx;database=xxx;uid=xxx;pwd=xxx'.
There is no further detail as to the failure.

By way of reference,
1. In mapserver-users Digest, Vol 49, Issue 58, Tamas Szekeres states "BTW: With the current approach, connecting to mssql via OGR provides better performance than using the mssql plugin."
2. Tamas also indicates that OGR can talk to MSSQL in "[gdal-dev] OGR MS SQL Spatial driver has been added", http://www.osgeo.org/pipermail/gdal-dev/2010-September/026055.html.
3. MapServer documentation at http://mapserver.org/input/vector/ogr.html does not list MSSQL as a data provider.
4. MapServer documentation at http://mapserver.org/input/vector/mssql.html still shows use of the msplugin_mssql2008.dll plugin.

I must also wonder: has a measurable improvement been demonstrated by eliminating the plugin and going to the direct OGR to MSSQL connection?

Yours in confusion,

- Phil Anzel
      Contractor for USDA/NRCS
      ITC Web Soil Survey Team Member

This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

_______________________________________________
mapserver-users mailing list
mapserver-users at lists.osgeo.org<mailto:mapserver-users at lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/mapserver-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20120226/e23c28e7/attachment.htm>


More information about the MapServer-users mailing list