get coastline polygons from osm data file

Hi:

i want to get coastline data (in osm defined as spring mean high water level) from an exported osm data file to mask out the land part in an equidistant lon lat grid. I only need the water part and set the land area to some fillvalue. If i can get the polygons for the land (or sea) part i can check whether a point in my equidistant lon lat grid is water or land. This should basically pretty simply stuff.

Yesterday i made a python script which gets lon lat information from the osm file, eg:
<node id=“9351882” lat=“55.0150278” lon=“8.4262778”

This has worked nicely and i made a plot where i can see the coastline. But there seems to be too much information which i don’t need, for example ferry lines or forest data.

Then i found the information that is the tag for the coastline.

Then this includes the following information where suddently lon/lat is missing. I see values as ref=1455316585 which i cannot interpret:






</way

Is there any mathematical formulation which i can apply to my python script to convert those values to lon/lat?

Many thanks in advance!
Hannes

Hi, now i understand what is meant by ref=. This points to a node which comes with lon/lat.

Basically one has to get the following data from the osm file:
natural=coastline
natural=beach
natural=cliff
natural=wetland
wetland=tidalflat
wetland=mangrove
man_made=groyne

I’ll write that python script and will post it here. Maybe some other might find that useful. Basically the script reads netcdf data of a lon/lat array and returns netcdf data with the masked lon/lat field. The final lon/lat grid is then used by a hydrodynamical model.

Hannes

Hi,

yesterday i successfully converted the coastline for Sylt Island (Germany) from an .osm file into a masked array with 1 for sea and 0 for land. This masked array can be exported either to ascii or netcdf. The output is a equidistant lon-lat field with a resolution defined by the user. I’m using that netcdf file to mask out land area in my bathymetry for a hydrodynamic numerical model.

The code is written in python.

The first script extracts coastline data from an .osm file (extracted from the ‘extract’ option on openstreetmap.org) and saves each coastline data set (polygone) to ascii. The input to the second script is (i) the desired lon/lat array (WGS84) with the individual resolution needed and (ii) the coastline polygones obtained by the first script. Then the second script uses the “Ray Casting Method” whether a given lon lat position is inside the coastline polygone which would then be a land point.

That’s it. If anybody needs the script please send a mail via the forum. Maybe i even post the scripts here.

Hannes

hi again:

here is the coastline (or land-sea matrix) of sylt island derived from openstreetmap data and converted to netcdf:
http://dl.dropbox.com/u/101655359/sylt_openstreetmap.nc

Of course there are still some corrections needed, maybe to fix via satellite images on google maps (applying a kmz file). One can see a polygon that is not correct in the thin dam to the east:
http://dl.dropbox.com/u/101655359/sylt_openstreetmap.png

apart from using google maps, openstreetmap seems the best source in getting high resolution coastline data for most places in the world which can be easily extracted as .osm.

Hannes