mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Force polygons into validity during GIS import.
Not sure why, but some polygons become invalid (which usually means a self-intersecting "polygon", such as two triangles that meet at a point) during this transformation. Shapely includes a tool to reshape polygons into validity, so use that.
This commit is contained in:
parent
4bb60cb500
commit
1f4fd0fd04
@ -8,6 +8,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from pyproj import CRS, Transformer
|
from pyproj import CRS, Transformer
|
||||||
from shapefile import Reader, Shape
|
from shapefile import Reader, Shape
|
||||||
|
from shapely import validation
|
||||||
from shapely.geometry import LineString, MultiPolygon, Polygon, shape
|
from shapely.geometry import LineString, MultiPolygon, Polygon, shape
|
||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ class CoordinateConverter:
|
|||||||
for poly in polys:
|
for poly in polys:
|
||||||
for boundary, holes in self._boundary_and_holes_of(poly):
|
for boundary, holes in self._boundary_and_holes_of(poly):
|
||||||
new_polys.append(
|
new_polys.append(
|
||||||
|
validation.make_valid(
|
||||||
Polygon(
|
Polygon(
|
||||||
self._convert_line_to_dcs_coords(boundary),
|
self._convert_line_to_dcs_coords(boundary),
|
||||||
holes=[
|
holes=[
|
||||||
@ -53,6 +55,7 @@ class CoordinateConverter:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
return new_polys
|
return new_polys
|
||||||
|
|
||||||
def _transformer_for(self, projection_file: Path) -> Transformer:
|
def _transformer_for(self, projection_file: Path) -> Transformer:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user