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
| Name | Type | Description | Default |
|---|---|---|---|
| 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 |
Examples
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
| Name | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| 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
| Name | Type | Description | Default |
|---|---|---|---|
| cross_section | CrossSection | Cross section to add. | required |
plot
cross_sections.CrossSectionCollection.plot(*args, **kwargs)Plot all cross sections in the collection.
remove
cross_sections.CrossSectionCollection.remove(cross_section)Remove a cross section from the collection.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| 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
| Name | Type | Description | Default |
|---|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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.
to_geopandas
cross_sections.CrossSectionCollection.to_geopandas(mode='sections')Convert the collection to a GeoDataFrame.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| mode | str | Mode of conversion. Options are “sections” and “markers”. Default is “sections”. | 'sections' |
Returns
| Name | Type | Description |
|---|---|---|
| gpd.GeoDataFrame | GeoDataFrame with the cross 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
| Name | Type | Description | Default |
|---|---|---|---|
| file_name | str or Path | Path to the file to save. | required |
Examples
>>> csc.to_xns11("cross_sections.xns11")