none
Have a Line. Want to to know what counties it Intersects with RRS feed

  • Question

  • I have a line that is working fine in WPF through rest API. What I would like to do is see which Counties it intersects with. Do I have to upload the County Layer and use SQL Server or is there and easier way? Pretty common layer already in Bing Maps and Google that doesn't change... Looking for best way to proceed. Spatial Data Services are Great!

    Thanks in advance - Dan

    Tuesday, July 4, 2017 4:25 PM

Answers

  • You could upload county data to SQL and do this test there, however, Bing Maps does have county data available through the Bing Spatial Data Services: https://msdn.microsoft.com/en-us/library/mt805047.aspx

    To use this you would need to convert your line object into a Well Known Text LineString and then pass that into the Bing Spatial Data Services as an intersection query. The results will contain well known text from the boundary data which can be converted into MapPolygon's in WPF. I've put together a code sample that does all of this and also provides a useful Well Known Text reader/writer for Bing Maps in WPF: https://code.msdn.microsoft.com/bing/Bing-Maps-WPF-Get-counties-b6bdc314


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, July 5, 2017 7:31 PM
    • Marked as answer by DDL19 Thursday, July 6, 2017 3:00 PM
    Wednesday, July 5, 2017 7:31 PM
  • It returns JSON by default when you add on a query to it. If you hit that URL directly you will likely get an HTML error if you are dropping the URL into a browser. Note that you don't specify your key as part of the URL like you are showing, that is the access id for the data source and shouldn't be changed. Your Bing Maps key gets appended as a query parameter in the URL. The code sample I provided is using a session key it got from the map which is a special Bing Maps key which marks the request as part of a map session and thus makes it non-billable. 

    [Blog] [twitter] [LinkedIn]

    Friday, July 7, 2017 12:53 AM
  • I've updated the WPF sample so that it centers the map over those counties. 

    I've also created a web version of this code sample which uses the Bing Maps V8 web control. You can find this sample here:  http://bingmapsv8samples.azurewebsites.net/#Find%20all%20counties%20that%20intersect%20a%20line

    To see the source code, press the source code button in the top right corner of the sample.


    [Blog] [twitter] [LinkedIn]

    Monday, July 17, 2017 7:15 PM
  • The spatial data services automatically generates a session key from the map for you. No need to manually do this your self like in the wpf control.

    [Blog] [twitter] [LinkedIn]

    Sunday, July 30, 2017 1:04 PM
  • That is the map that is asking for your credentials, not the Bing Spatial Data Services. You need to provide a key to load the map. You can't use a session key to load the map.

    [Blog] [twitter] [LinkedIn]

    Monday, July 31, 2017 1:09 PM

All replies

  • For spatial Intersects ... I use SQL Server.  You don't necessarily have to load the County layer... just need to define a query or sql proceedure to accept the the line, buffer and intersect that with the County table and return the results to your web app.
    Wednesday, July 5, 2017 4:58 PM
  • You could upload county data to SQL and do this test there, however, Bing Maps does have county data available through the Bing Spatial Data Services: https://msdn.microsoft.com/en-us/library/mt805047.aspx

    To use this you would need to convert your line object into a Well Known Text LineString and then pass that into the Bing Spatial Data Services as an intersection query. The results will contain well known text from the boundary data which can be converted into MapPolygon's in WPF. I've put together a code sample that does all of this and also provides a useful Well Known Text reader/writer for Bing Maps in WPF: https://code.msdn.microsoft.com/bing/Bing-Maps-WPF-Get-counties-b6bdc314


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, July 5, 2017 7:31 PM
    • Marked as answer by DDL19 Thursday, July 6, 2017 3:00 PM
    Wednesday, July 5, 2017 7:31 PM
  • Thanks Ricky! you are the best!

    Regards - Dan

    Thursday, July 6, 2017 3:01 PM
  • How to I make this spatial query JSON enabled?

        string USCountiesQueryUrl = "https://spatial.virtualearth.net/REST/v1/data/...key.../USCensus2010_Counties/Counties";

    Thanks in Advance - Dan

    Thursday, July 6, 2017 6:39 PM
  • It returns JSON by default when you add on a query to it. If you hit that URL directly you will likely get an HTML error if you are dropping the URL into a browser. Note that you don't specify your key as part of the URL like you are showing, that is the access id for the data source and shouldn't be changed. Your Bing Maps key gets appended as a query parameter in the URL. The code sample I provided is using a session key it got from the map which is a special Bing Maps key which marks the request as part of a map session and thus makes it non-billable. 

    [Blog] [twitter] [LinkedIn]

    Friday, July 7, 2017 12:53 AM
  • Ricky got the app up and working put it doesn't zoom to the area and is showing the entire world. Were do I set this? Also... would this code work as well in a asp.net app ?

    Thanks - for your help!

    Regards - Dan

    Friday, July 7, 2017 5:22 PM
  • Ricky,

    How is this code Centered on program start? I have some different lines but it goes to your initial view.

    Thanks in Advance - Dan

    Saturday, July 15, 2017 11:37 PM
  • I've updated the WPF sample so that it centers the map over those counties. 

    I've also created a web version of this code sample which uses the Bing Maps V8 web control. You can find this sample here:  http://bingmapsv8samples.azurewebsites.net/#Find%20all%20counties%20that%20intersect%20a%20line

    To see the source code, press the source code button in the top right corner of the sample.


    [Blog] [twitter] [LinkedIn]

    Monday, July 17, 2017 7:15 PM
  • Is there a way to use the Bing Maps session key in the web version to make it non billable like in the WPF version?

    Thanks in advance - Dan

    Saturday, July 29, 2017 3:35 PM
  • The spatial data services automatically generates a session key from the map for you. No need to manually do this your self like in the wpf control.

    [Blog] [twitter] [LinkedIn]

    Sunday, July 30, 2017 1:04 PM
  • Ricky,

    In looking at your web code for this ... It is asking for my key isn't it?

        var map;
    
    
    
        //The query URL to the US County data source in the Bing Spatial Data Services. Documentation: https://msdn.microsoft.com/en-us/library/mt805047.aspx
    
        var sdsDataSourceUrl = "https://spatial.virtualearth.net/REST/v1/data/6c39d83e5812459f914832970618048e/USCensus2010_Counties/Counties";
    
    
    
        function GetMap() {
    
            map = new Microsoft.Maps.Map('#myMap', {
    
                credentials: YourBingMapsKey,
    
                zoom: 1
    
            });

    Sunday, July 30, 2017 5:05 PM
  • That is the map that is asking for your credentials, not the Bing Spatial Data Services. You need to provide a key to load the map. You can't use a session key to load the map.

    [Blog] [twitter] [LinkedIn]

    Monday, July 31, 2017 1:09 PM
  • Thanks for clarifying.
    Monday, July 31, 2017 1:15 PM
  • Can you do a similar intersection with Census tract and or Block group?
    Friday, September 8, 2017 3:41 PM
  • Sure you can, all you need is the data. Simply swap out the data source, or use the same methods against a database of census data.

    [Blog] [twitter] [LinkedIn]

    Friday, September 8, 2017 4:30 PM
  • So there isn't a "canned" one like there is for County??
    Friday, September 8, 2017 4:33 PM
  • Nope. Not at this time.

    [Blog] [twitter] [LinkedIn]

    Saturday, September 9, 2017 3:19 AM
  • I would like to upload the census block group file.  How do I need to format this or better yet is there a line intersection like there is for County? 
    Wednesday, October 18, 2017 2:26 PM
  • The input data can be any of the following formats; ESRI ShapeFile (best option), KML, delimited file (comma, tab, or pipe) or XML. XML and delimited files must have the following file structure: https://msdn.microsoft.com/en-US/library/gg585138.aspx

    [Blog] [twitter] [LinkedIn]

    Wednesday, October 18, 2017 4:30 PM