implement AltitudeArea.get_altitudes() for multiple points
This commit is contained in:
parent
732cd8a4ea
commit
27ba0c0eaa
1 changed files with 19 additions and 13 deletions
|
@ -208,23 +208,29 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
||||||
|
|
||||||
def get_altitudes(self, points):
|
def get_altitudes(self, points):
|
||||||
points = np.asanyarray(points).reshape((-1, 2))
|
points = np.asanyarray(points).reshape((-1, 2))
|
||||||
if self.altitude2 is None:
|
if self.altitude is not 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.coords) - np.array(self.point1.coords)
|
if len(self.points) == 1:
|
||||||
distances = (np.sum(((points - np.array(self.point1.coords)) * slope), axis=1) / (slope ** 2).sum()).clip(0, 1)
|
raise ValueError
|
||||||
|
|
||||||
if self.altitude2 < self.altitude:
|
max_altitude = max(p.altitude for p in self.points)
|
||||||
min_altitude = float(self.altitude2)
|
min_altitude = min(p.altitude for p in self.points)
|
||||||
max_altitude = float(self.altitude)
|
|
||||||
|
if len(self.points) == 2:
|
||||||
|
slope = np.array(self.points[1].coordinates) - np.array(self.points[0].coordinates)
|
||||||
|
distances = (
|
||||||
|
(np.sum(((points - np.array(self.points[0].coordinates)) * slope), axis=1)
|
||||||
|
/ (slope ** 2).sum()).clip(0, 1)
|
||||||
|
)
|
||||||
|
altitudes = self.points[0].altitude + distances*(self.points[1].altitude-self.points[0].altitude)
|
||||||
else:
|
else:
|
||||||
min_altitude = float(self.altitude)
|
altitudes = RBFInterpolator(
|
||||||
max_altitude = float(self.altitude2)
|
np.array([p.coordinates for p in self.points]),
|
||||||
|
np.array([p.altitude for p in self.points])
|
||||||
|
)(points)
|
||||||
|
|
||||||
return np.clip(
|
return np.clip(altitudes, a_min=min_altitude, a_max=max_altitude)
|
||||||
float(self.altitude) + distances*(float(self.altitude2)-float(self.altitude)),
|
|
||||||
a_min=min_altitude, a_max=max_altitude
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def recalculate(cls):
|
def recalculate(cls):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue