Using PostGIS v1.0
The following examples use PostGIS functions to create and query spatial objects. For more information about the PostGIS functions, please consult the official PostGIS documentation.
The following command creates a table named
roads table that will hold GIS data and a geometry column.
Then, 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 2 points):
You can use the GIST function to create an index on the geometry column:
AsText(geometry) is a PostGIS function that return a text representation of the geometry:
After an index is created, you can use the
&& operator in a query:
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: