Commit 8c2874e0 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Geometry: Compute KP at shape file import.

Showing with 39 additions and 2 deletions
+39 -2
...@@ -192,6 +192,22 @@ class PointXYZ(Point, SQLSubModel): ...@@ -192,6 +192,22 @@ class PointXYZ(Point, SQLSubModel):
def dist(self, p2): def dist(self, p2):
return PointXYZ.distance(self, p2) return PointXYZ.distance(self, p2)
def dist_2d(self, p2):
return PointXYZ.distance_2d(self, p2)
@staticmethod
def distance_2d(p1, p2):
"""Euclidean distance between p1 and p2.
Args:
p1: A XYZ Point
p2: A XYZ Point
Returns:
Euclidean 2D distance between the two points
"""
return dist((p1.x, p1.y), (p2.x, p2.y))
@staticmethod @staticmethod
def distance(p1, p2): def distance(p1, p2):
"""Euclidean distance between p1 and p2. """Euclidean distance between p1 and p2.
...@@ -201,6 +217,6 @@ class PointXYZ(Point, SQLSubModel): ...@@ -201,6 +217,6 @@ class PointXYZ(Point, SQLSubModel):
p2: A XYZ Point p2: A XYZ Point
Returns: Returns:
Euclidean distance between the two points Euclidean 3D distance between the two points
""" """
return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z)) return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z))
...@@ -573,7 +573,6 @@ class Reach(SQLSubModel): ...@@ -573,7 +573,6 @@ class Reach(SQLSubModel):
ind += 1 ind += 1
prof = ProfileXYZ( prof = ProfileXYZ(
kp=round(points[0][0]),
reach=self, status=self._status reach=self, status=self._status
) )
prof.import_points(points) prof.import_points(points)
...@@ -582,6 +581,7 @@ class Reach(SQLSubModel): ...@@ -582,6 +581,7 @@ class Reach(SQLSubModel):
self.profiles = profiles + self.profiles self.profiles = profiles + self.profiles
self._update_profile_numbers() self._update_profile_numbers()
self._recompute_kp()
return profiles return profiles
...@@ -814,3 +814,24 @@ class Reach(SQLSubModel): ...@@ -814,3 +814,24 @@ class Reach(SQLSubModel):
except Exception as e: except Exception as e:
logger_exception(e) logger_exception(e)
return 0 return 0
def _recompute_kp(self, offset=0.0):
self._recompute_kp_no_gl(offset=offset)
def _recompute_kp_no_gl(self, offset=0.0):
profiles = iter(self.profiles)
previous = next(profiles)
previous.kp = offset
for profile in profiles:
prev_points = previous.points
curr_points = profile.points
dist = (
prev_points[0].dist_2d(curr_points[0]) +
prev_points[-1].dist_2d(curr_points[-1])
) / 2.0
profile.kp = previous.kp + dist
previous = profile
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment