A geometric data type represents a spatial object with coordinates and shape. Postgres provides built-in 2D types such as point, line, lseg, box, path, polygon, and circle; PostGIS extends this model with typed geometry values such as Point, LineString, Polygon, and MultiPolygon. section 10.1.1 section 10.1.2
Use geometry values to model and query spatial data:
- Store points of interest, city centers, restaurants, roads, rivers, buildings, parks, lakes, and city boundaries. section 10.1.1 section 10.3.2
- Associate a subtype and spatial reference identifier with a column, such as geometry(Point, 3857), where 3857 denotes Web Mercator. section 10.1.2 section 10.3.1
- Perform planar calculations and spatial predicates, including distance, area, containment, intersection, equality, and coordinate transformation. section 10.5.1 section 10.5.2
- Remember that geometry uses Cartesian mathematics on a Euclidean plane, making calculations fast but potentially less accurate over large distances because it does not model Earth’s curvature. section 10.1.2 section 10.7
Find nearby restaurants
A PostGIS query can search within 500 meters of a hotel, calculate distances, and order the results: JOIN florida.planet_osm_point AS p ON ST_DWithin(h.way, p.way, 500) WHERE p.amenity = 'restaurant' ORDER BY ST_Distance(h.way, p.way) LIMIT 5. The sample output starts with Wagamama at 68 meters and Boulon Brasserie at 132 meters. section 10.5.1
Inspect and transform a point
A point stored in Web Mercator can be displayed as WKT with ST_AsText and transformed to longitude and latitude with ST_Transform(way, 4326). Tampa’s sample point becomes POINT(-82.458444 27.947759499952074), which can then be inserted into an OpenStreetMap URL. section 10.5.1 section 10.3.1
Table 10.1 Postgres geometric data types
| Type name |
Description |
Input format |
|
|
A point on a 2D plane |
|
|
|
An infinite straight line in 2D space |
|
|
|
A finite line segment between two points |
|
|
|
A rectangle defined by two opposite corners |
|
|
|
An open or closed path defined as a sequence of connected points |
open path: closed path: |
|
|
A closed polygon with three or more points |
|
|
|
A circle with a center and a radius |
|
Browse the built-in Postgres geometric types, their spatial meanings, and accepted input formats. section 10.1.1
