All Products
Search
Document Center

Tair (Redis® OSS-Compatible):Implement digital fences by using TairGIS

Last Updated:Nov 21, 2024

This topic describes how to use the TairGIS data structure provided by Tair (Enterprise Edition) to monitor user trajectories based on points, lines, and polygons.

Background information

Location-based services (LBS) use a variety of technologies to locate devices in real time and provide information and basic services for device users over mobile Internet. LBS technologies play a pivotal role in a large number of industrial applications and research projects these days.

Redis provides Redis geospatial indexes that are useful for querying spatial relationships between points or finding nearby points within a given radius. However, this data structure records data to a relatively coarse precision and provides limited functionality.

By comparison, the TairGIS data structure of Tair allows you to query data in the form of points, lines, and polygons, which costs far less to develop LBS applications than the geospatial data structure of Redis. One of the typical applications of TairGIS is geofencing security systems for senior and child care.

Sample solution

Overview: A school area is added to TairGIS and is specified as a digital fence. If a student leaves the area within the specified time frame, an alert is triggered.

  1. Run the GIS.ADD command to add the school area to TairGIS by using the well-known text (WKT) language. Example:

    GIS.ADD test_app school_location 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'
  2. Obtain the location data of a student and check whether the student remains within the digital fence.

    • Use the GPS service to obtain the location data

      After you obtain the location data of the student, you can run the GIS.CONTAINS command to check whether the student remains within the digital fence. Example:

      GIS.CONTAINS test_app 'POINT (40.086631 30.138141)'
    • Cooperate with telecom carriers to obtain the location data

      Depending on the density of base stations, the location data from telecom carriers may be a sector of an area that is covered by a base station or the entire coverage area of the base station. You can use WKT to describe the location data as a polygon. Example: POLYGON ((10 22, 30 45, 16 53, 10 22)).

      Then, you can run the GIS.CONTAINS command to check whether the polygon coincides with the digital fence. If yes, the student remains within or near the digital fence. If not, the student moves out of the digital fence.

      GIS.CONTAINS test_app 'POLYGON ((10 22, 30 45, 16 53, 10 22))'
Note

You can also run the GIS.WITHIN and GIS.INTERSECTS commands to check whether a student is within a digital fence. For more information, see GIS.

Summary

TairGIS allows you to store and process geographical data for LBS applications with ease and delivers high performance in high-concurrency scenarios.