This topic describes how to use the TairGIS data structure provided by ApsaraDB for Redis Enhanced Edition (Tair) to monitor user trajectories based on points, lines, and planes.

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 based on the mobile Internet. In recent years, a large number of industrial applications and research projects use LBS technologies. These technologies play an important role in many applications.

The COVID-19 pandemic that emerged in 2020 has posed grave health threats to mankind and put countries around the world on pause. To control the spread of the COVID-19 pandemic, China has mobilized the whole country and galvanized the people into a nationwide response. Gradually, cities across China begin to recover from the COVID-19 pandemic. Employees go back to work, enterprises resume production, and students go back to schools. While the spread of the pandemic in China is under control, many other countries are still fighting to flatten the curve of COVID-19 cases. Epidemic prevention and control remains challenging. 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 provided by open source Redis. You can use these native Redis GEO commands to describe location data. However, these commands offer limited support for LBS applications because these commands provide only limited precision and features. TairGIS commands available for performance-enhanced instances of ApsaraDB for Redis Enhanced Edition (Tair) provide more features than the native Redis GEO commands. For more information, see TairGIS commands.

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 these users. You can use the following two methods to obtain the location data:

  • Use the Global Positioning System (GPS) service on user mobile phones. 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 users have been to high-risk areas such as those with epidemic outbreaks. In most cases, you do not need to store the historical trajectory data of users. Alerts can be sent 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 as TairGIS data. You can use points, lines, or polygons to indicate user trajectories based on WKT, and store the points, lines, or polygons as TairGIS data. Then, you can run TairGIS commands to query the intersections between the user trajectories and these high-risk areas to determine whether a user has been to these high-risk areas.

Note WKT is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects, and transformations between spatial reference systems.

The methods to process location data vary based on the methods that you use to obtain the location data. The following examples provide details.

Examples

  • Use the GPS service to obtain the location data

    After you obtain the current GPS data of a user, you can run the GIS.CONTAINS command to check whether the user location is in a high-risk area. For more information about the GIS.CONTAINS command, see GIS.CONTAINS. 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 approaching a high-risk area. If the user approaches a high-risk area, alerts are sent. For more information about the GIS.INTERSECTS command, see GIS.INTERSECTS.

    You can use WKT to describe the GPS data of a user as a point, such as 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 demonstrates 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 the TairGIS data structure. 
    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, such as 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. For more information about the GIS.INTERSECTS command, see GIS.INTERSECTS. Sample code:

    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 structure. 
    GIS.INTERSECTS your_province 'POLYGON ((10 22, 30 45, 16 53, 10 22))'
Note For more information about TairGIS commands, see TairGIS commands.

Summary

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