avoid shapely deprecation warnings
This commit is contained in:
parent
8f4f6aed6e
commit
495294a886
5 changed files with 9 additions and 18 deletions
|
@ -115,11 +115,11 @@ class GeometryMixin(SerializableMixin):
|
||||||
return True
|
return True
|
||||||
if self.geometry is self.orig_geometry:
|
if self.geometry is self.orig_geometry:
|
||||||
return False
|
return False
|
||||||
if not self.geometry.almost_equals(self.orig_geometry, 1):
|
if not self.geometry.equals_exact(self.orig_geometry, 0.05):
|
||||||
return True
|
return True
|
||||||
field = self._meta.get_field('geometry')
|
field = self._meta.get_field('geometry')
|
||||||
rounded = field.to_python(field.get_prep_value(self.geometry))
|
rounded = field.to_python(field.get_prep_value(self.geometry))
|
||||||
if not rounded.almost_equals(self.orig_geometry, 2):
|
if not rounded.equals_exact(self.orig_geometry, 0.005):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -189,8 +189,8 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
||||||
if self.altitude2 is None:
|
if self.altitude2 is None:
|
||||||
return np.full((points.shape[0], ), fill_value=float(self.altitude))
|
return np.full((points.shape[0], ), fill_value=float(self.altitude))
|
||||||
|
|
||||||
slope = np.array(self.point2) - np.array(self.point1)
|
slope = np.array(self.point2.coords) - np.array(self.point1.coords)
|
||||||
distances = (np.sum(((points - np.array(self.point1)) * slope), axis=1) / (slope ** 2).sum()).clip(0, 1)
|
distances = (np.sum(((points - np.array(self.point1.coords)) * slope), axis=1) / (slope ** 2).sum()).clip(0, 1)
|
||||||
|
|
||||||
if self.altitude2 < self.altitude:
|
if self.altitude2 < self.altitude:
|
||||||
min_altitude = float(self.altitude2)
|
min_altitude = float(self.altitude2)
|
||||||
|
@ -604,7 +604,7 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
||||||
num_deleted += 1
|
num_deleted += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not field.get_final_value(new_area.geometry).almost_equals(candidate.geometry):
|
if not field.get_final_value(new_area.geometry).equals_exact(candidate.geometry, 0.00001):
|
||||||
num_modified += 1
|
num_modified += 1
|
||||||
|
|
||||||
candidate.geometry = new_area.geometry
|
candidate.geometry = new_area.geometry
|
||||||
|
|
|
@ -149,12 +149,12 @@ class SVGEngine(RenderEngine):
|
||||||
if isinstance(geom, Polygon):
|
if isinstance(geom, Polygon):
|
||||||
return ('<path d="' +
|
return ('<path d="' +
|
||||||
' '.join((('M %.1f %.1f L'+(' %.1f %.1f'*(len(ring.coords)-1))+' z') %
|
' '.join((('M %.1f %.1f L'+(' %.1f %.1f'*(len(ring.coords)-1))+' z') %
|
||||||
tuple((np.array(ring)*self.np_scale+self.np_offset).flatten()))
|
tuple((np.array(ring.coords)*self.np_scale+self.np_offset).flatten()))
|
||||||
for ring in chain((geom.exterior,), geom.interiors))
|
for ring in chain((geom.exterior,), geom.interiors))
|
||||||
+ '"/>').replace('.0 ', ' ')
|
+ '"/>').replace('.0 ', ' ')
|
||||||
if isinstance(geom, LineString):
|
if isinstance(geom, LineString):
|
||||||
return (('<path d="M %.1f %.1f L'+(' %.1f %.1f'*(len(geom.coords)-1))+'"/>') %
|
return (('<path d="M %.1f %.1f L'+(' %.1f %.1f'*(len(geom.coords)-1))+'"/>') %
|
||||||
tuple((np.array(geom)*self.np_scale+self.np_offset).flatten())).replace('.0 ', ' ')
|
tuple((np.array(geom.coords)*self.np_scale+self.np_offset).flatten())).replace('.0 ', ' ')
|
||||||
try:
|
try:
|
||||||
geoms = geom.geoms
|
geoms = geom.geoms
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import math
|
import math
|
||||||
from collections import deque, namedtuple
|
from collections import deque, namedtuple
|
||||||
from contextlib import suppress
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from typing import List, Sequence, Union
|
from typing import List, Sequence, Union
|
||||||
|
|
||||||
|
@ -199,11 +198,7 @@ def cut_polygon_with_line(polygon: Union[Polygon, MultiPolygon, Sequence[Polygon
|
||||||
polygons: List[List[LinearRing]] = []
|
polygons: List[List[LinearRing]] = []
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
for polygon in orig_polygon:
|
for polygon in orig_polygon:
|
||||||
rings = getattr(polygon, 'c3nav_cache', None)
|
polygons.append([polygon.exterior, *polygon.interiors])
|
||||||
if not rings:
|
|
||||||
rings = [polygon.exterior, *polygon.interiors]
|
|
||||||
polygon.c3nav_cache = rings
|
|
||||||
polygons.append(rings)
|
|
||||||
|
|
||||||
# find intersection points between the line and polygon rings
|
# find intersection points between the line and polygon rings
|
||||||
points = deque()
|
points = deque()
|
||||||
|
@ -339,7 +334,6 @@ def cut_polygon_with_line(polygon: Union[Polygon, MultiPolygon, Sequence[Polygon
|
||||||
for polygon in polygons:
|
for polygon in polygons:
|
||||||
polygon = [ring for ring in polygon if ring is not None]
|
polygon = [ring for ring in polygon if ring is not None]
|
||||||
new_polygon = Polygon(polygon[0], tuple(polygon[1:]))
|
new_polygon = Polygon(polygon[0], tuple(polygon[1:]))
|
||||||
new_polygon.c3nav_cache = polygon
|
|
||||||
result.append(new_polygon)
|
result.append(new_polygon)
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
|
@ -349,9 +343,6 @@ def clean_cut_polygon(polygon: Polygon) -> Polygon:
|
||||||
interiors.extend(cut_ring(polygon.exterior))
|
interiors.extend(cut_ring(polygon.exterior))
|
||||||
exteriors = [(i, ring) for (i, ring) in enumerate(interiors) if ring.is_ccw]
|
exteriors = [(i, ring) for (i, ring) in enumerate(interiors) if ring.is_ccw]
|
||||||
|
|
||||||
with suppress(AttributeError):
|
|
||||||
delattr(polygon, 'c3nav_cache')
|
|
||||||
|
|
||||||
if len(exteriors) != 1:
|
if len(exteriors) != 1:
|
||||||
raise ValueError('Invalid cut polygon!')
|
raise ValueError('Invalid cut polygon!')
|
||||||
exterior = interiors[exteriors[0][0]]
|
exterior = interiors[exteriors[0][0]]
|
||||||
|
|
|
@ -109,5 +109,5 @@ def shapely_to_mpl(geometry):
|
||||||
|
|
||||||
|
|
||||||
def linearring_to_mpl_path(linearring):
|
def linearring_to_mpl_path(linearring):
|
||||||
return Path(np.array(linearring),
|
return Path(np.array(linearring.coords),
|
||||||
(Path.MOVETO, *([Path.LINETO] * (len(linearring.coords)-2)), Path.CLOSEPOLY), readonly=True)
|
(Path.MOVETO, *([Path.LINETO] * (len(linearring.coords)-2)), Path.CLOSEPOLY), readonly=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue