mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Geometry: Add shapefile import file format.
This commit is contained in:
1 parent
fd1b2b1041
commit
e528ba5278
4 files changed
+57
-1
No files matched your search
@@ -16,7 +16,9 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
import shapefile
|
||||
import numpy as np
|
||||
|
||||
from time import time
|
||||
@@ -533,8 +535,58 @@ class Reach(SQLSubModel):
|
||||
|
||||
# Import/Export
|
||||
|
||||
@timer
|
||||
def import_geometry(self, file_path_name: str):
|
||||
if file_path_name.endswith(".st"):
|
||||
return self.import_geometry_st(file_path_name)
|
||||
elif file_path_name.endswith(".shp"):
|
||||
return self.import_geometry_shp(file_path_name)
|
||||
else:
|
||||
return []
|
||||
|
||||
@timer
|
||||
def import_geometry_shp(self, file_path_name: str):
|
||||
sf = shapefile.Reader(
|
||||
os.path.abspath(file_path_name)
|
||||
)
|
||||
|
||||
if sf.shapeType != shapefile.POLYLINEZ:
|
||||
raise FileFormatError(
|
||||
file_path_name,
|
||||
"Shapefile is not a POLYLINEZ"
|
||||
)
|
||||
|
||||
profiles = []
|
||||
|
||||
for i in range(len(sf)):
|
||||
s_profile = sf.shape(i)
|
||||
z = s_profile.z
|
||||
|
||||
ind = 0
|
||||
points = []
|
||||
for point in s_profile.points:
|
||||
points.append([
|
||||
point[0],
|
||||
point[1],
|
||||
z[ind]
|
||||
])
|
||||
|
||||
ind += 1
|
||||
|
||||
prof = ProfileXYZ(
|
||||
kp=round(points[0][0]),
|
||||
reach=self, status=self._status
|
||||
)
|
||||
prof.import_points(points)
|
||||
|
||||
profiles.append(prof)
|
||||
|
||||
self.profiles = profiles + self.profiles
|
||||
self._update_profile_numbers()
|
||||
|
||||
return profiles
|
||||
|
||||
@timer
|
||||
def import_geometry_st(self, file_path_name: str):
|
||||
"""Import a geometry from file (.ST or .st)
|
||||
|
||||
Args:
|
||||
|
||||
Reference in new issue
Block a user