liveBook · Manning

Point

As explained in Just Use Postgres!

Point is a PostGIS geometric subtype representing a single position with coordinate values.

A Point is a PostGIS geometry subtype representing one position through X and Y coordinates in a selected coordinate system. Points model cities, landmarks, restaurants, hotels, and other locations. section 10.1.2 section 10.1

Use these PostGIS functions to create, inspect, transform, and compare points:

  • Create a point with ST_MakePoint(x, y), then assign its spatial reference metadata with ST_SetSRID. section 10.5.1
  • Transform coordinates with ST_Transform; extract coordinates with ST_X and ST_Y. section 10.5.1
  • Find nearby points with ST_DWithin and calculate planar distance with ST_Distance. section 10.5.1

Find restaurants near a hotel

A point stored in Web Mercator can be used directly for proximity searches. This query selects restaurants within 500 meters, orders them by distance, and returns the five closest results: WITH roost_hotel AS ( SELECT way FROM florida.planet_osm_point WHERE name = 'Roost Apartment Hotel' AND tourism = 'hotel' ) SELECT p.name, p.amenity, round(ST_Distance(h.way, p.way)) AS distance_meters FROM roost_hotel AS h JOIN florida.planet_osm_point AS p ON ST_DWithin(h.way, p.way, 500) WHERE p.amenity = 'restaurant' ORDER BY distance_meters LIMIT 5; The results include Wagamama at 68 meters and Boulon Brasserie at 132 meters. section 10.5.1

Listing 10.11 Searching for the center of Tampa
SELECT name, ST_AsText(way) AS coordinates
FROM florida.planet_osm_point
WHERE name = 'Tampa' and place = 'city';

Inspect the Tampa city point as readable WKT before transforming its Web Mercator coordinates to longitude and latitude. section 10.5.1

How Just Use Postgres! covers it

How deep it goes
Explains subtype declarations, coordinate systems, construction, transformation, coordinate extraction, and planar proximity queries without covering indexing internals.
Examples
Uses Tampa city coordinates, OpenStreetMap URLs, Miami coordinates, and restaurants near the Roost Apartment Hotel.
What it assumes
Assumes basic SQL and introduces geometry subtypes, X/Y coordinates, SRIDs, and planar distance units.
What you can do after
Apply PostGIS functions to create points, transform coordinate systems, extract coordinates, and find nearby locations.
How it connects
Connects Point with PostGIS geometry, geography, SRID, Web Mercator, coordinate systems, and spatial distance functions.

Also explained in

Compare how 4 books explain point →

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.