I'm trying to link a GeoServer application to a SQL Server Spatial Database. The spatial data has been saved as Geography, but GeoServer can read only Geometry type.

So I'm using the following script to create an additional field of Geometry type:

UPDATE [dbo].[GeoBoundaries]
SET [GeoCoords] = geometry::STGeomFromWKB([SimplifiedCoords].STAsBinary(),[SimplifiedCoords].STSrid).MakeValid()

The issue is with Russian Federation that has polygons crossing the 180 meridian.

The Geography data type is correctly shown:

enter image description here

instead, the Geometry data type has issues displaying the crossing meridian polygons: enter image description here

Obviously Geoserver is not able to read the GeoCoords field even if it is a geometry field and raise an error:

java.lang.RuntimeException: java.io.IOException: Error occured calculating bounds for GeoBoundaries
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry": 

How can I correctly convert geography to geometry to be used by Geoserver?

  • You could enhance the SQLDialect class that GeoServer uses to handle Geography types - there is example code in the PostGIS Dialect (or just use PostGIS). – Ian Turton Aug 2 at 15:05
  • I can't move the whole DB infrastructure to another DBMS, it's crazy!! What do you mean by enhance SQLDialect class? – Giox Aug 2 at 15:11
  • SQLServerDialect is the class which allows GeoServer to talk the kind of SQL that SQLServer talks. It doesn't seem to know about Geography, the way for example PostGIS does so you would need to add some code to it, or pay one of the GeoTools devs to do it. But SQLServer is less popular than say a FOSS DB like PostGIS. – Ian Turton Aug 2 at 15:18
  • @IanTurton thanks for the suggestion but in any case I'd like to solve the issue inside SQL Server, and convert in the right way the Geography to Geometry data type. Once done this everything is fixed and fully working and compatible – Giox Aug 2 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.