MapServer and SQL Server 2008 Plug-in


2009-12-18 11:52




geodatabases, mapserver, sql server 2008





The SQL Server 2008 plugin for MapServeris 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.
 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.

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 forversion 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.



1. Noureddine Farah **


Glad that you were able to get the fixes for the issues encountered. One quick comment about the error and it fixe in MI Pro 10.0.1 maintenance release. In the release notes, while one can argue that the description might not be very explicit on the error and its message, here is the reference to the issue (in the release notes):

C15797 When ArcGIS® 9.2 or 9.3 is installed on the machine MapInfo

Professional closes unexpectedly when | opening a Universal Data File. | Resolution: Issue is resolved. | “


2. geographika **

Thanks for taking the time to read the post and reply. Just looked

through the release notes, and the issue is right at the top of the list. | There’s nothing on Google about the error (until this post!), so it was hard to narrow down the issue. | The SQL Server data seems to be working perfectly so far (including editing), and its nice to see MapInfo take an interest in their users.

Add Comment