-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: convert MultiPolygons to Polygons (LAN-794)
Water Body: Leaflet Draw doesn't support editing the MutiPolygons (imported from the former GIS), so we need to convert them to Polygons.
- Loading branch information
1 parent
29d5bf6
commit cedf00b
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
|
||
import frappe | ||
|
||
|
||
def execute(): | ||
""" | ||
Water Body: convert all MultiPolygons to Polygons in the geo shapes. | ||
Leaflet Draw doesn't support editing the MutiPolygons (imported from the | ||
former GIS), so we need to convert them to Polygons. | ||
""" | ||
for wb_name in frappe.get_all( | ||
"Water Body", filters={"location": ("like", "%MultiPolygon%")}, pluck="name" | ||
): | ||
geojson_str = frappe.db.get_value("Water Body", wb_name, "location") | ||
geojson = json.loads(geojson_str) | ||
|
||
if "features" not in geojson: | ||
continue | ||
|
||
features = [] | ||
modified = False | ||
for feature in geojson["features"]: | ||
if feature["geometry"]["type"] != "MultiPolygon": | ||
features.append(feature) | ||
else: | ||
features.extend( | ||
{ | ||
"type": "Feature", | ||
"geometry": {"type": "Polygon", "coordinates": polygon}, | ||
"properties": feature["properties"], | ||
} | ||
for polygon in feature["geometry"]["coordinates"] | ||
) | ||
modified = True | ||
|
||
if modified: | ||
geojson["features"] = features | ||
frappe.db.set_value("Water Body", wb_name, "location", json.dumps(geojson)) |