Using PostGIS v3.2
The following examples use PostGIS functions to create and query spatial objects. For more information about the PostGIS functions, see the official PostGIS documentation.
The following command creates a table named roads
that holds GIS data and a geometry column.
Use the PostGIS AddGeometryColumn
function to add a column to the table:
Use the following SQL commands to insert data into the table roads
. This data consists of the geometry of the type of Linestring
(a line between two points):
You can use the GIST
function to create an index on the geometry column:
AsText(geometry)
is a PostGIS function that returns a text representation of the geometry:
After an index is created, you can use the &&
operator in a query:
Use the BOX3D
function to specify a bounding box. The &&
operator uses the index to quickly reduce the result set down to only those geometries with bounding boxes that overlap the specified area.
You can use the ~=
operator to check if two geometries are geometrically identical: