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