liveBook · Manning

ST_SetSRID

As explained in Just Use Postgres!

ST_SetSRID is a PostGIS function that assigns spatial reference system metadata to a geometry without changing its coordinates.

ST_SetSRID assigns an SRID to a geometry as metadata without changing its coordinates. It is especially useful after creating a point with ST_MakePoint. section 10.5.1

Create a point for distance searches

WITH roost_hotel AS ( SELECT ST_SetSRID( ST_MakePoint(-9178356.224987695, 3242002.0503882724), 3857) AS point ) SELECT p.name, p.amenity, round(ST_Distance(h.point, p.way)) AS distance_meters, round(ST_Distance(h.point, p.way) * 3.28) AS distance_feet FROM roost_hotel AS h JOIN florida.planet_osm_point AS p ON ST_DWithin(h.point, p.way, 500) WHERE p.amenity = 'restaurant' ORDER BY distance_meters LIMIT 5; The query returns Wagamama at 68 meters, followed by Boulon Brasserie at 132 meters. section 10.5.1

How Just Use Postgres! covers it

How deep it goes
Defines metadata assignment and demonstrates a complete query, while stopping short of coordinate transformation.
Examples
Demonstrates a Roost Apartment Hotel point and returns five nearby restaurants with meter and feet distances.
What it assumes
Assumes familiarity with geometries, coordinate pairs, SRIDs, and basic PostGIS spatial queries.
What you can do after
Apply it via PostGIS to label constructed coordinates and run spatial proximity queries.
How it connects
Connects ST_MakePoint with ST_DWithin and ST_Distance for proximity searches, and distinguishes them from ST_Transform.

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.