From 328f276d07b5c9679aec4401202a0d9a6be7fa7d Mon Sep 17 00:00:00 2001 From: Guillem Borrell Nogueras Date: Fri, 11 Nov 2022 11:46:52 +0100 Subject: [PATCH] Update 'Dump OSM data to a postgis database' --- Dump-OSM-data-to-a-postgis-database.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Dump-OSM-data-to-a-postgis-database.md b/Dump-OSM-data-to-a-postgis-database.md index ff02766..6efaf34 100644 --- a/Dump-OSM-data-to-a-postgis-database.md +++ b/Dump-OSM-data-to-a-postgis-database.md @@ -92,4 +92,21 @@ wget https://download.openstreetmap.fr/extracts/north-america/mexico-latest.osm. sudo -u postgres osm2pgsql --create --database pgsnapshot --cache 20000 --number-processes 2 --slim -P 5435 --keep-coastlines --extra-attributes --hstore-all mexico-latest.osm.pbf ``` -Then change the postgresql.conf and pg_hba.conf files to allow remote connections to the database. \ No newline at end of file +Then change the postgresql.conf and pg_hba.conf files to allow remote connections to the database. + +## Interesting Postgis features + +You can compute minimum distances with KNN as follows: + +``` +select + st_distance(st_transform(st_setsrid(st_point(-120, 12), 4326), 3857), way) as distance +from + public.planet_osm_roads +where + highway in ('motorway', 'trunk', 'primary', 'secondary') +order by + st_transform(st_setsrid(st_point(-120, 12), 4326), 3857) <-> way +limit + 1 +``` \ No newline at end of file