Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Geospatial functions in Azure Stream Analytics enable real-time analytics on streaming geospatial data. With just a few lines of code, you can develop a production grade solution for complex scenarios. These functions support all WKT types and GeoJSON Point, Polygon, and LineString.
Examples of scenarios that can benefit from geospatial functions include:
Stream Analytics Query Language has seven built-in geospatial functions: CreateLineString, CreatePoint, CreatePolygon, ST_DISTANCE, ST_OVERLAPS, ST_INTERSECTS, and ST_WITHIN.
The CreateLineString
function accepts points and returns a GeoJSON LineString, which can be plotted as a line on a map. You must have at least two points to create a LineString. The LineString points will be connected in order.
The following query uses CreateLineString
to create a LineString using three points. The first point is created from streaming input data, while the other two are created manually.
SELECT
CreateLineString(CreatePoint(input.latitude, input.longitude), CreatePoint(10.0, 10.0), CreatePoint(10.5, 10.5))
FROM input
latitude | longitude |
---|---|
3.0 | -10.2 |
-87.33 | 20.2321 |
{"type" : "LineString", "coordinates" : [ [-10.2, 3.0], [10.0, 10.0], [10.5, 10.5] ]}
{"type" : "LineString", "coordinates" : [ [20.2321, -87.33], [10.0, 10.0], [10.5, 10.5] ]}
To learn more, visit the CreateLineString reference.
The CreatePoint
function accepts a latitude and longitude and returns a GeoJSON point, which can be plotted on a map. Your latitudes and longitudes must be a float datatype.
The following example query uses CreatePoint
to create a point using latitudes and longitudes from streaming input data.
SELECT
CreatePoint(input.latitude, input.longitude)
FROM input
latitude | longitude |
---|---|
3.0 | -10.2 |
-87.33 | 20.2321 |
{"type" : "Point", "coordinates" : [-10.2, 3.0]}
{"type" : "Point", "coordinates" : [20.2321, -87.33]}
To learn more, visit the CreatePoint reference.
The CreatePolygon
function accepts points and returns a GeoJSON polygon record. The order of points must follow right-hand ring orientation, or counter-clockwise. Imagine walking from one point to another in the order they were declared. The center of the polygon would be to your left the entire time.
The following example query uses CreatePolygon
to create a polygon from three points. The first two points are created manually, and the last point is created from input data.
SELECT
CreatePolygon(CreatePoint(input.latitude, input.longitude), CreatePoint(10.0, 10.0), CreatePoint(10.5, 10.5), CreatePoint(input.latitude, input.longitude))
FROM input
latitude | longitude |
---|---|
3.0 | -10.2 |
-87.33 | 20.2321 |
{"type" : "Polygon", "coordinates" : [[ [-10.2, 3.0], [10.0, 10.0], [10.5, 10.5], [-10.2, 3.0] ]]}
{"type" : "Polygon", "coordinates" : [[ [20.2321, -87.33], [10.0, 10.0], [10.5, 10.5], [20.2321, -87.33] ]]}
To learn more, visit the CreatePolygon reference.
The ST_DISTANCE
function returns the distance between two geometries in meters.
The following query uses ST_DISTANCE
to generate an event when a gas station is less than 10 km from the car.
SELECT Cars.Location, Station.Location
FROM Cars c
JOIN Station s ON ST_DISTANCE(c.Location, s.Location) < 10 * 1000
To learn more, visit the ST_DISTANCE reference.
The ST_OVERLAPS
function compares two geometries. If the geometries overlap, the function returns a 1. The function returns 0 if the geometries don't overlap.
The following query uses ST_OVERLAPS
to generate an event when a building is within a possible flooding zone.
SELECT Building.Polygon, Building.Polygon
FROM Building b
JOIN Flooding f ON ST_OVERLAPS(b.Polygon, b.Polygon)
The following example query generates an event when a storm is heading towards a car.
SELECT Cars.Location, Storm.Course
FROM Cars c, Storm s
JOIN Storm s ON ST_OVERLAPS(c.Location, s.Course)
To learn more, visit the ST_OVERLAPS reference.
The ST_INTERSECTS
function compares two geometries. If the geometries intersect, then the function returns 1. The function returns 0 if the geometries don't intersect each other.
The following example query uses ST_INTERSECTS
to determine if a paved road intersects a dirt road.
SELECT
ST_INTERSECTS(input.pavedRoad, input.dirtRoad)
FROM input
datacenterArea | stormArea |
---|---|
{"type":"LineString", "coordinates": [ [-10.0, 0.0], [0.0, 0.0], [10.0, 0.0] ]} | {"type":"LineString", "coordinates": [ [0.0, 10.0], [0.0, 0.0], [0.0, -10.0] ]} |
{"type":"LineString", "coordinates": [ [-10.0, 0.0], [0.0, 0.0], [10.0, 0.0] ]} | {"type":"LineString", "coordinates": [ [-10.0, 10.0], [0.0, 10.0], [10.0, 10.0] ]} |
1
0
To learn more, visit the ST_INTERSECTS reference.
The ST_WITHIN
function determines whether a geometry is within another geometry. If the first is contained in the last, the function will return 1. The function will return 0 if the first geometry isn't located within the last one.
The following example query uses ST_WITHIN
to determine whether the delivery destination point is within the given warehouse polygon.
SELECT
ST_WITHIN(input.deliveryDestination, input.warehouse)
FROM input
deliveryDestination | warehouse |
---|---|
{"type":"Point", "coordinates": [76.6, 10.1]} | {"type":"Polygon", "coordinates": [ [0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0] ]} |
{"type":"Point", "coordinates": [15.0, 15.0]} | {"type":"Polygon", "coordinates": [ [10.0, 10.0], [20.0, 10.0], [20.0, 20.0], [10.0, 20.0], [10.0, 10.0] ]} |
0
1
To learn more, visit the ST_WITHIN reference.
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Learning path
Implement a Data Streaming Solution with Azure Stream Analytics - Training
Implement a Data Streaming Solution with Azure Stream Analytics
Documentation
Common query patterns in Azure Stream Analytics - Azure Stream Analytics
This article describes several common query patterns and designs that are useful in Azure Stream Analytics jobs.
Introduction to Azure Stream Analytics windowing functions - Azure Stream Analytics
This article describes four windowing functions (tumbling, hopping, sliding, session) that are used in Azure Stream Analytics jobs.
Use reference data for lookups in Azure Stream Analytics - Azure Stream Analytics
This article describes how to use reference data to look up or correlate data in an Azure Stream Analytics job's query design.