Commit f6a2240b authored by Theophile Terraz's avatar Theophile Terraz
Browse files

wet_area and wet_perimeter

No related merge requests found
Pipeline #56684 passed with stages
in 57 seconds
Showing with 73 additions and 9 deletions
+73 -9
...@@ -356,3 +356,9 @@ class Profile(object): ...@@ -356,3 +356,9 @@ class Profile(object):
def wet_area(self, z): def wet_area(self, z):
raise NotImplementedMethodeError(self, self.wet_area) raise NotImplementedMethodeError(self, self.wet_area)
def wet_radius(self, z):
raise NotImplementedMethodeError(self, self.wet_radius)
def get_nb_wet_areas(self, z):
raise NotImplementedMethodeError(self, self.get_nb_wet_areas)
...@@ -402,19 +402,28 @@ class ProfileXYZ(Profile, SQLSubModel): ...@@ -402,19 +402,28 @@ class ProfileXYZ(Profile, SQLSubModel):
return abs(rg.dist(rd)) return abs(rg.dist(rd))
def wet_perimeter(self, z): def wet_perimeter(self, z):
line = self.wet_line(z) lines = self.wet_lines(z)
if line is None: if lines is None:
return 0 return 0
return line.length length = 0.0
for line in lines:
length += line.length
return length
def wet_area(self, z): def wet_area(self, z):
poly = self.wet_polygon(z) lines = self.wet_lines(z)
if poly is None: if lines is None:
return 0 return 0
area = 0.0
for line in lines:
poly = geometry.Polygon(line)
area += poly.area
return area
return poly.area return poly.area
def wet_radius(self, z): def wet_radius(self, z):
...@@ -431,21 +440,57 @@ class ProfileXYZ(Profile, SQLSubModel): ...@@ -431,21 +440,57 @@ class ProfileXYZ(Profile, SQLSubModel):
if len(points) < 3: if len(points) < 3:
return None return None
z = map(lambda p: p.z, points) zz = map(lambda p: p.z, points)
station = self._get_station(points) station = self._get_station(points)
line = geometry.LineString(list(zip(station, z))) line = geometry.LineString(list(zip(station, zz)))
return line return line
def wet_lines(self, z):
points = self._points
if len(points) < 3:
return None
lines = []
zz = list(map(lambda p: p.z, points))
station = self._get_station(points)
line = []
for i in range(self.number_points-1):
if zz[i] >= z and zz[i+1] < z:
y = np.interp(
z,
[zz[i], zz[i+1]],
[station[i], station[i+1]]
)
line.append([y,z])
if zz[i] < z:
line.append([station[i],zz[i]])
if zz[i] <= z and zz[i+1] > z:
y = np.interp(
z,
[zz[i], zz[i+1]],
[station[i], station[i+1]]
)
line.append([y,z])
lines.append(geometry.LineString(line))
line = []
return lines
def wet_polygon(self, z): def wet_polygon(self, z):
points = self.wet_points(z) points = self.wet_points(z)
if len(points) < 3: if len(points) < 3:
return None return None
z = map(lambda p: p.z, points) zz = map(lambda p: p.z, points)
station = self._get_station(points) station = self._get_station(points)
poly = geometry.Polygon(list(zip(station, z))) poly = geometry.Polygon(list(zip(station, zz)))
return poly return poly
def wet_points(self, z): def wet_points(self, z):
...@@ -457,6 +502,19 @@ class ProfileXYZ(Profile, SQLSubModel): ...@@ -457,6 +502,19 @@ class ProfileXYZ(Profile, SQLSubModel):
return points return points
def get_nb_wet_areas(self, z):
n_zones = 0
points = self._points
if points[0].z <= z:
n_zones += 1
for i in range(self.number_points-1):
if points[i].z > z and points[i+1].z <= z:
n_zones += 1
return n_zones
def get_water_limits(self, z): def get_water_limits(self, z):
""" """
Determine left and right limits of water elevation. Determine left and right limits of water elevation.
......
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