You can monitor user trajectories based on points, linestrings, and planes by using the TairGIS data structure that is provided by ApsaraDB for Redis Enhanced Edition (Tair).

Background information

Location-based services (LBS) use various technologies to locate devices in real time, and provide information and basic services for users and devices based on the mobile Internet. In recent years, a large number of industrial applications and research projects have been engaged in LBS technologies. LBS technologies play an important role in many applications.

In 2020, the COVID-19 pandemic poses huge health threats to human beings and presses the pause button around the world. To prevent the COVID-19 pandemic from spreading, China has taken proactive measures by using the power of the entire country. China has made great achievements in controlling the spread of the pandemic. The cities across China start to recover from the wounds of the COVID-19 pandemic. Gradually, employees go back to work, enterprises resume production, and students go back to schools. The spreading of the pandemic in China is basically under control, and the other countries and regions are taking efforts to flatten the curve of the COVID-19 pandemic cases. The epidemic prevention and control are still facing considerable challenges. LBS offers an efficient solution to handle these challenges. LBS allows you to monitor user trajectories to identify risks and ensure the safety of people. LBS can also facilitate epidemiological surveys.

ApsaraDB for Redis Community Edition supports native Redis GEO commands that are offered by the open source Redis service. You can use the native Redis GEO commands to describe location data. However, the native Redis GEO commands allow you to implement only limited features due to the limited granularities of geographic data. Therefore, the Redis GEO commands offer limited support for LBS applications. Performance-enhanced instances of ApsaraDB for Redis Enhanced Edition (Tair) support TairGIS commands. TairGIS commands provide more features than the native Redis GEO commands.

TairGIS uses R-tree indexes and supports Geographic Information System (GIS) API operations. Redis supports GEO commands that are suitable for Geohash strings and sorted sets. The GEO commands support geospatial indexing for one-dimensional arrays. This allows you to query points. TairGIS supports indexing for two-dimensional arrays. This allows you to query points, lines, and planes. You can use TairGIS to check intersection or inclusion relationships. TairGIS provides more powerful features.

TairGIS allows you to significantly reduce the costs of developing LBS applications. One of the typical applications of TairGIS is geofencing security systems for senior and child care.

Implementation methods

To monitor the trajectories of a specific group of users, you must obtain the location data of the users. To obtain the location data, you can use the following two methods:

  • Use the Global Positioning System (GPS) service on the mobile phones of the users. In this method, users must enable the GPS service on their mobile phones.
  • Cooperate with telecom carriers.

In scenarios similar to epidemic control, user trajectories are monitored to check whether the users have been to high-risk areas, such as the areas where an epidemic outbreak occurs. Therefore, you do not need to store the previous trajectory data of the users in most cases. You only need to report alerts when users enter high-risk areas. This provides maximum protection for user privacy.

You can use polygons to indicate high-risk areas based on the well-known text (WKT) language, and store the polygons in TairGIS data. You can use points, linestrings, or polygons to indicate user trajectories based on WKT, and store the points, the linestrings, or the polygons in TairGIS data. Then, you can run the TairGIS commands to query the intersections between the user trajectories and the high-risk areas to determine whether a user has passed through the high-risk areas.

Note WKT is a text markup language that you can use to represent vector geometry objects on a map and the spatial reference systems of spatial objects. WKT also allows you to perform transformations between spatial reference systems.

The methods of processing location data varies based on the methods that you use to obtain the location data. The following examples provide details.


  • Use the GPS service to obtain the location data

    After you obtain the current GPS data of a user, you can run the TairGIS GIS.CONTAINS command to check whether the user location is in high-risk areas. If the user is on a road, you can use the GPS data to locate the specific road. Then, run the GIS.INTERSECTS command to check whether the user is moving towards a high-risk area. If the user is moving towards a high-risk area, alerts are reported.

    You can use WKT to describe the GPS data of a user as a point, for example, POINT(30 11). You can use WKT to describe the road information as a linestring, such as LINESTRING (30 10, 40 40). The following sample code helps you understand how to implement the business logic.
    GIS.ADD your_province your_location 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' // Add the GPS information of a user to TairGIS data.
    GIS.CONTAINS your_province 'POINT (30 11)' 
    GIS.INTERSECTS your_province 'LINESTRING (30 10, 40 40)'
  • Cooperate with telecom carriers to obtain the location data

    In scenarios where base stations are deployed by telecom carriers in a sparse manner, the location data that you obtain indicates an area. The area may be a sector that is covered by a base station or the entire coverage area of the base station. You can use WKT to describe the area as a polygon, for example, POLYGON ((10 22, 30 45, 16 53, 10 22)). You can run the GIS.INTERSECTS command to analyze the intersections between the polygon and the high-risk areas. The sample code is provided as follows:

    GIS.ADD your_province your_location 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' // Add the location information that you obtain from the base stations of the telecom carrier to the TairGIS data.
    GIS.INTERSECTS your_province 'POLYGON ((10 22, 30 45, 16 53, 10 22))'
Note For more information about TairGIS commands, see TairGIS commands.


Performance-enhanced instances of ApsaraDB for Redis Enhanced Edition (Tair) provide the TairGIS data structure. TairGIS provides an easy method for you to use LBS applications to store and compute geographic data. TairGIS also allows you to deliver high performance in high-concurrency scenarios.