aspectumapp / osm2geojson

Convert OSM and Overpass XML/JSON to GeoJSON
MIT License
100 stars 14 forks source link

How does the libary handle lines/polygons/nodes in the same relation? #16

Closed thagorx closed 3 years ago

thagorx commented 3 years ago

hey I stumbled upon this library and was wondering how does it handle a relation that contains multiple different types of geometry ?

cheers.

rapkin commented 3 years ago

Can you give me example?

thagorx commented 3 years ago

relation 1899923 for example has nodes, lines and polygons

rapkin commented 3 years ago

Ok, I made overpass query https://overpass-turbo.eu/s/132c

Converted JSON-data to GeoJSON:

import json
import codecs
from osm2geojson import json2geojson

def read_data_file(path):
    with codecs.open(path, 'r', encoding='utf-8') as data:
        return data.read()

json_data = json.loads(read_data_file('./data_from_overpass.json'))
geo_data = json2geojson(json_data)
f = open('./result.geojson', 'w')
f.write(json.dumps(geo_data, indent=2))
f.close()

And I see all geometry (1 polygon, lines and points) in result file.

Also I compared result with overpass map

image

image

You can see more points (osm2geojson converts all geometry without filtration), but you can easily filter them by tags.

Did it help you?

thagorx commented 3 years ago

Yes this helps kind of :D my issues actually is a more complex dataset: https://overpass-turbo.eu/s/134p when I try to parse it with json2geojson the library throws a couple of Failed to convert relation to shape before it fails with KeyError: 'lon' so my assumption was that there might be a problem with handling multi geometry relation. But since then I wrote a parsers myself and I think the issue is rather, that for some relation not all sub elements are retrieved with Overpass QL.

rapkin commented 3 years ago

Yes. Overpass can send partial data. But problem with KeyError: 'lon' looks suspicious. I think that lib should return all valid geometry if it possible, so I'll try to reproduce this issue

rapkin commented 3 years ago

I found problem with ids (in your example we have node with id 26763057 and way with id 26763057) - that was root of problems. I'm working on fix now.

thagorx commented 3 years ago

Yeah ids are only unique within each geometry type