MapServer and SQL Server 2008 Plug-in

The SQL Server 2008 plugin for MapServer is a “native driver modeled on the PostGIS driver to mapserversupport SQL Server 2008’s newly added spatial capabilities.” It works fine for displaying data as WMS layers in OpenLayers however I ran into all sorts of problems when trying to use the GetFeatureInfo WMS query.

With MapServer 5.2.1  (installed using MapServer for Windows – MS4W v2.3.1) no error message was returned, however neither was any data . I initially thought this was due to the following bug in the plugin, which was reported to have been fixed for MapServer 5.4.

So I tried downloading MS4W v3.0 Beta 7, which included MapServer 5.4, and upgraded my installation. The WMS queries still failed but at least this time I got an error message:

msMSSQL2008LayerGetShape(): Query error. Error executing MSSQL2008 SQL statement:
SELECT convert(varchar(20), FID) from SEI_MyTable WHERE
GEOM.STIntersects(Geometry::STGeomFromText('POLYGON((343410.447904052 262585.540545139,
343410.447904052 262585.540545139,343410.447904052 262585.540545139,343410.447904052
262585.540545139,343410.447904052 262585.540545139))',0)) = 1

-[Microsoft][ODBC SQL Server Driver][SQL Server]A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":
System.FormatException: 24305: The Polygon input is not valid because the ring does not have enough distinct points. Each ring of a polygon must contain at least three distinct points.
System.FormatException:
 at Microsoft.SqlServer.Types.Validator.Execute(Transition transition)
 at Microsoft.SqlServer.Types.ForwardingGeoDataSink.EndFigure()
 at Microsoft.SqlServer.Types.OpenGisWktReader.ParseLineStringText()
 at Microsoft.SqlServer.Types.OpenGisWktReader.ParsePolygonText()
 at Microsoft.SqlServer.Types.OpenGisWktReader.ParseTaggedText(OpenGisType type)
 at Microsoft.SqlServer.Types.OpenGisWktReader.Read(OpenGisType type, Int32 srid)
 at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid)

It appears that no matter what values I passed into my bounding box parameter, a spatial query was made using a bounding box / polygon consisting of 4 identical points, hence the error from SQL Server. I tried a bounding box set to the full extent of my data but still no luck – the bbox values made no different at all.

http://geographika.azurewebsites.net/cgi-bin/mapserv.exe?map=/ms4w/apps/sei/test.map&service=WMS&
version=1.1.1&request=GetFeatureInfo&layers=test&query_layers=test&styles=,
&bbox=0,0,500000,500000&srs=EPSG%3A29902&feature_count=10&x=710&y=132&height=253&
width=991&info_format=text%2Fhtml

This useful site automatically compiles the most recent MapServer versions into binaries available or download, however the most recent versions of the plug-in still fail.

I found a post that had a similar issue using CGI scripts rather than WMS calls. A suggestion was to use the TOLERANCE parameter for a layer, to increase the bounding box size, however this makes no difference to a WMS GetFeatureInfo query.

The MapServer 5.4 sourcecode for the plugin can be seen here, however it is in C..and I can’t seem to find where the rectangle object is passed in or created. It appears Tamas Szekeres has taken over updates to this plugin so I’ll try and contact him to make him aware of this issue. I’m not sure how many people actually use SQL Server 2008 and MapServer, but there is at least one other person!

Update (March 2010): It appears this issue has now been fixed for version 5.6 by Tamas Szekeres.

– Changed the query shape to POINT instead of POLYGON when the area of the query shape is zero (causing a failure at the server).

More details on the issue can be found in the MapServer-dev mailing list.



3 views shared on this article. Join in...

  1. Afroz Kannancheri says:

    Hi,
    I m also in a process of migrating my application to mssql2008 by moving all shape files to database.
    Got stuck with the same error while using the GetfeatureInfo. Please let me know if you found a workaround.

    Very happy to see your post as I was checking if there was something wrong with my code.

    Thanks and regards

  2. geographika says:

    @Afroz Kannancheri
    Thanks for chasing that up. I’ll be testing with the WMS again soon. Meanwhile I implemented my own spatial query handler using .NET and stored procedures.

  3. Hi, its good piece of writing about media print, we all understand media is a enormous source of data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment

You may use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>