TairGIS is a data structure that uses R-tree indexes and supports APIs related to a geographic information system (GIS). Compared with native Redis GEO commands that allow you to use Geohash and Redis Sorted Set to query points, TairGIS provides more features by allowing you to query points, linestrings, and polygons.
Features
Uses R-tree indexes for query and storage.
Supports linestring and polygon queries, including queries for the intersection of sets.
Provides the GIS.SEARCH command, which functions like native Redis GEORADIUS command.
The module is open-sourced. For more information, visit GitHub.
The latest minor version provides more features and higher stability. We recommend that you update the instance to the latest minor version. For more information, see Update the minor version of an instance. If your instance is a cluster or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version. This ensures that all commands can be run as expected.
Usage notes
The TairGIS data that you want to manage is stored on a Tair instance.
GIS.ADD area polygonName polygonWkt [polygonName polygonWkt ...]
Adds one or more polygons to an area. The polygons are described in WKT.
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.
Checks whether a point, linestring, or polygon is located in polygons within a specific area. If yes, this command returns the number and WKTs of polygons that contain the point, linestring, or polygon in the area.
Checks whether an area is located within a point, linestring, or polygon. If yes, this command returns the number and WKTs of polygons in the area that are located within the point, linestring, or polygon.
Checks whether a point, linestring, or polygon intersects with polygons within a specific area. If yes, this command returns the number and WKTs of polygons within the area that intersect with the point, linestring, or polygon.
Deletes one or more TairGIS keys. This is a native Redis command.
Note The following section describes command syntax used in this topic:
Uppercase keyword: the command keyword.
Italic: Words in italic indicate variable information that you supply.
[options]: optional parameters. Parameters that are not included in brackets are required.
A|B: specifies that these parameters are mutually exclusive. Select one of two or more parameters.
...: specifies to repeat the preceding content.
GIS.ADD
Item
Description
Syntax
GIS.ADD area polygonName polygonWkt [polygonName polygonWkt ...]
Time complexity
O(log n)
Command description
Adds one or more polygons to an area. The polygons are described in WKT.
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.
Parameter
area: a geometric concept.
PolygonName: the name of the polygon that you want to manage.
polygonWkt: the description of the polygon that is written in WKT. The description includes longitudes and latitudes. The following polygon types can be described in WKT:
POINT: the WKT that describes a point. Example: 'POINT (120.086631 30.138141)'. The value indicates that the point is located at longitude 120.086631 and latitude 30.138141.
LINESTRING: the WKT that describes a linestring. The linestring consists of two points. Example: 'LINESTRING (30 10, 40 40)'.
POLYGON: the WKT that describes a polygon. The polygon consists of multiple points. Example: 'POLYGON ((31 20, 29 20, 29 21, 31 31))'.
Note
Valid values of a longitude are -180 to 180, and valid values of a latitude are -90 to 90.
The MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRY, or COLLECTION collection type is not supported.
Output
If the operation is successful, the number of polygons that have been added and updated is returned.
PolygonName: the name of the polygon that you want to manage.
Output
If the operation is successful, the WKT of the polygon is returned.
If the area or polygon does not exist, nil is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD hangzhou campus 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' command is run in advance.
Sample command:
GIS.GET hangzhou campus
Sample output:
'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'
GIS.GETALL
Item
Description
Syntax
GIS.GETALL area [WITHOUTWKT]
Time complexity
O(n)
Command description
Retrieves the names and WKTs of all polygons within an area. If you specify the WITHOUTWKT parameter, only the names of the polygons are returned.
Parameter
area: a geometric concept.
WITHOUTWKT: specifies whether to return the WKTs of polygons. If this parameter is specified, the WKTs of the polygons are not returned.
Output
If the operation is successful, the names and WKTs of the polygons are returned. If the WITHOUTWKT parameter is specified, only the names of the polygons are returned.
If the area does not exist, nil is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD hangzhou campus 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' command is run in advance.
Checks whether a point, linestring, or polygon is located in polygons within a specific area. If yes, this command returns the number and WKTs of polygons that contain the point, linestring, or polygon in the area.
Parameter
area: a geometric concept.
polygonWkt: the description of the polygon that is written in WKT. The description includes longitudes and latitudes. The following polygon types can be described in WKT:
POINT: the WKT that describes a point.
LINESTRING: the WKT that describes a linestring.
POLYGON: the WKT that describes a polygon.
WITHOUTWKT: specifies whether to return the WKTs of polygons. If this parameter is specified, the WKTs of the polygons are not returned.
Output
If the operation is successful, the number and WKTs of the polygons are returned.
If the area does not exist, the "empty list or set" message is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD hangzhou campus 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' command is run in advance.
Checks whether an area is located within a point, linestring, or polygon. If yes, this command returns the number and WKTs of polygons in the area that are located within the point, linestring, or polygon.
Parameter
area: a geometric concept.
polygonWkt: the description of the polygon that is written in WKT. The description includes longitudes and latitudes. The following polygon types can be described in WKT:
POINT: the WKT that describes a point.
LINESTRING: the WKT that describes a linestring.
POLYGON: the WKT that describes a polygon.
Note
MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRY, or COLLECTION is not supported.
WITHOUTWKT: specifies whether to return the WKTs of polygons. If this parameter is specified, the WKTs of the polygons are not returned.
Output
If the operation is successful, the number and WKTs of the polygons are returned.
If the area does not exist, the "empty list or set" message is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD hangzhou campus 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' command is run in advance.
Checks whether a point, linestring, or polygon intersects with polygons within a specific area. If yes, this command returns the number and WKTs of polygons within the area that intersect with the point, linestring, or polygon.
Parameter
area: a geometric concept.
polygonWkt: the description of the polygon that is written in WKT. The description includes longitudes and latitudes. The following polygon types can be described in WKT:
POINT: the WKT that describes a point.
LINESTRING: the WKT that describes a linestring.
POLYGON: the WKT that describes a polygon.
WITHOUTWKT: specifies whether to return the WKTs of polygons. If this parameter is specified, the WKTs of the polygons are not returned.
Output
If the operation is successful, the number and WKTs of the polygons are returned.
If the area does not exist, the "empty list or set" message is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD hangzhou campus 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))' command is run in advance.
GIS.SEARCH area [RADIUS longitude latitude distance M|KM|FT|MI]
[MEMBER field distance M|KM|FT|MI]
[GEOM geom]
[COUNT count]
[ASC|DESC]
[WITHDIST]
[WITHOUTWKT]
Time complexity
Optimal time complexity:
Least desirable time complexity: O(log n)
Command description
Queries the points in an area that are located within a radius of a specific longitude and latitude position.
Parameter
area: a geometric concept.
RADIUS: the longitude, latitude, radius, and radius unit. Valid values for the unit: meters (m), kilometers (km), feet (kt), and miles (mi). Example: RADIUS 15 37 200 km.
MEMBER: the point in the area that is used as the base point and the radius for the point. Valid values for the radius unit: meters (m), kilometers (km), feet (kt), and miles (mi). Example: MEMBER Agrigento 100 km. In this example, "Agrigento" indicates the name of the polygon, "100" indicates the radius, and "km" indicates the radius unit. This order must be used for the parameter syntax.
GEOM: the polygon written in WKT that specifies the search range. Example: GEOM 'POLYGON((10 30,20 30,20 40,10 40))'.
COUNT: the maximum number of entries that can be returned. Example: COUNT 3.
ASC|DESC: the order in which the returned entries are ranked. ASC indicates that the returned entries are ranked from short to long based on their distance to the center. DESC indicates that the returned entries are ranked from long to short based on their distance to the center.
WITHDIST: specifies whether to return the distance between a specific point and the point specified by the MEMBER parameter.
WITHOUTWKT: specifies whether to return the WKTs of points. If this parameter is specified, the WKTs of the points are not returned.
Note
You can specify only one of the RADIUS, MEMBER, and GEOM parameters.
Output
If the operation is successful, the number and WKTs of the points are returned.
If the area does not exist, the "empty list or set" message is returned.
Otherwise, an error message is returned.
Example
The GIS.ADD Sicily "Palermo" "POINT (13.361389 38.115556)" "Catania" "POINT(15.087269 37.502669)" command is run in advance.
Sample command:
GIS.SEARCH Sicily RADIUS 15 37 200 km WITHDIST ASC