Answered by:

WPF Map Control sql geometry data

Question

I have an existing WPF application that has geometry data stored in sql server 2008 r2. There are also some shape files that are used, but I can import these into SQL server if needed. I would like to use the new WPF Map Control to display the various
geometry data sets as layers that can be turned on and off. What is required to query the SQL database and display the results as a layer in the WPF map control?

Alternatively, if you are using older technology you can use standard SQL tools in WPF to connect directly to the Database and query the data. The Spatial Data can be handled using the Spatial types dll that can be used in .NET.

The Geometry class is nearly identical to the Geography class. There is a couple of ways to do this.

One is to convert the Geometry objects to Geography objects. This can easily be done by first making sure the geometry is valid, then using the binary of the geometry to create a geography object. It might make sense to add a new column to your database
and generate the geography data there.

Another method is to use STX in place of the Long property and STY in place of the Lat property in the code that parses the geometry/geography into a map shape.

Alternatively, if you are using older technology you can use standard SQL tools in WPF to connect directly to the Database and query the data. The Spatial Data can be handled using the Spatial types dll that can be used in .NET.

This example is helpful. I was able to get the sample code to run and now I want to add in some of my data. I ran across my first road block in that my data uses the geometry data type and not the geography data type. So I am working through how to build
a MapPolygon from a SQL Geometry data field.

The Geometry class is nearly identical to the Geography class. There is a couple of ways to do this.

One is to convert the Geometry objects to Geography objects. This can easily be done by first making sure the geometry is valid, then using the binary of the geometry to create a geography object. It might make sense to add a new column to your database
and generate the geography data there.

Another method is to use STX in place of the Long property and STY in place of the Lat property in the code that parses the geometry/geography into a map shape.

The problem statement is:- I have geometry data in SQL Server (AutoCAD DWG file -> ESRI Shape Files via FME -> SQL geometry data using Shape2SQL) and SSRS map control is handling it very nicely but because the control has limitations in Zoomin/Pan
the customer is not convinced and we have to look out for alternates. I tried converting the shape files to geography data type through FME tool by Safe but it can not proceed without knowing the source files coordinate system.

I learned Bing maps APIs but almost all of the samples/examples points to use Geography data rather geometry and that makes sense also. Everything on a map should resolve to some type of lat/long.

We are open for custom development and my question is - is there any out of the box control in WPF/Silverlight stack which can read and draw geometry shapes from SQL server and render them over the web with the interactivity (zooming/panning) such as provided
by Bing Maps control. As per my understanding it should be a canvas control as we want to render a shape rather a map.

The Well Known Text is always the same regardless if the data is a geometry or a geography. Alternatively, if you know the coordinates are using the WGS84 datum, standard used by online maps and GPS devices, then the spatial reference identifier (SRID)
to use in SQL for geography data is 4326.