azureazure-stream-analyticsstream-analytics

Stream analytics geospatial function usage


I want to use Stream Analytics geospatial functions by using the latitude/longitude data (sent via Azure IoTHub) and a target latitude/longitude or polygon data (from reference input).

I know we can join stream and reference inputs in a query but is it possible to implement a solution we do not have any data to join between stream and reference inputs and still calculate e.g. the distance between points using ST_DISTANCE?

The sample reference input data:

"points":[
{
    "point": {
    "type" : "Point",
    "coordinates" : [0.0, 10.0] } 
},
{
    "point": {
    "type" : "Point",
    "coordinates" : [0.0, 0.0] }
},
{
    "point": {
    "type" : "Point",
    "coordinates" : [0.0, -5.0] }
}]

The data above will have more points, so manual entry of the points in the query will not be a good solution.

I expect the output to contain the points compared and their distance.


Solution

  • After playing with the SQL query, I found out that actually CROSS JOIN is available in Stream Analytics but not in the documentation. So using something like:

    SELECT ST_DISTANCE(CreatePoint(input.Lat, input.Lon), CreatePoint(ref.Lat, ref.Lon)) 
    INTO output FROM inputStream input 
    CROSS JOIN reference ref
    

    works.