-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to pull OSM geometry data #4
Comments
To pull info from OSM, we can query it with Overpass. Overpass Turbo let's you interactively play around with and run some queries. This page has some example queries, and I used it to create an example that grabbed a particular Way ID:
We'll need to find someway to then insert it into our database, which may require something like osmtogeojson to convert it to geojson that can then be inserted into the database. |
Our Postgres parks database REST endpoint. So for instance, to get all of the rows in the parks table that have no geometry, you can hit this endpoint: That will give you the row id (in our database) and the osm_info (see the wiki for how that is structured) |
I've setup a basic instance of osmtogeojson. At the moment it requires the OSM JSON output from Overpass (use |
Took this Overpass Turbo query:
and turned it into a url to query Overpass and get JSON: |
SQL Query to update row example: UPDATE parks.parks SET geom = ST_Multi(ST_GeomFromGeoJSON
('{
"type":"Polygon",
"coordinates":
[
[
[1,1]
]
],
"crs":{"type":"name","properties":{"name":"EPSG:4326"}}
}'))
WHERE id = 7; |
Once you get the OSM data and convert it to geojson, we can insert it by running a couple of SQL statements (can probably be combined into one, or at least a function): SELECT ST_AsText(ST_Collect(ST_SetSRID(ST_GeomFromGeoJSON(feat->>'geometry'),4326)))
FROM (
SELECT json_array_elements('{
"type": "FeatureCollection",
"features": [...more geojson is here...]
}'::json->'features') AS feat
) AS f; And then taking that output and plugging it into something like: UPDATE parks.parks SET geom = ST_SetSRID(
ST_GeomFromText( 'GEOMETRYCOLLECTION( POLYGON...' ),
4326)
WHERE id = 1; |
I got the parks that had osm info filled with geom data. Check it out |
Here's the SQL to run at the end that will add/update the centroids for all of them: UPDATE parks.parks SET point_location = ST_Centroid(geom) WHERE geom IS NOT NULL; |
General steps for this component:
The text was updated successfully, but these errors were encountered: