Analytics, Azure, Cloud Computing, Internet of Things (IoT)

6 Mins Read

Quick Guide for Processing GPS Data with Azure Stream Analytics: Geo-spatial Functions

Tracking the location of a vehicle has become a very common task carried out by various industries like transport and logistics. But as the world is rushing towards smart solutions in every aspect, it requires much more than just tracking a vehicle. I always say “Data is money”. This stands true even for GPS data which can open an ocean of opportunities for building up smart solutions for fleet management, logistics, automobile remote monitoring / maintenance, security, weather forecast, etc.

Microsoft Azure is one of the best Cloud Computing platforms available for IoT. For performing the real-time analysis of data, there is a PaaS service known as Azure Stream Analytics which can analyze live data efficiently. Recently, Microsoft Azure came up with a new set of functions for analyzing the GPS based data which offers functionality for developing different types of advanced IoT applications. These functions are known as Geo-spatial functions. I have dedicated this blog for those who want to process GPS data streamed via IoT devices and learn about the related terms, processes and potential applications.

Few Terms to Clarify Before We Begin:

Before we begin to understand how we can process GPS data and types of applications supported, I would like to clarify some basic terms to make things simple.

Geo-spatial: The term Geo-spatial relates to any technology or system which is used to acquire, process and store geographic information.
Point (Geo-location): Point refers to a single geo-location on map that are co-ordinates of longitude and latitude format.
LineString:  LineString defines multiple points in a single object representation.
Polygon (Geo-fencing): Polygon is a section of the entire map which defines the area or route of purpose basically known as Geo-fencing. This term states the restriction of any object from going out or getting inside a specific area or route.
Ring Orientation: Ring Orientation is the order of points mentioned in specifying a polygon. Imagine, if you plot a polygon which defines a small area of your house and you start walking alongside the perimeter of that polygon in a sequence of points defined in the polygon, then one hand would be inside the polygon and other hand would be outside the polygon. There are two types of ring orientation of a polygon i.e. Left-handed and Right-handed. Microsoft Azure Geo-systems are designed with Right-hand orientation, which means the points should be defined in a sequence where the left hand should always be inside the polygon while walking through the perimeter of the polygon in the sequence from point 1 to point 2.

Right Handed OrientationRight Handed Ring Orientation 1

GeoJSON: GeoJSON is a data format like JSON, but optimized to store and encode Geo-spatial and non-Geo-spatial information related to Maps and other Geo-systems.

Collection and Streaming of GPS Data to Azure

In real-life, the Global Positioning System can be present in various ways. It could be a mobile phone enabled with GPS service, a dedicated-proprietary GPS device installed by a fleet owner or a custom-made IoT device embedded with microchips like GPS modules. Depending upon the source, the method of collecting this information would change. These days, researchers have started creating their own IoT devices based on their need. These devices are created by interfacing GPS / GSM modules like SIM808 and microcontrollers like Arduino. These modules can work with mobile phone networks based on GSM sim cards and have GPS receivers which can accurately provide information about its current co-ordinates.

SIM808 - A GSM / GPS Module 1SIM808 – A GSM / GPS Module 1

 These devices are further registered with Cloud ingestion points like Azure IoT Hub or Azure Event Hub, so that data can be streamed to the Cloud where we prefer to setup our Lambda Architecture. Azure IoT Hub or Azure Event Hub can be integrated to Azure Stream Analytics. Through this well-defined channel, the data reaches for real-time processing on the Cloud.

Real-Time Analysis of GPS Data Using Azure Stream Analytics

There are many functions which are supported for real-time analysis in Azure Stream Analytics. A function defines the action that needs to be taken on the data. We can count occurrences of events, perform mathematical calculations, filter or segregate data by using functions. To give a simple example, we can write a small query which can calculate average temperature every 10 seconds by using AVG function.

In a similar way, we also have functions which can be used for processing GPS data streaming in the Azure Stream Analytics. They are known as Geo-spatial functions. Here I have given easy explanations of all the Geo-spatial functions available:

CreatePoint: This is a function which is used to fix a Geo-location on map like the way we double click on a spot in Google Maps to pin a location. We can create multiple such points which can be used to define source spot, destination spot or reference point for defining a specific field on the map. We need to enter two values: Longitude and Latitude to define a Geo-location using CreatePoint function.
ST_DISTANCE: This is a function which is used to find out the distance between any two Geo-locations. In the last function, we created points which are defined Geo-locations. Here, we need to enter the name of the points created for source and destination.
CreatePolygon: This is a function which is used to define a certain area or route on the map. We can define Geo-locations by using CreatePoint function. In CreatePolygon function, we need to specify multiple points in a sequence which can plot a polygon. There are a few things to keep in mind while creating a polygon here:
1. Microsoft Azure Geo-systems follows Right-hand ring orientation.
2. Polygon cannot have holes, which means that you cannot define a subset of area (hole) within a polygon. Standard Geo-systems allow to have a hole in the polygon for greater degree of complicated Geo-fencing.

Polygon Hole 1Polygon Hole  1

3.  Polygon should have at least three points for its definition. Also, the first point and last point should be same so that the structure of polygon is completed and it can clearly lock the area between the points.

CreateLineString: This function can be used to create LineString which can be referred to other functions to define a certain path. In this function, we need to mention at least two points.
ST_OVERLAPS: This function can be used to determine if one polygon is overlapping the other. We need to define two polygons in this function. This can be useful in situations when one polygon is stationary like a city and another polygon is an object which defines a storm or a hurricane. If some weather system is tracking the storm or hurricane, then it’s co-ordinates can be used to define a polygon. The points of this polygon can constantly update as it gets the input from the weather tracking system. By using the function: ST_OVERLAPS, we can create a notification system if a storm or a hurricane hits the concerned area. This function can be applied in other fields like astrophysics, wild life or space research.
ST_WITHIN: This function is useful in applications like logistics. There are two inputs required. First input is a single point or an entire polygon and the other input is a fixed polygon. A GPS tracker in a truck that sends information about its location can be updated as the first input value and the other could be a polygon defining the location of the factory which is the destination. A notification system can be built around this to automate the supply chain management scenarios.
ST_INTERSECT: This function is used to detect if two LineStrings are intersecting each other at any point of time.

Potential Solutions to Build Around by Performing Real-time Processing of GPS Data

  • Restricting operations of any digital equipment beyond a certain geography which may belong to private or military organization in respect to avoid any loss of data.
  • Monitoring and Route Validation for vehicles to make sure the logistic’s truck or rented vehicles don’t go beyond a specified boundary.
  • Geographically aware applications giving information about critical resources like hospitals, ATM centres or base camps in surrounding regions.

Summary

The Geo-spatial functions are built into Azure Stream Analytics and were launched in February 2017. Microsoft states, there are around 100 customers testing these functions such as NASCAR for race analysis. The benefit of using Geo-spatial functions is the ease of building applications around GPS data. If these functions are not developed, then the logic of understanding and utilizing GPS data can make a query super complex.

WRITTEN BY CloudThat

SHARE

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!