Created
October 20, 2023 14:07
-
-
Save ahmadpoorgholam/026fea985a3b814948bfa0b25247bbf2 to your computer and use it in GitHub Desktop.
convet_ploygon_to_multipolygon.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shapely.geometry import shape, MultiPolygon | |
# JSON representation of a single Polygon | |
polygon_json = { | |
"type": "Polygon", | |
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] | |
} | |
# Convert the JSON representation to a Shapely Polygon | |
polygon = shape(polygon_json) | |
# Convert the single Polygon to a MultiPolygon | |
multi_polygon = MultiPolygon([polygon]) | |
# Get the JSON representation of the MultiPolygon | |
multi_polygon_json = multi_polygon.__geo_interface__ | |
# Print the MultiPolygon JSON representation | |
print(multi_polygon_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment