How do I remove water from OpenStreetMap?

I would like to get the San Francisco plan from OpenStreetMap. There is a relation for SF , but it includes a large amount of water that would make it unrecognizable for a city dweller:

Outline of SF from OSM

Is there a better training ground for San Francisco at OSM? Are there ways for coastlines, and if so, how can I find and subtract them from the ABL?

+3


source to share


2 answers


I was able to do this using osmtogeojson and ogr2ogr . I first grabbed the full XML OSM for the San Francisco relationship and converted it to GeoJSON:

$ curl 'http://www.openstreetmap.org/api/0.6/relation/111968/full' > sf.osm
$ osmtogeojson sf.osm > sf.json

      

Then I removed the non-polygonal functions using this script :

$ only_polygons.py sf.json > sf.polygons.json

      

Then I downloaded the land polygons file that Tordanik referenced and managed:



$ ogr2ogr land_polygons.sfbbox.shp -clipsrc -122.56 37.68 -122.27 37.939 land-polygons-complete-4326/land_polygons.shp
$ ogr2ogr -f GeoJSON sf-land.json -clipsrc sf.polygons.json land_polygons.sfbbox.shp

      

This creates a GeoJSON ( sf-land.json

) file with San Francisco land boundaries:

SF boundary, snug to the coastline

I don't know where the Farallon Islands went, but it mostly works!

Each step is fast, except for the first command ogr2ogr

, which copies the ground polygons into the bounding box containing San Francisco. It took about 2 minutes on my MacBook Pro. This path was significantly faster than passing sf.polygons.json directly as an argument -clipsrc

to the first command.

+3


source


Yes, there are ways for the coastline . For example this path , which is also part of the relationship, but also in a way that is obviously not part of the relationship. Therefore, I find it very difficult to mechanically remove all the water and small islands, but it is not possible. I think you would need to restore the entire data map inside the polygon and run some spatial queries.



The attitude you are looking at defines the administrative boundary line of San Francisco. The attitude you're looking for is San Francisco land with no water (and probably no small islands owned by San Francisco). Such relationships do not usually exist in OSM.

+1


source







All Articles