locked
Using ST_WITHIN GeoSpatial RRS feed

  • Question

  • Okay, I give. I have been trying to get ST_WHILE to work for the last 4 hours without success. I have two test files as follows:

    Test File 1 Structure:
    [{
    "id": "a2b8bcd8-ff79-4bb7-a86f-615556104c1f",
    "mechanism": "geo",
    "geometry": {
    "type": "Point",
    "coordinates": [15.0, 15.0]
    }
    }]

    Test File 2 Structure:
    [{
    "geometry":{
    "type": "Polygon",
    "coordinates": [[10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0]]
    }
    }]

    Test File 1 represents data from an event hub. Test File 2 represents static reference data. I am running the following query:
    select st_within(eh.geometry, r.geometry) from eventhub eh join reference r on eh.mechanism='geo'

    The result says this:
    GeJSON polygon must contain field "type" with value "Polygon" and field "coordinates" with a list of no less than 4 point type elements, first point must be equal to last point. Values cannot be null.

    I have tried every variation known to mankind on the files but the result is always the same. I can get ST_WHILE to work if I manually use CreatePoint and CreatePolygon but that is not a workable solution. Do you all have a bug, or is there something wrong with my file structures above?

    Thanks for any help.

    Monday, July 24, 2017 7:20 PM

Answers

  • Never mind I fixed it.  For anyone else banging their head against the wall on this I will list my solution below.  Take note, the same shown on the msdn documentation site is not correct.

    The problem was due to a typo.  According to the msdn documentation for ST_WITHIN (https://msdn.microsoft.com/en-us/library/mt778931.aspx) the structure of the geometry object in the JSON for the Polygon is:

    {“type”:”Polygon”, “coordinates”: [ [10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0] ]}

    If you use the above structure, it will fail in Stream Analytics when you run the query using ST_WITHIN.  The correct structure is below:

    {“type”:”Polygon”, “coordinates”: [[ [10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0] ]]}

    Notice the extra [] added.  This solved the problem.  Once I added those and ran the query in Stream Analytics, everything worked.  Hope this helps someone.

    Wednesday, July 26, 2017 2:22 PM

All replies

  • Never mind I fixed it.  For anyone else banging their head against the wall on this I will list my solution below.  Take note, the same shown on the msdn documentation site is not correct.

    The problem was due to a typo.  According to the msdn documentation for ST_WITHIN (https://msdn.microsoft.com/en-us/library/mt778931.aspx) the structure of the geometry object in the JSON for the Polygon is:

    {“type”:”Polygon”, “coordinates”: [ [10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0] ]}

    If you use the above structure, it will fail in Stream Analytics when you run the query using ST_WITHIN.  The correct structure is below:

    {“type”:”Polygon”, “coordinates”: [[ [10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0] ]]}

    Notice the extra [] added.  This solved the problem.  Once I added those and ran the query in Stream Analytics, everything worked.  Hope this helps someone.

    Wednesday, July 26, 2017 2:22 PM
  • Hi,

    Thanks for taking the time to post your findings. Sorry for the typo in the documentation and the inconvenience. We will update the documentation.

    Thanks,

    JS

    Thursday, July 27, 2017 3:54 PM