Is there a way to merge two overlapping GEOJSON polygons in python, returning a single merged GEOJSON object?
You could try using this python script, to merge. Add the geojson into QGIS, convert to shapefile, edit/merge features, and finally export back out to geojson. Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
First, starting from the inside, json.loads () loads our geojson string into a python object. shape () then turns this into a shapely feature, a Multipolygon in this case. buffer (0) on this object corrects any invalid geometry (for example, turning a single-part bowtie into a multipolygon).
It is listed on PyPi as ‘geojson’. The recommended way to install is via pip: pip install geojson GeoJSON Objects¶ This library implements all the GeoJSON Objectsdescribed in The GeoJSON Format Specification.
Instantly share code, notes, and snippets. Group multiple GeoJSON files into one output file. . Already have an account?
This example from here seems to be a lot more concise:
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
polygon1 = Polygon([(0, 0), (5, 3), (5, 0)])
polygon2 = Polygon([(0, 0), (3, 10), (3, 0)])
polygons = [polygon1, polygon2]
u = cascaded_union(polygons)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With