Geospatial indexing

Options for indexing geospatial data

Redis supports two different schema types for geospatial data:

  • GEO: This uses a simple format where individual geospatial points are specified as numeric longitude-latitude pairs.
  • GEOSHAPE: This uses a subset of the Well-Known Text (WKT) format to specify both points and polygons using either geographical coordinates or Cartesian coordinates.

The sections below explain how to index these schema types. See the Geospatial reference page for a full description of both types.

GEO

The following command creates a GEO index for JSON objects that contain the geospatial data in a field called 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.

RATE THIS PAGE
Back to top ↑