liveBook · Manning

ST_Transform

As explained in Just Use Postgres!

ST_Transform is a PostGIS function that converts a geometry's coordinates to a specified spatial reference system.

ST_Transform converts a geometry’s coordinates into a specified spatial reference system and returns a new geometry. It is useful when projected coordinates must become longitude and latitude for GPS-style output. section 10.5.1

Convert Tampa’s point 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'; -- Tampa | POINT(-82.458444 27.947759499952074) section 10.5.1

Build an OpenStreetMap URL

Transform the stored point first, then extract its latitude and longitude: WITH tampa_city_point AS ( SELECT ST_Transform(way, 4326) AS coordinate FROM florida.planet_osm_point WHERE name = 'Tampa' AND place = 'city' ) SELECT 'https://www.openstreetmap.org/?mlat=' || ST_Y(coordinate) || '&mlon=' || ST_X(coordinate) AS osm_url FROM tampa_city_point; 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';

Browse the runnable query that transforms Tampa’s stored geometry to SRID 4326; the paired result shows the converted coordinates. section 10.5.1

How Just Use Postgres! covers it

How deep it goes
Defines the function and demonstrates SQL usage, but does not detail transformation internals or edge cases.
Examples
Uses Tampa’s city-center point and an OpenStreetMap URL as concrete transformation examples.
What it assumes
Assumes familiarity with PostGIS geometries and SRIDs while distinguishing coordinate transformation from assigning SRID metadata.
What you can do after
Apply it via PostGIS to produce latitude-longitude coordinates and construct an OpenStreetMap link.
How it connects
Links spatial reference systems, SRIDs, Web Mercator, latitude and longitude, and coordinate extraction.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.