This commit is contained in:
Marius Stanciu
2022-05-09 14:18:49 +03:00
committed by Marius
parent 411a9320e5
commit 9dc6c94a45
3 changed files with 34 additions and 7 deletions

View File

@@ -186,10 +186,38 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0):
geo_element = Polygon(rings.geoms[0])
else:
geo_element = LineString(rings.geoms[0])
geometry.append(geo_element)
else:
try:
geo_element = Polygon(rings.geoms[0], rings.geoms[1:])
except Exception:
poly_list = [Polygon(line.coords) for line in rings.geoms]
# if len(poly_list) == 2:
# if poly_list[0].contains(poly_list[1]):
# geo_element = Polygon(rings.geoms[0], rings.geoms[1:])
# geometry.append(geo_element)
# else:
# geometry = poly_list
# else:
# geo_element = Polygon(rings.geoms[0], rings.geoms[1:])
# geometry.append(geo_element)
contained = []
not_contained = []
if len(poly_list) > 1:
for p in poly_list[1:-1]:
if poly_list[0].contains(p):
contained.append(p)
else:
not_contained.append(p)
else:
not_contained = poly_list
if not_contained:
geometry += [poly_list[0]]
geometry += not_contained
if contained:
geo_element = Polygon(poly_list[0].exterior, [p.exterior for p in contained])
geometry.append(geo_element)
except Exception as err:
coords = []
for line in rings.geoms:
coords.append(line.coords[0])
@@ -198,7 +226,7 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0):
geo_element = Polygon(coords)
except Exception:
geo_element = LineString(coords)
geometry.append(geo_element)
geometry.append(geo_element)
return geometry