Skip to content

Commit

Permalink
#11 Add determination of branch_id and offset in 'branch_to_prof' method
Browse files Browse the repository at this point in the history
  • Loading branch information
rhutten committed Nov 23, 2020
1 parent b1caaa9 commit 3348cea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
18 changes: 15 additions & 3 deletions delft3dfmpy/datamodels/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class ExtendedGeoDataFrame(gpd.GeoDataFrame):
# normal properties
_metadata = ['required_columns', 'geotype'] + gpd.GeoDataFrame._metadata

def __init__(self, geotype, required_columns=None, *args, **kwargs):
def __init__(self, geotype, required_columns=None,logger=logging, *args, **kwargs):

# Add logger object to self
# FIXME: logging below results in error
#self.logger = logger

# Check type
if required_columns is None:
Expand Down Expand Up @@ -339,15 +343,23 @@ def check_projection(self, crs_out):
logger.info(f'OSM data has same projection as projected crs in ini-file')

def branch_to_prof(self, offset=0., vertex_end=False, rename_col=None, prefix='', suffix=''):
"""Create profiles on branches from branch data"""

gdf_out = self.copy()

# interpolate over feature geometries
if vertex_end:
p = self.interpolate(self.length - offset)
chainage = self.length - offset
p = self.interpolate(chainage)
else:
p = self.interpolate(offset)
chainage = offset
p = self.interpolate(chainage)
gdf_out.geometry = p
gdf_out['offset'] = chainage

if rename_col is not None:
try:
gdf_out['branch_id'] = gdf_out[rename_col]
gdf_out[rename_col] = [f'{prefix}{g[1][rename_col]}{suffix}' for g in self.iterrows()]
except:
raise ValueError(f"Column rename with '{rename_col}' did not succeed.")
Expand Down
9 changes: 0 additions & 9 deletions delft3dfmpy/datamodels/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ def __init__(self, extent_file=None, data_columns=None, proj_crs = None, logger=
# FIXME: check available columns and required columns for the OSM data, and apply these here
self.branches = ExtendedGeoDataFrame(geotype=LineString, required_columns=self.get_columns('branches'))

# FIXME: in openstreetmap, cross sections are not linestrings, perpendicular to stream, but profile types and dimensions of a channel
# It may be that this is "parameterised cross sections, and we simply don't need the property below.
self.crosssections = ExtendedGeoDataFrame(geotype=LineString, required_columns=[
'code',
'geometry',
'ruwheidswaarde',
'ruwheidstypecode'
])

# FIXME: ensure that all required parameterised properties are provided. I can imagine this is a matter of making
# several parameterised profiles for different profile types (e.g. trapezoidal, rectangular, circular, etc.)
self.profiles = ExtendedGeoDataFrame(geotype=LineString, required_columns=self.get_columns('crosssections'))
Expand Down
8 changes: 6 additions & 2 deletions examples/test_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
fn_ini = os.path.join(root, 'osm_settings.ini')

logger = initialize_logger('osm2fm.log', log_level=10)

# Read ini file
logger.info(f'Read config from {fn_ini}')
config = configparser.ConfigParser(inline_comment_prefixes=[";", "#"])
Expand Down Expand Up @@ -61,12 +62,15 @@
)

# retrieve profiles at start of each line segment
profiles_start = osm.profiles.branch_to_prof(offset=0.5, prefix='A_', rename_col='id')
profiles_start = osm.profiles.branch_to_prof(offset=0.5, prefix = 'Prof_', suffix='_A', rename_col='id')
# retrieve profiles at end of each line segment
profiles_end = osm.profiles.branch_to_prof(offset=0.5, prefix='B_', rename_col='id', vertex_end=True)
profiles_end = osm.profiles.branch_to_prof(offset=0.5, prefix = 'Prof_', suffix='_B', rename_col='id', vertex_end=True)
# concat into a new profiles object
osm.profiles = pd.concat([profiles_start, profiles_end])

#
#osm.profiles.sample_raster(rasterio,offset=None,geometry)

# Plot branches and cross-sections
plt.rcParams['axes.edgecolor'] = 'w'

Expand Down

0 comments on commit 3348cea

Please sign in to comment.