A spatial reference system defines how coordinates represent geographic locations and how spatial operations interpret their units. In PostGIS, geometries carry an SRID identifying that system. section 10.5.1
Use these PostGIS functions to assign, convert, inspect, and compare spatial coordinates:
- ST_SetSRID assigns SRID metadata without changing coordinate values. section 10.5.1
- ST_Transform creates a geometry in another spatial reference system and converts its coordinates. section 10.5.1
- ST_Distance and ST_DWithin interpret distances using the geometries’ spatial reference system units. section 10.5.1
Convert a city point to longitude and latitude
SELECT name, ST_AsText(ST_Transform(way, 4326)) AS coordinates FROM florida.planet_osm_point WHERE name = 'Tampa' AND place = 'city'; returns POINT(-82.458444 27.947759499952074). section 10.5.1
Listing 10.12 Transforming coordinates to latitude and longitude
SELECT name, ST_AsText(ST_Transform(way, 4326)) AS coordinates FROM florida.planet_osm_point WHERE name = 'Tampa' and place = 'city';
Inspect the runnable query that transforms stored coordinates into latitude-and-longitude form. section 10.5.1
