aspectumapp / osm2geojson

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

Convert shapes to geojson #13

Closed stephen-lazarionok closed 4 years ago

stephen-lazarionok commented 4 years ago

Is there any way to convert shapes to geojson. I am looking for a way where I can manipulate with shapes and then create the geojson.

rapkin commented 4 years ago

You can use method shape_to_feature.

import codecs
import osm2geojson

with codecs.open('file.json', 'r', encoding='utf-8') as data:
    json = data.read()

shapes_with_props = osm2geojson.json2shapes(json)
item = shapes_with_props[0]

geojson_feature = osm2geojson.shape_to_feature(item['shape'], item['properties'])
# {type: 'Feature', ...}