OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
openswmm::gpkg Namespace Reference

Namespaces

namespace  detail
 
namespace  formats
 

Classes

struct  DbDeleter
 
struct  DecodedLinestring
 
struct  DecodedMultipolygon
 
struct  DecodedPoint
 
struct  FilePathPair
 Two-string carrier for any external file path that appears in a SWMM .inp file. More...
 
class  GeoPackageInputPlugin
 
class  GeoPackageOutputPlugin
 
class  GeoPackagePluginInfo
 IPluginComponentInfo for the GeoPackage I/O plugin. More...
 
class  GeoPackageReportPlugin
 
class  GpkgError
 
struct  SimulationContext
 Central, reentrant simulation context. More...
 
struct  StmtDeleter
 
class  Transaction
 

Typedefs

using DbPtr = std::unique_ptr<sqlite3, DbDeleter>
 
using StmtPtr = std::unique_ptr<sqlite3_stmt, StmtDeleter>
 

Enumerations

enum  WkbType : uint32_t {
  WKB_POINT = 1 ,
  WKB_LINESTRING = 2 ,
  WKB_POLYGON = 3 ,
  WKB_MULTIPOLYGON = 6
}
 
enum class  TableType
 Type of data stored in a Table. More...
 
enum class  FileMode
 Mode keyword for one [FILES] row — SAVE or USE. More...
 
enum class  TableType
 Type of data stored in a Table. More...
 
enum class  FileMode
 Mode keyword for one [FILES] row — SAVE or USE. More...
 

Functions

std::string scratchDirFor (const std::string &gpkg_path)
 Compute the canonical scratch-dir path for a given .gpkg file.
 
void read_external_content (sqlite3 *db, openswmm::SimulationContext &ctx, const std::string &simulation_id, const std::string &scratch_dir)
 Hydrate every external-file slot on ctx from the Part D tables and materialise scratch files in scratch_dir.
 
void write_external_content (sqlite3 *db, const openswmm::SimulationContext &ctx, const std::string &simulation_id)
 Populate the Part D content tables for simulation_id from the in-memory model.
 
int read_model (sqlite3 *db, SimulationContext &ctx, const std::string &simulation_id, const std::string &scratch_dir="")
 Read a model definition from a GeoPackage into a SimulationContext.
 
int read_from_file (const std::string &path, SimulationContext &ctx, const std::string &simulation_id)
 Convenience: open a GeoPackage file and read a model.
 
void create_schema (sqlite3 *db)
 Create all GeoPackage metadata tables and OpenSWMM application tables.
 
void register_crs (sqlite3 *db, int srs_id, const std::string &org, int org_id, const std::string &srs_name, const std::string &wkt)
 Register a CRS in gpkg_spatial_ref_sys (if not already present).
 
void register_feature_table (sqlite3 *db, const std::string &table_name, const std::string &geom_type, int srs_id, const std::string &identifier, const std::string &description, double min_x, double min_y, double max_x, double max_y)
 Register a feature table in gpkg_contents and gpkg_geometry_columns.
 
void populate_default_variables (sqlite3 *db)
 Pre-populate the variables catalog with known SWMM output variables.
 
void write_model (sqlite3 *db, const SimulationContext &ctx, const std::string &simulation_id, int srs_id=0)
 Write the full model definition from a SimulationContext into a GeoPackage.
 
int write_to_file (const std::string &path, const SimulationContext &ctx, const std::string &simulation_id)
 Convenience: create a new GeoPackage file, write schema + model.
 
std::vector< uint8_t > encode_point (double x, double y, int32_t srs_id)
 Encode a POINT geometry in GeoPackage Binary format.
 
std::vector< uint8_t > encode_linestring (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id)
 Encode a LINESTRING geometry in GeoPackage Binary format.
 
std::vector< uint8_t > encode_multipolygon (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id)
 Encode a MULTIPOLYGON geometry (single polygon, single ring) in GeoPackage Binary format.
 
std::vector< uint8_t > encode_polygon (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id)
 Encode a POLYGON geometry (single ring) in GeoPackage Binary format.
 
DecodedPoint decode_point (const std::vector< uint8_t > &blob)
 
DecodedLinestring decode_linestring (const std::vector< uint8_t > &blob)
 
DecodedMultipolygon decode_multipolygon (const std::vector< uint8_t > &blob)
 
DbPtr open_database (const std::string &path, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE)
 
StmtPtr prepare (sqlite3 *db, const std::string &sql)
 
void exec (sqlite3 *db, const std::string &sql)
 
void bind_text (sqlite3_stmt *stmt, int col, const std::string &val)
 
void bind_double (sqlite3_stmt *stmt, int col, double val)
 
void bind_int (sqlite3_stmt *stmt, int col, int val)
 
void bind_null (sqlite3_stmt *stmt, int col)
 
void bind_blob (sqlite3_stmt *stmt, int col, const void *data, int size)
 
std::string column_text (sqlite3_stmt *stmt, int col)
 
double column_double (sqlite3_stmt *stmt, int col)
 
int column_int (sqlite3_stmt *stmt, int col)
 
bool column_is_null (sqlite3_stmt *stmt, int col)
 
std::vector< uint8_t > column_blob (sqlite3_stmt *stmt, int col)
 

Variables

constexpr uint8_t WKB_LITTLE_ENDIAN = 1
 
constexpr uint8_t GP_MAGIC_1 = 0x47
 
constexpr uint8_t GP_MAGIC_2 = 0x50
 

Typedef Documentation

◆ DbPtr

using openswmm::gpkg::DbPtr = std::unique_ptr<sqlite3, DbDeleter>

◆ StmtPtr

using openswmm::gpkg::StmtPtr = std::unique_ptr<sqlite3_stmt, StmtDeleter>

Enumeration Type Documentation

◆ FileMode [1/2]

enum class openswmm::FileMode
strong

Mode keyword for one [FILES] row — SAVE or USE.

NONE is the in-memory default for unconfigured slots so the writer can skip them. SAVE writes data out at simulation end; USE reads data in at simulation start.

◆ FileMode [2/2]

enum class openswmm::FileMode
strong

Mode keyword for one [FILES] row — SAVE or USE.

NONE is the in-memory default for unconfigured slots so the writer can skip them. SAVE writes data out at simulation end; USE reads data in at simulation start.

◆ TableType [1/2]

enum class openswmm::TableType : int
strong

Type of data stored in a Table.

See also
Legacy reference: TableType in src/solver/enums.h

◆ TableType [2/2]

enum class openswmm::TableType : int
strong

Type of data stored in a Table.

See also
Legacy reference: TableType in src/solver/enums.h

◆ WkbType

enum openswmm::gpkg::WkbType : uint32_t
Enumerator
WKB_POINT 
WKB_LINESTRING 
WKB_POLYGON 
WKB_MULTIPOLYGON 

Function Documentation

◆ bind_blob()

void openswmm::gpkg::bind_blob ( sqlite3_stmt * stmt,
int col,
const void * data,
int size )
inline

◆ bind_double()

void openswmm::gpkg::bind_double ( sqlite3_stmt * stmt,
int col,
double val )
inline
Here is the caller graph for this function:

◆ bind_int()

void openswmm::gpkg::bind_int ( sqlite3_stmt * stmt,
int col,
int val )
inline
Here is the caller graph for this function:

◆ bind_null()

void openswmm::gpkg::bind_null ( sqlite3_stmt * stmt,
int col )
inline
Here is the caller graph for this function:

◆ bind_text()

void openswmm::gpkg::bind_text ( sqlite3_stmt * stmt,
int col,
const std::string & val )
inline
Here is the caller graph for this function:

◆ column_blob()

std::vector< uint8_t > openswmm::gpkg::column_blob ( sqlite3_stmt * stmt,
int col )
inline

◆ column_double()

double openswmm::gpkg::column_double ( sqlite3_stmt * stmt,
int col )
inline
Here is the caller graph for this function:

◆ column_int()

int openswmm::gpkg::column_int ( sqlite3_stmt * stmt,
int col )
inline
Here is the caller graph for this function:

◆ column_is_null()

bool openswmm::gpkg::column_is_null ( sqlite3_stmt * stmt,
int col )
inline

◆ column_text()

std::string openswmm::gpkg::column_text ( sqlite3_stmt * stmt,
int col )
inline
Here is the caller graph for this function:

◆ create_schema()

void openswmm::gpkg::create_schema ( sqlite3 * db)

Create all GeoPackage metadata tables and OpenSWMM application tables.

Creates (idempotently):

  • gpkg_spatial_ref_sys, gpkg_contents, gpkg_geometry_columns (OGC standard)
  • Part A: options, nodes, links, subcatchments, rain_gages, node_links, subcatch_routing, curves, input_timeseries, patterns, pollutants, transects
  • Part B: simulations, variables, result_timeseries, result_summary
  • Part C: observed_series, observed_values
  • Part D (Slice IO-5): hotstart_slots + hotstart_{node,link,subcatch}_state
    • hotstart_{node,link,subcatch}_pollutant_state, raingage_data, climate_data, routing_interface_{node,subcatch,gage}, and routing_interface_node_pollutants. Composite foreign keys into the existing model tables enforce cascading delete / update and reject orphan rows. See IO_PORTABILITY_PLAN.md §3.4 for the design rationale.
Parameters
dbOpen SQLite database handle.
Exceptions
GpkgErroron failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_linestring()

DecodedLinestring openswmm::gpkg::decode_linestring ( const std::vector< uint8_t > & blob)
inline
Here is the call graph for this function:

◆ decode_multipolygon()

DecodedMultipolygon openswmm::gpkg::decode_multipolygon ( const std::vector< uint8_t > & blob)
inline
Here is the call graph for this function:

◆ decode_point()

DecodedPoint openswmm::gpkg::decode_point ( const std::vector< uint8_t > & blob)
inline
Here is the call graph for this function:

◆ encode_linestring()

std::vector< uint8_t > openswmm::gpkg::encode_linestring ( const std::vector< double > & xs,
const std::vector< double > & ys,
int32_t srs_id )
inline

Encode a LINESTRING geometry in GeoPackage Binary format.

Parameters
xsX coordinates of vertices.
ysY coordinates of vertices.
Here is the call graph for this function:

◆ encode_multipolygon()

std::vector< uint8_t > openswmm::gpkg::encode_multipolygon ( const std::vector< double > & xs,
const std::vector< double > & ys,
int32_t srs_id )
inline

Encode a MULTIPOLYGON geometry (single polygon, single ring) in GeoPackage Binary format.

Parameters
xsX coordinates of polygon ring vertices.
ysY coordinates of polygon ring vertices.
Here is the call graph for this function:

◆ encode_point()

std::vector< uint8_t > openswmm::gpkg::encode_point ( double x,
double y,
int32_t srs_id )
inline

Encode a POINT geometry in GeoPackage Binary format.

Here is the call graph for this function:

◆ encode_polygon()

std::vector< uint8_t > openswmm::gpkg::encode_polygon ( const std::vector< double > & xs,
const std::vector< double > & ys,
int32_t srs_id )
inline

Encode a POLYGON geometry (single ring) in GeoPackage Binary format.

Parameters
xsX coordinates of polygon ring vertices.
ysY coordinates of polygon ring vertices.

Used for the 2D mesh triangle feature layer (one ring of 3 vertices, closed automatically). Identical to encode_multipolygon minus the outer MULTIPOLYGON wrapper.

Here is the call graph for this function:

◆ exec()

void openswmm::gpkg::exec ( sqlite3 * db,
const std::string & sql )
inline
Here is the caller graph for this function:

◆ open_database()

DbPtr openswmm::gpkg::open_database ( const std::string & path,
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE )
inline
Here is the caller graph for this function:

◆ populate_default_variables()

void openswmm::gpkg::populate_default_variables ( sqlite3 * db)

Pre-populate the variables catalog with known SWMM output variables.

Parameters
dbOpen database handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare()

StmtPtr openswmm::gpkg::prepare ( sqlite3 * db,
const std::string & sql )
inline
Here is the caller graph for this function:

◆ read_external_content()

void openswmm::gpkg::read_external_content ( sqlite3 * db,
openswmm::SimulationContext & ctx,
const std::string & simulation_id,
const std::string & scratch_dir )

Hydrate every external-file slot on ctx from the Part D tables and materialise scratch files in scratch_dir.

scratch_dir is created if missing. When scratch_dir is empty the call is a no-op — the function is then equivalent to skipping external-content hydration entirely (useful in read_model callers that don't have a .gpkg path context).

Exceptions
GpkgErroron materialiser failures.
Here is the caller graph for this function:

◆ read_from_file()

int openswmm::gpkg::read_from_file ( const std::string & path,
SimulationContext & ctx,
const std::string & simulation_id )

Convenience: open a GeoPackage file and read a model.

Parameters
pathPath to the .gpkg file.
ctxSimulation context to populate.
simulation_idWhich model instance to load.
Returns
0 on success, non-zero on error.
Here is the call graph for this function:

◆ read_model()

int openswmm::gpkg::read_model ( sqlite3 * db,
SimulationContext & ctx,
const std::string & simulation_id,
const std::string & scratch_dir = "" )

Read a model definition from a GeoPackage into a SimulationContext.

When scratch_dir is non-empty (Slice IO-8), the reader also walks the Part D content tables (raingage_data, climate_data, routing_interface_*, hotstart_*) and materialises one scratch file per role under scratch_dir. Each ctx external-file slot's FilePathPair.absolute is then bound to the matching scratch path so legacy fopen sites keep working. See ExternalContentReader.hpp for details.

Parameters
dbOpen SQLite database handle.
ctxSimulation context to populate.
simulation_idWhich model instance to load.
scratch_dirDirectory for materialised scratch files (sibling of the source .gpkg). Pass empty to skip Part D hydration.
Returns
0 on success, non-zero on error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_crs()

void openswmm::gpkg::register_crs ( sqlite3 * db,
int srs_id,
const std::string & org,
int org_id,
const std::string & srs_name,
const std::string & wkt )

Register a CRS in gpkg_spatial_ref_sys (if not already present).

Parameters
dbOpen database handle.
srs_idNumeric SRS ID (e.g., 4326).
orgOrganization name (e.g., "EPSG").
org_idOrganization CRS ID (e.g., 4326).
srs_nameHuman-readable name (e.g., "WGS 84").
wktWKT definition string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_feature_table()

void openswmm::gpkg::register_feature_table ( sqlite3 * db,
const std::string & table_name,
const std::string & geom_type,
int srs_id,
const std::string & identifier,
const std::string & description,
double min_x,
double min_y,
double max_x,
double max_y )

Register a feature table in gpkg_contents and gpkg_geometry_columns.

Parameters
dbOpen database handle.
table_nameTable name (e.g., "nodes").
geom_typeGeometry type name (e.g., "POINT", "LINESTRING", "MULTIPOLYGON").
srs_idSRS ID from gpkg_spatial_ref_sys.
identifierHuman-readable identifier.
descriptionTable description.
min_x,min_y,max_x,max_yBounding box.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scratchDirFor()

std::string openswmm::gpkg::scratchDirFor ( const std::string & gpkg_path)

Compute the canonical scratch-dir path for a given .gpkg file.

Sibling directory named <basename>.scratch/. Pure string transformation — no filesystem touch.

Here is the caller graph for this function:

◆ write_external_content()

void openswmm::gpkg::write_external_content ( sqlite3 * db,
const openswmm::SimulationContext & ctx,
const std::string & simulation_id )

Populate the Part D content tables for simulation_id from the in-memory model.

Exceptions
GpkgErrorwhen a USE-direction slot references a missing file or when a format parser reports a hard failure.
Here is the caller graph for this function:

◆ write_model()

void openswmm::gpkg::write_model ( sqlite3 * db,
const SimulationContext & ctx,
const std::string & simulation_id,
int srs_id = 0 )

Write the full model definition from a SimulationContext into a GeoPackage.

Creates the schema if needed, registers the CRS, and writes all SWMM input sections as feature/attribute tables. The simulation_id groups all written data for this model instance.

Parameters
dbOpen SQLite database handle (schema must exist or will be created).
ctxSimulation context containing the parsed model.
simulation_idUnique ID for this model instance.
srs_idSRS ID to use for geometry encoding (default: 0 = undefined).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_to_file()

int openswmm::gpkg::write_to_file ( const std::string & path,
const SimulationContext & ctx,
const std::string & simulation_id )

Convenience: create a new GeoPackage file, write schema + model.

Parameters
pathOutput file path (created or overwritten).
ctxSimulation context.
simulation_idUnique ID for this model instance.
Returns
0 on success, non-zero on error.
Here is the call graph for this function:

Variable Documentation

◆ GP_MAGIC_1

uint8_t openswmm::gpkg::GP_MAGIC_1 = 0x47
constexpr

◆ GP_MAGIC_2

uint8_t openswmm::gpkg::GP_MAGIC_2 = 0x50
constexpr

◆ WKB_LITTLE_ENDIAN

uint8_t openswmm::gpkg::WKB_LITTLE_ENDIAN = 1
constexpr