cross_sections.CrossSectionCollection
cross_sections.CrossSectionCollection(self , cross_sections= None )
A collection of CrossSection objects.
The collection is a dict-like object where the keys are tuples of location ID, chainage and topo ID.
Parameters
cross_sections
Collection[CrossSection] | CrossSectionData | Path | str
If Collection[CrossSection], the collection will be initialized from the list of CrossSection objects. If CrossSectionData, the collection will be initialized from a .NET DHI.Mike1D.CrossSectionModule.CrossSectionData object. If Path or str, the collection will be initialized from an xns11 file.
None
Create a collection from a list of cross sections
>>> from mikeio1d.cross_sections import CrossSectionCollection, CrossSection
>>> x = [0 , 1 , 2 , 3 , 4 , 5 ]
>>> z = [0 , 1 , 2 , 3 , 4 , 5 ]
>>> xs1 = CrossSection.from_xz(x, z, location_id= "loc1" , chainage= 100 , topo_id= "topo1" )
>>> xs2 = CrossSection.from_xz(x, z, location_id= "loc2" , chainage= 200 , topo_id= "topo1" )
>>> csc = CrossSectionCollection([xs1, xs2])
Access a cross section with indexing, or explicitly with sel()
>>> csc['loc1' , '100.000' , 'topo1' ]
>>> csc.sel(location_id= 'loc1' , chainage= 100 , topo_id= 'topo1' )
Create a collection from an xns11 file
>>> csc = CrossSectionCollection("cross_sections.xns11" )
Save the collection to an xns11 file
>>> csc.to_xns11("cross_sections.xns11" )
Attributes
chainages
Unique chainages in the collection (as string with 3 decimals).
cross_section_data
The DHI.Mike1D.CrossSectionModule.CrossSectionData object.
data
The DHI.Mike1D.CrossSectionModule.CrossSectionData object.
interpolation_type
Defines how an interpolated cross section is interpolated.
location_ids
Unique location IDs in the collection.
topo_ids
Unique topo IDs in the collection.
Methods
add
Add a cross section to the collection.
plot
Plot all cross sections in the collection.
remove
Remove a cross section from the collection.
sel
Select cross sections from the collection.
to_dataframe
Convert the collection to a DataFrame.
to_geopandas
Convert the collection to a GeoDataFrame.
to_xns11
Save the collection to an Xns11 file.
add
cross_sections.CrossSectionCollection.add(cross_section)
Add a cross section to the collection.
Parameters
cross_section
CrossSection
Cross section to add.
required
plot
cross_sections.CrossSectionCollection.plot(* args, ** kwargs)
Plot all cross sections in the collection.
Arguments are passed to CrossSection.plot.
Returns
matplotlib.axes.Axes
The axes that was plotted to.
remove
cross_sections.CrossSectionCollection.remove(cross_section)
Remove a cross section from the collection.
Parameters
cross_section
CrossSection
Cross section to remove.
required
sel
cross_sections.CrossSectionCollection.sel(
location_id= ...,
chainage= ...,
topo_id= ...,
)
Select cross sections from the collection.
Parameters
location_id
str
Location ID of the cross section.
...
chainage
str | float
Chainage of the cross section.
...
topo_id
str
Topo ID of the cross section.
...
Returns
CrossSection or list[CrossSection]
Providing all arguments will return a CrossSection. Provinding partial arguments will always return a list, even if it only includes one CrossSection.
to_dataframe
cross_sections.CrossSectionCollection.to_dataframe()
Convert the collection to a DataFrame.
Returns
pd.DataFrame
DataFrame indexed by location ID, chainage and topo ID, with a cross_section column.
to_geopandas
cross_sections.CrossSectionCollection.to_geopandas(mode= 'sections' )
Convert the collection to a GeoDataFrame.
Parameters
mode
str
Mode of conversion. Options are “sections” and “markers”. Default is “sections”.
'sections'
Returns
gpd.GeoDataFrame
GeoDataFrame with the cross sections or markers.
Raises
ValueError
If mode is not “sections” or “markers”.
Note:
This method requires the geopandas package to be installed. Cross sections must have defined coordinates.
to_xns11
cross_sections.CrossSectionCollection.to_xns11(file_name, ** kwargs)
Save the collection to an Xns11 file.
Parameters
file_name
str or Path
Path to the file to save.
required
Examples
>>> csc.to_xns11("cross_sections.xns11" )