none
Microsoft.Maps.SpatialMath.Geometry.intersection returning unexpected result RRS feed

  • Question

  • Edit: My original post was a little misleading, the problem is now clarified and my sample code has its wkt fixed.

    Microsoft.Maps.SpatialMath.Geometry.intersects and Microsoft.Maps.SpatialMath.Geometry.intersection do not appear to be returning the expected result

    Here is some code to reproduce:

        var poly1 = new Microsoft.Maps.LocationRect(new Microsoft.Maps.Location(40.09520959912304, -74.87733000000001), 0.047206878662109375, 0.014773129229972426);
        var wkt = "POLYGON ((-74.9040734733333 40.0943419237323 0,-74.9040734733333 40.1008590069343 0,-74.904006958 40.100940705 0,-74.9038162229999 40.101314545 0,-74.903648376 40.1015892040001 0,-74.9033737179999 40.1019592300001 0,-74.9030761719999 40.1026382460001 0,-74.9028930659999 40.1030273450001 0,-74.9026412969999 40.1033592230001 0,-74.902427673 40.1036834730001 0,-74.9021911619999 40.103988648 0,-74.9019775389999 40.1041183480001 0,-74.9017028809999 40.104255677 0,-74.9013900749999 40.1043624890002 0,-74.9010696409999 40.1044540420002 0,-74.9006805419999 40.1045570380002 0,-74.900283814 40.1046447760002 0,-74.899803161 40.1048202520001 0,-74.8994216919999 40.104927064 0,-74.8989410399999 40.105033875 0,-74.8983535759999 40.1051979080001 0,-74.8978118899999 40.105346681 0,-74.8973999019999 40.1055183420001 0,-74.89691925 40.1057510390002 0,-74.896057129 40.106204988 0,-74.8952026369999 40.1065826430002 0,-74.8944702149999 40.1069908150002 0,-74.8938751219999 40.1073608400001 0,-74.8928527829999 40.1079521180001 0,-74.8917236329999 40.1085853590001 0,-74.8912811279999 40.1088638310001 0,-74.890899658 40.1091270460001 0,-74.8903655999999 40.1094627390001 0,-74.889892578 40.1096916200002 0,-74.8893432619999 40.1100273140002 0,-74.8888854979999 40.1102752700001 0,-74.888404846 40.1105461130001 0,-74.8878097529999 40.1108551030002 0,-74.887260437 40.1111755380001 0,-74.8866729739999 40.1114730850001 0,-74.886375427 40.1115989690001 0,-74.886032104 40.1117095960001 0,-74.8856353759999 40.1118812570002 0,-74.8852005009999 40.1120414740002 0,-74.8846893309998 40.1122093210002 0,-74.884231567 40.112392427 0,-74.8838577269999 40.1126098640001 0,-74.8835678099999 40.1127777110001 0,-74.8832702639999 40.1129417420001 0,-74.8829040529999 40.1131629950001 0,-74.8824157709999 40.1135139480001 0,-74.882110595 40.1136970530002 0,-74.8818435669999 40.1139297490003 0,-74.881515503 40.1141815190001 0,-74.881263733 40.1143646250001 0,-74.8809890739999 40.1145553600002 0,-74.880760193 40.1146583570001 0,-74.8789183064611 40.11521 0,-74.8775888636365 40.11521 0,-74.8719024659999 40.0991134650001 0,-74.8743820189999 40.0984306340001 0,-74.8805847169999 40.0975875870002 0,-74.8889694219999 40.0964050300002 0,-74.8960342409999 40.0953407290001 0,-74.901748657 40.0945739760001 0,-74.9040734733333 40.0943419237323 0))";
        var poly2 = Microsoft.Maps.WellKnownText.read(wkt);
        // shows false
        console.log("Intersects? " + Microsoft.Maps.SpatialMath.Geometry.intersects(poly1, poly2));
        // shows null
        console.log("Intersection: " + Microsoft.Maps.SpatialMath.Geometry.intersection(poly2, poly1));

    If however you look at the raw lat/longs there is definitely some intersection. In my original code, poly1 is the MBR of the map and you can clearly see the polygon visible on it. Also, I used my original clip function (which is what I am hoping to replace now that you have some spatial functions in v8) and it returns poly2 clipped to poly1's mbr as expected.

    - Brad


    • Edited by Brad Mathews Tuesday, September 19, 2017 6:58 PM
    Tuesday, September 19, 2017 6:09 PM

Answers

  • A locstionRect is not a primitive. Primitives are shapes that are rendered on the map. A LocationRect is not a shape, but an area similar to a Location.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 20, 2017 2:22 PM
    • Marked as answer by Brad Mathews Thursday, September 21, 2017 10:16 PM
    Wednesday, September 20, 2017 2:22 PM
  • You can convert your location rect into a polygon fairly easily. Add the following line of code before doing your intersections:

    poly1 = Microsoft.Maps.SpatialMath.locationRectToPolygon(poly1);


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 20, 2017 5:52 PM
    • Marked as answer by Brad Mathews Thursday, September 21, 2017 10:16 PM
    Wednesday, September 20, 2017 5:52 PM

All replies

  • Poly1 isn't a polygon. Note that these calculations use spatial math, so the lines between the coordinates are curved (geodesic), not straight lines.

    [Blog] [twitter] [LinkedIn]

    Wednesday, September 20, 2017 2:47 AM
  • True, poly1 isn't a polygon but a LocationRect. Is a locationRect not an iPrimitive? Is that the problem?

    - Brad

    Wednesday, September 20, 2017 3:44 AM
  • A locstionRect is not a primitive. Primitives are shapes that are rendered on the map. A LocationRect is not a shape, but an area similar to a Location.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 20, 2017 2:22 PM
    • Marked as answer by Brad Mathews Thursday, September 21, 2017 10:16 PM
    Wednesday, September 20, 2017 2:22 PM
  • You can convert your location rect into a polygon fairly easily. Add the following line of code before doing your intersections:

    poly1 = Microsoft.Maps.SpatialMath.locationRectToPolygon(poly1);


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 20, 2017 5:52 PM
    • Marked as answer by Brad Mathews Thursday, September 21, 2017 10:16 PM
    Wednesday, September 20, 2017 5:52 PM
  • I was literally seconds away from asking for that exact feature when my email dinged with your reply.

    How many other undocumented gems like this are out there and how do I find out about them?

    It might also be a good idea to add this function to the LocationRect class like: polygon = myLocRect.getPolygon(). That way another user does not need to load the SpatialMath module (which I of course need to do in my case anyway.)

    - Brad




    • Edited by Brad Mathews Wednesday, September 20, 2017 6:18 PM
    Wednesday, September 20, 2017 6:07 PM