地理空间索引
用于为地理空间数据编制索引的选项
Redis 支持两种不同的地理空间数据架构类型:
GEO
:这使用一种简单的格式,其中单个地理空间 点指定为数字经纬度对。GEOSHAPE
:此函数使用熟知文本 (WKT) 格式的子集,使用任一地理位置指定点和多边形 coordinates 或 Cartesian 坐标。
以下各节介绍如何为这些架构类型编制索引。有关这两种类型的完整描述,请参阅地理空间参考页面。
GEO
以下命令创建一个GEO
index (对于包含
名为location
:
If you now add JSON objects with the product:
prefix and a location
field,
they will be added to the index automatically:
The query below finds products within a 100 mile radius of Colorado Springs
(Longitude=-104.800644, Latitude=38.846127). This returns only the location in
Denver, but a radius of 200 miles would also include the location in Fort Collins:
See Geospatial queries
for more information about the available options.
GEOSHAPE
The following command creates an index for JSON objects that include
geospatial data in a field called geom
. The FLAT
option at the end
of the field definition specifies Cartesian coordinates instead of
the default spherical geographical coordinates. Use SPHERICAL
in
place of FLAT
to choose the coordinate space explicitly.
Use the shape:
prefix for the JSON objects to add them to the index:
You can now run various geospatial queries against the index. For
example, the query below returns any shapes within the boundary
of the green square but omits the green square itself:
You can also run queries to find whether shapes in the index completely contain
or overlap each other. See
Geospatial queries
for more information.
On this page