|
NGen
|
Reads a hydrofabric stored as one or two GeoPackages. More...
#include <GeoPackageHydrofabricReader.hpp>
Inheritance diagram for ngen::hydrofabric::GeoPackageHydrofabricReader:
Collaboration diagram for ngen::hydrofabric::GeoPackageHydrofabricReader:Public Member Functions | |
| geojson::GeoJSON | read_divides (const std::vector< std::string > &ids={}) override |
| Read the hydrofabric's divides. | |
| geojson::GeoJSON | read_nexus (const std::vector< std::string > &ids={}) override |
| Read the hydrofabric's nexuses. | |
Protected Member Functions | |
| GeoPackageHydrofabricReader (geopackage::GeoPackageReader divides_reader, std::optional< geopackage::GeoPackageReader > nexus_reader, HydrofabricVersion version) | |
| const geopackage::GeoPackageReader & | reader_for (const std::string &layer) const |
The reader for the file holding layer. | |
| HydrofabricVersion | version () const noexcept |
| The detected schema version, for the version-keyed schema utilities. | |
| virtual void | check_required_columns (const std::string &layer) const |
Verify up front that layer carries the columns this version needs. | |
| virtual void | normalize_divides (geojson::FeatureCollection ÷s) const =0 |
| Bring a freshly read divides collection into ngen's canonical vocabulary, in place. | |
| virtual void | normalize_nexus (geojson::FeatureCollection &nexus) const =0 |
| Bring a freshly read nexus collection into ngen's canonical vocabulary, in place. | |
Private Attributes | |
| geopackage::GeoPackageReader | divides_reader_ |
| std::optional< geopackage::GeoPackageReader > | nexus_reader_ |
| const HydrofabricVersion | version_ |
Reads a hydrofabric stored as one or two GeoPackages.
A GeoPackage hydrofabric keeps its divides and nexuses in named layers, so this reader owns generic ngen::geopackage::GeoPackageReader instances and mediates between them and the two hydrofabric roles: it resolves which column carries each layer's id, checks that the columns its schema version requires are present, and translates what the file names into what the rest of ngen expects. The generic readers stay unaware of all of it.
The two roles may share one GeoPackage or come from two, which is why the second reader is optional rather than a second mandatory handle: absent means "the same file the divides came from", and the file is opened once.
Schema versions differ only in that translation, so this class is abstract and each supported version is a subclass. Instances come from make_hydrofabric_reader(), which detects the version.
|
protected |
| [in] | divides_reader | Reader for the GeoPackage holding the divides layer |
| [in] | nexus_reader | Reader for the GeoPackage holding the nexus layer, or no value when that layer lives in the same file as the divides |
| [in] | version | Hydrofabric schema version detected for this hydrofabric |
|
protectedvirtual |
Verify up front that layer carries the columns this version needs.
Checking before the read means a file missing a required column is reported as the schema problem it is, rather than as a failure to find a column mid-row. The default checks nothing.
| [in] | layer | Hydrofabric layer about to be read |
| std::runtime_error | if a required column is absent |
Reimplemented in ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader, ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader, and ngen::hydrofabric::V4_0GeoPackageHydrofabricReader.
Referenced by read_divides(), and read_nexus().
|
protectedpure virtual |
Bring a freshly read divides collection into ngen's canonical vocabulary, in place.
The generic read stores each column under the file's own name for it, but for simplicity, ngen's consumers key on specific names: "id" and "toid". A version that names them differently aliases its columns onto those names here, leaving the originals in place. Implementations also validate the rows they translate and summarize outcomes worth a warning.
| [in,out] | divides | Divides collection to update in place |
| std::runtime_error | if a row cannot be translated |
Implemented in ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader, and ngen::hydrofabric::V2_2GeoPackageHydrofabricReader.
Referenced by read_divides().
|
protectedpure virtual |
Bring a freshly read nexus collection into ngen's canonical vocabulary, in place.
The generic read stores each column under the file's own name for it, but for simplicity, ngen's consumers key on specific names: "id" and "toid". A version that names them differently aliases its columns onto those names here, leaving the originals in place. Implementations also validate the rows they translate and summarize outcomes worth a warning.
| [in,out] | nexus | Nexus collection to update in place |
| std::runtime_error | if a row cannot be translated |
Implemented in ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader, and ngen::hydrofabric::V2_2GeoPackageHydrofabricReader.
Referenced by read_nexus().
|
overridevirtual |
Read the hydrofabric's divides.
| [in] | ids | Optional subset of divide IDs to capture; if empty, all divides are read. IDs that the hydrofabric does not contain are silently ignored, so the result is the intersection of the hydrofabric and ids. |
| std::runtime_error | if the divides cannot be read |
Implements ngen::hydrofabric::HydrofabricReader.
Reimplemented in ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader.
References check_required_columns(), ngen::geopackage::GeoPackageReader::db(), ngen::hydrofabric::DIVIDES_LAYER, ngen::hydrofabric::get_layer_id_column(), normalize_divides(), ngen::geopackage::GeoPackageReader::read(), reader_for(), and version_.
Referenced by ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::read_divides().
|
overridevirtual |
Read the hydrofabric's nexuses.
| [in] | ids | Optional subset of nexus IDs to capture; if empty, all nexuses are read. IDs that the hydrofabric does not contain are silently ignored. |
| std::runtime_error | if the nexuses cannot be read |
Implements ngen::hydrofabric::HydrofabricReader.
References check_required_columns(), ngen::geopackage::GeoPackageReader::db(), ngen::hydrofabric::get_layer_id_column(), ngen::hydrofabric::NEXUS_LAYER, normalize_nexus(), ngen::geopackage::GeoPackageReader::read(), reader_for(), and version_.
|
protected |
The reader for the file holding layer.
The two hydrofabric roles are the whole domain: "nexus" resolves to the second file when there is one and otherwise to the single shared file, and "divides" always resolves to the file it was constructed from. Any other name is refused rather than guessed at – in a split hydrofabric there is no honest answer for which file holds a layer this class does not know, and a guess would surface later as a missing-table error naming the wrong file.
| [in] | layer | Hydrofabric layer name, "divides" or "nexus" |
| std::logic_error | if layer is neither "divides" nor "nexus" |
References ngen::hydrofabric::DIVIDES_LAYER, divides_reader_, ngen::hydrofabric::NEXUS_LAYER, and nexus_reader_.
Referenced by ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::V4_0GeoPackageHydrofabricReader::check_required_columns(), read_divides(), ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::read_divides(), and read_nexus().
|
protectednoexcept |
The detected schema version, for the version-keyed schema utilities.
References version_.
Referenced by ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::V4_0GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::normalize_divides(), ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::normalize_nexus(), and ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::read_divides().
|
private |
Referenced by reader_for().
|
private |
Referenced by reader_for().
|
private |
Referenced by read_divides(), read_nexus(), and version().