NGen
Loading...
Searching...
No Matches
ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader Class Referenceabstract

Common behavior of the hydrofabric v4 readers. More...

#include <GeoPackageHydrofabricReader.hpp>

+ Inheritance diagram for ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader:
+ Collaboration diagram for ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader:

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

 AbstractV4GeoPackageHydrofabricReader (geopackage::GeoPackageReader divides_reader, std::optional< geopackage::GeoPackageReader > nexus_reader, HydrofabricVersion version)
 
void check_required_columns (const std::string &layer) const override
 Verify up front that layer carries the columns this version needs.
 
void normalize_nexus (geojson::FeatureCollection &nexus) const override
 Bring a freshly read nexus collection into ngen's canonical vocabulary, in place.
 
void normalize_divides (geojson::FeatureCollection &divides) const override
 Alias each divide's downstream nexus to "toid", then warn once with a count of the divides that ended up without one, rather than once per divide.
 
virtual void attribute_divide_toid (geojson::PropertyMap &properties, const std::string &id) const =0
 Attribute "toid" on one divide, however this variant expresses it.
 
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.
 

Private Attributes

geopackage::GeoPackageReader divides_reader_
 
std::optional< geopackage::GeoPackageReader > nexus_reader_
 
const HydrofabricVersion version_
 

Detailed Description

Common behavior of the hydrofabric v4 readers.

Both v4 variants renamed the nexus identifier columns (id/toid to nexus_id/nexus_toid), so nexus translation lives here, as does the summary warning about divides left without a downstream reference. What the variants do not share is how a divide reaches its nexus, which is left to attribute_divide_toid() in the concrete subclasses.

Constructor & Destructor Documentation

◆ AbstractV4GeoPackageHydrofabricReader()

ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::AbstractV4GeoPackageHydrofabricReader ( geopackage::GeoPackageReader divides_reader,
std::optional< geopackage::GeoPackageReader > nexus_reader,
HydrofabricVersion version )
protected
Parameters
[in]divides_readerReader for the GeoPackage holding the divides layer
[in]nexus_readerReader for the nexus layer's GeoPackage, if a separate file
[in]versionWhich v4 variant was detected

Member Function Documentation

◆ attribute_divide_toid()

virtual void ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::attribute_divide_toid ( geojson::PropertyMap & properties,
const std::string & id ) const
protectedpure virtual

Attribute "toid" on one divide, however this variant expresses it.

Leaving "toid" unset marks the divide terminal, which is what an absent downstream reference means to every consumer downstream of the loader.

Parameters
[in,out]propertiesProperty map for the divide
[in]idResolved divide id
Exceptions
std::runtime_errorif a column this variant requires is absent from the row

Implemented in ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader, and ngen::hydrofabric::V4_0GeoPackageHydrofabricReader.

Referenced by normalize_divides().

◆ check_required_columns()

void ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::check_required_columns ( const std::string & layer) const
overrideprotectedvirtual

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.

Parameters
[in]layerHydrofabric layer about to be read
Exceptions
std::runtime_errorif a required column is absent

Reimplemented from ngen::hydrofabric::GeoPackageHydrofabricReader.

Reimplemented in ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader, and ngen::hydrofabric::V4_0GeoPackageHydrofabricReader.

References ngen::hydrofabric::NEXUS_ID_COLUMN, ngen::hydrofabric::NEXUS_LAYER, ngen::hydrofabric::NEXUS_TOID_COLUMN, ngen::hydrofabric::GeoPackageHydrofabricReader::reader_for(), ngen::hydrofabric::GeoPackageHydrofabricReader::version(), and ngen::hydrofabric::version_label().

Referenced by ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::check_required_columns(), and ngen::hydrofabric::V4_0GeoPackageHydrofabricReader::check_required_columns().

◆ normalize_divides()

void ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::normalize_divides ( geojson::FeatureCollection & divides) const
overrideprotectedvirtual

Alias each divide's downstream nexus to "toid", then warn once with a count of the divides that ended up without one, rather than once per divide.

Parameters
[in,out]dividesDivides collection to update in place
Exceptions
std::runtime_errorif a row cannot be translated

Implements ngen::hydrofabric::GeoPackageHydrofabricReader.

References attribute_divide_toid(), ngen::hydrofabric::DIVIDE_ID_COLUMN, ngen::hydrofabric::TOID_KEY, ngen::hydrofabric::GeoPackageHydrofabricReader::version(), and ngen::hydrofabric::version_label().

◆ normalize_nexus()

void ngen::hydrofabric::AbstractV4GeoPackageHydrofabricReader::normalize_nexus ( geojson::FeatureCollection & nexus) const
overrideprotectedvirtual

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.

Parameters
[in,out]nexusNexus collection to update in place
Exceptions
std::runtime_errorif a row cannot be translated

Implements ngen::hydrofabric::GeoPackageHydrofabricReader.

References ngen::hydrofabric::ID_KEY, ngen::hydrofabric::NEXUS_ID_COLUMN, ngen::hydrofabric::NEXUS_TOID_COLUMN, ngen::hydrofabric::TOID_KEY, ngen::hydrofabric::GeoPackageHydrofabricReader::version(), and ngen::hydrofabric::version_label().

◆ read_divides()

geojson::GeoJSON ngen::hydrofabric::GeoPackageHydrofabricReader::read_divides ( const std::vector< std::string > & ids = {})
overridevirtualinherited

Read the hydrofabric's divides.

Parameters
[in]idsOptional 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.
Returns
geojson::GeoJSON Collection of divide features
Exceptions
std::runtime_errorif the divides cannot be read

Implements ngen::hydrofabric::HydrofabricReader.

Reimplemented in ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader.

References ngen::hydrofabric::GeoPackageHydrofabricReader::check_required_columns(), ngen::geopackage::GeoPackageReader::db(), ngen::hydrofabric::DIVIDES_LAYER, ngen::hydrofabric::get_layer_id_column(), ngen::hydrofabric::GeoPackageHydrofabricReader::normalize_divides(), ngen::geopackage::GeoPackageReader::read(), ngen::hydrofabric::GeoPackageHydrofabricReader::reader_for(), and ngen::hydrofabric::GeoPackageHydrofabricReader::version_.

Referenced by ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::read_divides().

◆ read_nexus()

geojson::GeoJSON ngen::hydrofabric::GeoPackageHydrofabricReader::read_nexus ( const std::vector< std::string > & ids = {})
overridevirtualinherited

Read the hydrofabric's nexuses.

Parameters
[in]idsOptional subset of nexus IDs to capture; if empty, all nexuses are read. IDs that the hydrofabric does not contain are silently ignored.
Returns
geojson::GeoJSON Collection of nexus features
Exceptions
std::runtime_errorif the nexuses cannot be read

Implements ngen::hydrofabric::HydrofabricReader.

References ngen::hydrofabric::GeoPackageHydrofabricReader::check_required_columns(), ngen::geopackage::GeoPackageReader::db(), ngen::hydrofabric::get_layer_id_column(), ngen::hydrofabric::NEXUS_LAYER, ngen::hydrofabric::GeoPackageHydrofabricReader::normalize_nexus(), ngen::geopackage::GeoPackageReader::read(), ngen::hydrofabric::GeoPackageHydrofabricReader::reader_for(), and ngen::hydrofabric::GeoPackageHydrofabricReader::version_.

◆ reader_for()

const geopackage::GeoPackageReader & ngen::hydrofabric::GeoPackageHydrofabricReader::reader_for ( const std::string & layer) const
protectedinherited

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.

Parameters
[in]layerHydrofabric layer name, "divides" or "nexus"
Returns
Const reference to the reader that layer is read through
Exceptions
std::logic_errorif layer is neither "divides" nor "nexus"

References ngen::hydrofabric::DIVIDES_LAYER, ngen::hydrofabric::GeoPackageHydrofabricReader::divides_reader_, ngen::hydrofabric::NEXUS_LAYER, and ngen::hydrofabric::GeoPackageHydrofabricReader::nexus_reader_.

Referenced by check_required_columns(), ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::V4_0GeoPackageHydrofabricReader::check_required_columns(), ngen::hydrofabric::GeoPackageHydrofabricReader::read_divides(), ngen::hydrofabric::V4_0Beta1GeoPackageHydrofabricReader::read_divides(), and ngen::hydrofabric::GeoPackageHydrofabricReader::read_nexus().

◆ version()

HydrofabricVersion ngen::hydrofabric::GeoPackageHydrofabricReader::version ( ) const
protectednoexceptinherited

Member Data Documentation

◆ divides_reader_

geopackage::GeoPackageReader ngen::hydrofabric::GeoPackageHydrofabricReader::divides_reader_
privateinherited

◆ nexus_reader_

std::optional<geopackage::GeoPackageReader> ngen::hydrofabric::GeoPackageHydrofabricReader::nexus_reader_
privateinherited

◆ version_


The documentation for this class was generated from the following files: