locked
How to create a polygon from Geography data type to a polygon on Bing Maps C# RRS feed

  • Question

  • Hi , I am very new to the SQL Server Spatial methods

    After reading numerous posts in MSDN forums on how to get a geography data type in SQL Server 2008  to a polygon on Bing Maps .

    I am left very confused , many of the methods suggested add too much functionality .

    I would like to avoid converting my Geography type to WKT or WKB as far as possible.

    Although if doing so is totally impossible , please help me on how to get it to WKT/WKB and back for display in Bing Maps.

    My basic goal is to just fetch all the polygons stored in my geography column from my database and just draw them on the Bing Maps at loading.But i am unable to do this basic thing too as i am being led to solutions that do not address my basic requirements.

    Please help me out

    PS:I am using Bing Maps Silverlight API

     

    Saturday, April 24, 2010 11:04 AM

Answers

  • Hi George,

    We've done something similar, and unfortunately there is no solution (out of the box) such re-using the Microsoft.Sqlserver.Types assembly from SQL Server 2008, for Silverlight (ie the Bing Maps Control) which only uses a subset of the .NET Framework. The problem is that the SQL assembly uses unmanaged code, and requires a port compilation to SL, which is not currently available (yet).

    More info can be found here: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299338

    Now, to get back to your requirements, this does unfortunately require WKB / WKT conversions to either byte[] or string types (if using web services / WCF), and then the complete reconstruction on the client to either linestrings / polygons through XAML. A nice solution perhaps is what Ricky Brundritt did through GDI on the server side which allows you draw 10 000+ geometries server side and only serve a image (with great performance), where Silverlight would fold / struggle performance wise with only 2000+ geometries and become unresponsive on the client.

    A sample can be found here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!1047.entry?sa=822507152

    You still have to implement you own points / linestrings functions / methods since this sample only focuses on polygons, but is certainly in the right direction.

    These are just some ideas.

    Hope this helps.

    Andries

    • Marked as answer by George Walsh Sunday, April 25, 2010 11:07 AM
    Sunday, April 25, 2010 10:47 AM

All replies

  • Hi George,

    We've done something similar, and unfortunately there is no solution (out of the box) such re-using the Microsoft.Sqlserver.Types assembly from SQL Server 2008, for Silverlight (ie the Bing Maps Control) which only uses a subset of the .NET Framework. The problem is that the SQL assembly uses unmanaged code, and requires a port compilation to SL, which is not currently available (yet).

    More info can be found here: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299338

    Now, to get back to your requirements, this does unfortunately require WKB / WKT conversions to either byte[] or string types (if using web services / WCF), and then the complete reconstruction on the client to either linestrings / polygons through XAML. A nice solution perhaps is what Ricky Brundritt did through GDI on the server side which allows you draw 10 000+ geometries server side and only serve a image (with great performance), where Silverlight would fold / struggle performance wise with only 2000+ geometries and become unresponsive on the client.

    A sample can be found here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!1047.entry?sa=822507152

    You still have to implement you own points / linestrings functions / methods since this sample only focuses on polygons, but is certainly in the right direction.

    These are just some ideas.

    Hope this helps.

    Andries

    • Marked as answer by George Walsh Sunday, April 25, 2010 11:07 AM
    Sunday, April 25, 2010 10:47 AM
  • Thanks andreiso i used WKT and then reconstructed SQLGeogarphy from SharpMaps SpatialTools function MakeValidGeographyFromText.

    and then i converted that geography to string using this in the WCF Service

        List<SqlGeography> l = new List<SqlGeography>();
        List<string> s = new List<string>();
        foreach (var result in db.GetPolygon())
        {
          l.Add(Functions.MakeValidGeographyFromText(result.Column1, 4326));
        }
        for (int i = 0; i < l.Count; i++)
          for (int j = 1; j < l.ElementAt(i).STNumPoints(); j++)
          {
            var loc = new Location((double)l.ElementAt(i).Lat, (double)l.ElementAt(i).Long);
            var sb = new StringBuilder();
            sb.Length = 0;
            sb.Append(loc.Latitude + "," + loc.Longitude + ";");
            s.Add(sb.ToString());
          }

    Now i am parsing in the Page.CS which is consuming the WCF Service.

    Thanks for the directions.

    Will post back if i get any issues on doing that.

    Sunday, April 25, 2010 11:07 AM
  • Hi,

    I have the same problem. I want to display my data from sql server 2008 via a wcf service on my bing maps with silverlight.

    I uploaded my Shapes with Shape2SQL...

    Then I created a wcf service which connects to my DB(only read functionallity) . I requested the data with STAsBinary.

    But now i don´t know how to go on.

    How can i parse the data to my mapLayer. I read that i need a WKB Reader?!

    Does anyone have an example with a step by step tutorial or possible code?

    What I need would be:

    1) create wcf service with read, delete update functionallity

    2) how to parse the the binary data

    3)load data to a maplayer

    4)display data on the map (this should be easy when the data is in the layer :-) )

     

    I really hope that you can help me, I am really kind of frustrated .

    THANK YOU !

    best regards Tom

     

    Monday, May 31, 2010 9:25 AM