Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging two GEOJSON polygons in Python

Tags:

python

geojson

Is there a way to merge two overlapping GEOJSON polygons in python, returning a single merged GEOJSON object?

like image 907
traggatmot Avatar asked Dec 17 '15 01:12

traggatmot


People also ask

How to merge GeoJSON with QGIS?

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!

How to turn a string into a multipolygon in Python?

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).

How do I install GeoJSON on PyPI?

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.

What can I do with GeoJSON?

Instantly share code, notes, and snippets. Group multiple GeoJSON files into one output file. . Already have an account?


1 Answers

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)
like image 160
Luke Madhanga Avatar answered Sep 19 '22 16:09

Luke Madhanga