none
Spatial Data Query.... Multiple Intersects... RRS feed

  • Question

  • Have the following code that works intersecting with 1 line...... How do I add a second line to the intersects? In this code I hav sampleLine3. I would like to add sampleLine2 and sampleLine1......Or do I need a new separate query?

               //Load the SpatialDataServices module.
    
                //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";
    
    
    
                Microsoft.Maps.loadModule(['Microsoft.Maps.SpatialDataService'], function () {
    
                    //Create a query to get data that intersects the polygon.
                    var queryOptions = {
                        queryUrl: sdsDataSourceUrl,
                        top: 10,
                        spatialFilter: {
                            spatialFilterType: 'intersects',
                            intersects: sampleLine3 
                        }
                    };
    Thanks in Advance.

     
    Monday, December 11, 2017 7:41 PM

Answers

  • Ok, looks like only individual shapes are currently supported, not arrays, which is odd. To work around this, you can convert the shapes into well known text directly like this:

     var queryOptions = {
      queryUrl: sdsDataSourceUrl,
      top: 25,
      spatialFilter: {
       spatialFilterType: 'intersects',
       intersects: Microsoft.Maps.WellKnownText.write([sampleLine3,sampleLine1])
      }
     };

    I'll add a feature request to support an array of shapes directly.


    [Blog] [twitter] [LinkedIn]

    • Marked as answer by DDL19 Tuesday, December 12, 2017 12:47 PM
    Tuesday, December 12, 2017 2:27 AM
  • Your event handler isn't closed. You should see a generic java script error in the browser console. Add }) to the end of that code block.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, December 12, 2017 2:54 PM
    • Marked as answer by DDL19 Tuesday, December 12, 2017 8:22 PM
    Tuesday, December 12, 2017 2:54 PM

All replies

  • Pass the lines in via an array. For example: 

    intersects: [sampleLine1, sampleLine2]

    This simply is passed into the WellKnowText module which will generate a MultiLineString object out of it which will be used in the query.


    [Blog] [twitter] [LinkedIn]

    Monday, December 11, 2017 9:40 PM
  • This code did not work....

             var sampleLine1 = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(29.01, -81.9), new Microsoft.Maps.Location(29.56587, -81.13541)],
                { strokeColor: 'red', strokeThickness: 3, strokeDashArray: [1, 2, 1, 2] });
                map.entities.push(sampleLine1);
    
             var sampleLine2 = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(28.91, -82.04), new Microsoft.Maps.Location(29.47746, -81.28738)],
                { strokeColor: 'red', strokeThickness: 3, strokeDashArray: [1, 2, 1, 2] });
                map.entities.push(sampleLine2);
    
            var sampleLine3 = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(26.67, -81.55), new Microsoft.Maps.Location(27.10157, -80.70543)],
                { strokeColor: 'red', strokeThickness: 3, strokeDashArray: [1, 2, 1, 2] });
                map.entities.push(sampleLine3);
    
    
              //Load the SpatialDataServices module.
    
                //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";
    
                Microsoft.Maps.loadModule(['Microsoft.Maps.SpatialDataService'], function () {
    
                    //Create a query to get data that intersects the polygon.
                    var queryOptions = {
                        queryUrl: sdsDataSourceUrl,
                        top: 25,
                        spatialFilter: {
                            spatialFilterType: 'intersects',
                            intersects: [sampleLine3,sampleLine1] 
                        }
                    };

    Works fine with just one line submitted.....

    Tuesday, December 12, 2017 12:12 AM
  • Ok, looks like only individual shapes are currently supported, not arrays, which is odd. To work around this, you can convert the shapes into well known text directly like this:

     var queryOptions = {
      queryUrl: sdsDataSourceUrl,
      top: 25,
      spatialFilter: {
       spatialFilterType: 'intersects',
       intersects: Microsoft.Maps.WellKnownText.write([sampleLine3,sampleLine1])
      }
     };

    I'll add a feature request to support an array of shapes directly.


    [Blog] [twitter] [LinkedIn]

    • Marked as answer by DDL19 Tuesday, December 12, 2017 12:47 PM
    Tuesday, December 12, 2017 2:27 AM
  • That works fine Ricky. Thanks! Next speed bump.....

    I have 3 lines.... 3 Intersections and added 3 pushpins... all works fine... I simply add this click event handler and the map no longer displays..... What is going on here?

                        Microsoft.Maps.Events.addHandler(pushpin3, 'click', function () {
                        infobox.setOptions({ visible: true });
    I have moved this code block around in my code and that does not seem to change the behavior .... or lack of it.....

    Tuesday, December 12, 2017 1:35 PM
  • Your event handler isn't closed. You should see a generic java script error in the browser console. Add }) to the end of that code block.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, December 12, 2017 2:54 PM
    • Marked as answer by DDL19 Tuesday, December 12, 2017 8:22 PM
    Tuesday, December 12, 2017 2:54 PM
  • sorry for brain dead response..... Thanks!
    Tuesday, December 12, 2017 8:22 PM