|
| 1 | +--- |
| 2 | +title: Introduction to Azure Stream Analytics geospatial functions |
| 3 | +description: This article describes geospatial functions that are used in Azure Stream Analytics jobs. |
| 4 | +services: stream-analytics |
| 5 | +author: mamccrea |
| 6 | +ms.author: mamccrea |
| 7 | +manager: kfile |
| 8 | +ms.reviewer: mamccrea |
| 9 | +ms.service: stream-analytics |
| 10 | +ms.topic: conceptual |
| 11 | +ms.date: 08/20/2018 |
| 12 | +--- |
| 13 | + |
| 14 | +# Introduction to Stream Analytics geospatial functions |
| 15 | + |
| 16 | +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 scenarios such as ride-sharing, fleet management, asset tracking, geo-fencing, and phone tracking across cell sites. The ability to join multiple streams of data with geospatial data can be used to answer complex questions on streaming data. Stream Analytics has adopted the GeoJSON standard for geospatial data. |
| 17 | + |
| 18 | +Stream Analytics Query Language has seven built-in geospatial functions: |
| 19 | + |
| 20 | +- [CreateLineString](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/createlinestring) |
| 21 | +- [CreatePoint](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/createpoint) |
| 22 | +- [CreatePolygon](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/createpolygon) |
| 23 | +- [ST_DISTANCE](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/st-distance) |
| 24 | +- [ST_OVERLAPS](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/st-overlaps) |
| 25 | +- [ST_INTERSECTS](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/st-intersects) |
| 26 | +- [ST_WITHIN](https://msdn.microsoft.com/en-us/azure/stream-analytics/reference/st-within) |
| 27 | + |
| 28 | +## CreateLineString |
| 29 | + |
| 30 | +```SQL |
| 31 | +SELECT |
| 32 | + CreateLineString(CreatePoint(input.latitude, input.longitude), CreatePoint(10.0, 10.0), CreatePoint(10.5, 10.5)) |
| 33 | +FROM input |
| 34 | +``` |
| 35 | + |
| 36 | +### Input Example |
| 37 | + |
| 38 | +|latitude|longitude| |
| 39 | +|--------------|---------------| |
| 40 | +|3.0|-10.2| |
| 41 | +|-87.33|20.2321| |
| 42 | + |
| 43 | +### Output Example |
| 44 | + |
| 45 | + {"type" : "LineString", "coordinates" : [ [-10.2, 3.0], [10.0, 10.0], [10.5, 10.5] ]} |
| 46 | + |
| 47 | + {"type" : "LineString", "coordinates" : [ [20.2321, -87.33], [10.0, 10.0], [10.5, 10.5] ]} |
| 48 | + |
| 49 | +## CreatePoint |
| 50 | + |
| 51 | +```SQL |
| 52 | +SELECT |
| 53 | + CreatePoint(input.latitude, input.longitude) |
| 54 | +FROM input |
| 55 | +``` |
| 56 | + |
| 57 | +### Input Example |
| 58 | + |
| 59 | +|latitude|longitude| |
| 60 | +|--------------|---------------| |
| 61 | +|3.0|-10.2| |
| 62 | +|-87.33|20.2321| |
| 63 | + |
| 64 | +### Output Example |
| 65 | + |
| 66 | + {"type" : "Point", "coordinates" : [-10.2, 3.0]} |
| 67 | + |
| 68 | + {"type" : "Point", "coordinates" : [20.2321, -87.33]} |
| 69 | + |
| 70 | +## CreatePolygon |
| 71 | + |
| 72 | +```SQL |
| 73 | +SELECT |
| 74 | + CreatePolygon(CreatePoint(input.latitude, input.longitude), CreatePoint(10.0, 10.0), CreatePoint(10.5, 10.5), CreatePoint(input.latitude, input.longitude)) |
| 75 | +FROM input |
| 76 | +``` |
| 77 | + |
| 78 | +### Input Example |
| 79 | + |
| 80 | +|latitude|longitude| |
| 81 | +|--------------|---------------| |
| 82 | +|3.0|-10.2| |
| 83 | +|-87.33|20.2321| |
| 84 | + |
| 85 | +### Output Example |
| 86 | + |
| 87 | + {"type" : "Polygon", "coordinates" : [[ [-10.2, 3.0], [10.0, 10.0], [10.5, 10.5], [-10.2, 3.0] ]]} |
| 88 | + |
| 89 | + {"type" : "Polygon", "coordinates" : [[ [20.2321, -87.33], [10.0, 10.0], [10.5, 10.5], [20.2321, -87.33] ]]} |
| 90 | + |
| 91 | +## ST_DISTANCE |
| 92 | + |
| 93 | +Generate an event when a gas station is less than 10 km from the car: |
| 94 | + |
| 95 | +```SQL |
| 96 | +SELECT Cars.Location, Station.Location |
| 97 | +FROM Cars c |
| 98 | +JOIN Station s ON ST_DISTANCE(c.Location, s.Location) < 10 * 1000 |
| 99 | +``` |
| 100 | + |
| 101 | +## ST_OVERLAPS |
| 102 | + |
| 103 | +Generate an event when building is within a possible flooding zone: |
| 104 | + |
| 105 | +```SQL |
| 106 | +SELECT Building.Polygon, Building.Polygon |
| 107 | +FROM Building b |
| 108 | +JOIN Flooding f ON ST_OVERLAPS(b.Polygon, b.Polygon) |
| 109 | +``` |
| 110 | + |
| 111 | +Generate an event when a storm is heading towards a car: |
| 112 | + |
| 113 | +```SQL |
| 114 | +SELECT Cars.Location, Storm.Course |
| 115 | +FROM Cars c, Storm s |
| 116 | +JOIN Storm s ON ST_OVERLAPS(c.Location, s.Course) |
| 117 | +``` |
| 118 | + |
| 119 | +## ST_INTERSECTS |
| 120 | + |
| 121 | +```SQL |
| 122 | +SELECT |
| 123 | + ST_INTERSECTS(input.pavedRoad, input.dirtRoad) |
| 124 | +FROM input |
| 125 | +``` |
| 126 | + |
| 127 | +### Input Example |
| 128 | + |
| 129 | +|datacenterArea|stormArea| |
| 130 | +|--------------------|---------------| |
| 131 | +|{“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] ]}| |
| 132 | +|{“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] ]}| |
| 133 | + |
| 134 | +### Output Example |
| 135 | + |
| 136 | + 1 |
| 137 | + |
| 138 | + 0 |
| 139 | + |
| 140 | +## ST_WITHIN |
| 141 | + |
| 142 | +```SQL |
| 143 | +SELECT |
| 144 | + ST_WITHIN(input.deliveryDestination, input.warehouse) |
| 145 | +FROM input |
| 146 | +``` |
| 147 | + |
| 148 | +### Input Example |
| 149 | + |
| 150 | +|deliveryDestination|warehouse| |
| 151 | +|-------------------------|---------------| |
| 152 | +|{“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] ]}| |
| 153 | +|{“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] ]}| |
| 154 | + |
| 155 | +### Output Example |
| 156 | + |
| 157 | + 0 |
| 158 | + |
| 159 | + 1 |
0 commit comments