From 7ce817eef5ac7670aaac0e09892f12ec703c8c93 Mon Sep 17 00:00:00 2001 From: rhutten Date: Thu, 29 Oct 2020 14:23:34 +0100 Subject: [PATCH] reading of cross-section and culverts including filtering based on draintype added #11 --- data/osm/osm_settings.ini | 5 +++-- delft3dfmpy/datamodels/common.py | 9 +++++++-- delft3dfmpy/datamodels/osm.py | 28 ++-------------------------- examples/test_osm.py | 24 +++++++++++++++++------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/data/osm/osm_settings.ini b/data/osm/osm_settings.ini index a580d4f..6c889a9 100644 --- a/data/osm/osm_settings.ini +++ b/data/osm/osm_settings.ini @@ -5,9 +5,10 @@ DataFile = dar_drains.json [datacolumns] IDcolumn = id +DrainTypeColumn = drain_type branches = id, geometry # write down -crosssections = id, draintype, covered, material, width, depth, top_width, diameter, profile_op, profile_cl, bottom_width, geometry -structure = id, draintype, geometry +crosssections = id, drain_type, covered, material, width, depth, top_width, diameter, profile_op, profile_cl, bottom_wid, elliptical, geometry +structures = id, drain_type, geometry [parameter] diff --git a/delft3dfmpy/datamodels/common.py b/delft3dfmpy/datamodels/common.py index 0af45e1..491f1cc 100644 --- a/delft3dfmpy/datamodels/common.py +++ b/delft3dfmpy/datamodels/common.py @@ -86,7 +86,7 @@ def delete_all(self): self.dropna(inplace=True) def read_shp(self, path, index_col=None, column_mapping=None, check_columns=True, clip=None, check_geotype=True, - id_col='code',filter_cols = False): + id_col='code',filter_cols = False, draintype_col=None, filter_culverts=False): """ Import function, extended with type checks. Does not destroy reference to object. """ @@ -95,10 +95,15 @@ def read_shp(self, path, index_col=None, column_mapping=None, check_columns=True #FIXME: add filter to read_file - # Remove unnecessary columns + # Only keep required columns if filter_cols: gdf.drop(columns=gdf.columns[~gdf.columns.isin(self.required_columns)], inplace=True) + # In case of culvert select indices that are culverts + #FIXME: draintype culvert could be different for other OSM data + if filter_culverts: + gdf.drop(index= gdf.index[gdf[draintype_col]!='culvert'], inplace = True) + #FIXME: add method to handle features with geometry is None. diff --git a/delft3dfmpy/datamodels/osm.py b/delft3dfmpy/datamodels/osm.py index 3cfe055..69690a0 100644 --- a/delft3dfmpy/datamodels/osm.py +++ b/delft3dfmpy/datamodels/osm.py @@ -38,35 +38,11 @@ def __init__(self, extent_file=None, data_columns=None): # 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.parametrised_profiles = ExtendedGeoDataFrame(geotype=LineString, required_columns=[ - 'code', - 'bodemhoogtebenedenstrooms', - 'bodemhoogtebovenstrooms', - 'bodembreedte', - 'taludhellinglinkerzijde', - 'taludhellingrechterzijde', - 'hoogteinsteeklinkerzijde', - 'hoogteinsteekrechterzijde', - 'ruwheidswaarde', - 'ruwheidstypecode' - ]) + self.parametrised_profiles = ExtendedGeoDataFrame(geotype=LineString, required_columns=self.get_columns('crosssections')) # FIXME: ensure that all culvert types and properties can be handled. We probably have circular and box-shaped culverts, sometimes with multiple openings - self.culverts = ExtendedGeoDataFrame(geotype=LineString, required_columns=[ - 'code', - 'geometry', - 'lengte', - 'hoogteopening', - 'breedteopening', - 'hoogtebinnenonderkantbenedenstrooms', - 'hoogtebinnenonderkantbovenstrooms', - 'vormcode', - 'intreeverlies', - 'uittreeverlies', - 'ruwheidstypecode', - 'ruwheidswaarde' - ]) + self.culverts = ExtendedGeoDataFrame(geotype=LineString, required_columns=self.get_columns('structures')) # # FIXME: not sure what laterals in this context mean, but I don't think we need it at this stage. # self.laterals = ExtendedGeoDataFrame(geotype=Point, required_columns=[ diff --git a/examples/test_osm.py b/examples/test_osm.py index 8569109..de83506 100644 --- a/examples/test_osm.py +++ b/examples/test_osm.py @@ -23,16 +23,20 @@ print(type(osm)) -# TODO: read branches, culvert, cross sections and properties from file and plot network to check -# TODO: BRANCHES - read id column from json. Do not deviate between drain type -osm.branches.read_shp(os.path.join(path,config.get('input','datafile')),index_col='id',clip = osm.clipgeo - , id_col=config.get('datacolumns', 'idcolumn'), filter_cols=True) +# Id column +id = config.get('datacolumns','idcolumn') -print('hello world') -# TODO: BRANCHES - connect branches on the right locations -# TODO: plot branches +# TODO: BRANCHES - read id column from json. Do not deviate between drain type +# Read branches and store in OSM data model +osm.branches.read_shp(os.path.join(path,config.get('input','datafile')),index_col=id, clip = osm.clipgeo + , id_col=id, filter_cols=True) # TODO: CROSS SECTIONS DEFINTION - read id, drain_type, material, width, depth, top_width, diameter, profile_op, profile_cl, bottom_width columns from json +# read cross-sections +osm.parametrised_profiles.read_shp(os.path.join(path,config.get('input','datafile')),index_col=id, clip = osm.clipgeo + , id_col=id, filter_cols=True) + +print('Hello world') # TODO: CROSS SECTIONS DEFINTION - specify roughness dependent on material add this # TODO: CROSS SECTION DEFINITION - assign elevation value to cross sections. this needs to be retrieved from a DEM (which we have!) @@ -44,6 +48,11 @@ # TODO: plot branches + cross sections locations # TODO: STRUCTURE - read id, draintype +# Read culverts +osm.culverts.read_shp(os.path.join(path,config.get('input','datafile')),index_col=id, clip = osm.clipgeo, + id_col=id, filter_cols=True, draintype_col=config.get('datacolumns','draintypecolumn') + , filter_culverts=True) + # TODO: STRUCTURE - select rows with draintype culvert # TODO: STRUCTURE - determine length and midpoint location culvert # TODO: STRUCTURE - snapping of open drains over culverts. May not be needed as wel only use parameterized profiles @@ -56,3 +65,4 @@ # TODO: create 1D2D links +print("Hello world")