Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created June 16, 2016 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/1f9f9600b52b3a1608b25ff72df0f6ff to your computer and use it in GitHub Desktop.
Save tommorris/1f9f9600b52b3a1608b25ff72df0f6ff to your computer and use it in GitHub Desktop.
osm2pgsql
# load pbf into postgres
osm2pgsql --create -H localhost --database osm ~/Downloads/great-britain-latest.osm.pbf -j -s
-- find restaurants nearby without cuisine tags
select name, osm_id, ST_AsGeoJSON(ST_Transform(way, 4326)) as geom, tags,
st_distance(ST_Transform(way, 4326), ST_GeomFromText('POINT(YOUR_LONG YOUR_LAT)', 4326)) as dist,
array_length(akeys(tags), 1) as tagc
from planet_osm_point
where (name is not null) and
(amenity = 'restaurant') and
(tags -> 'cuisine' is null) and
(array_length(akeys(tags), 1) = 2)
order by st_distance(ST_Transform(way, 4326),
ST_GeomFromText('POINT(YOUR_LONG YOUR_LAT)', 4326)
)
limit 30;
-- find named stuff that's nearby that needs more tags
select name, osm_id, ST_AsGeoJSON(ST_Transform(way, 4326)) as geom, tags,
st_distance(ST_Transform(way, 4326), ST_GeomFromText('POINT(YOUR_LONG YOUR_LAT)', 4326)) as dist,
array_length(akeys(tags), 1) as tagc
from planet_osm_point
where (name is not null) and
(array_length(akeys(tags), 1) = 1)
order by st_distance(ST_Transform(way, 4326),
ST_GeomFromText('POINT(YOUR_LONG YOUR_LAT)', 4326)
)
limit 30;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment