edisgo.io.db

Module Contents

Functions

config_settings(→ dict[str, dict[str, ...)

Return a nested dictionary containing the configuration settings.

credentials(→ dict[str, str | int | pathlib.Path])

Return local database connection parameters.

ssh_tunnel(→ str)

Initialize an SSH tunnel to a remote host according to the input arguments.

engine(→ sqlalchemy.engine.base.Engine)

Engine for local or remote database.

session_scope_egon_data(engine)

Provide a transactional scope around a series of operations.

sql_grid_geom(→ geoalchemy2.types.Geometry)

get_srid_of_db_table(→ int)

sql_within(geom_a, geom_b, srid)

Checks if geometry a is completely within geometry b.

sql_intersects(geom_col, geom_shape, srid)

edisgo.io.db.config_settings(path: pathlib.Path | str) dict[str, dict[str, str | int | pathlib.Path]][source]

Return a nested dictionary containing the configuration settings.

It’s a nested dictionary because the top level has command names as keys and dictionaries as values where the second level dictionary has command line switches applicable to the command as keys and the supplied values as values.

So you would obtain the --database-name configuration setting used by the current invocation of egon-data via

settings()["egon-data"]["--database-name"]
Parameters:

path (pathlib.Path or str) – Path to configuration YAML file of egon-data database.

Returns:

Nested dictionary containing the egon-data and optional ssh tunnel configuration settings.

Return type:

dict

edisgo.io.db.credentials(path: pathlib.Path | str) dict[str, str | int | pathlib.Path][source]

Return local database connection parameters.

Parameters:

path (pathlib.Path or str) – Path to configuration YAML file of egon-data database.

Returns:

Complete DB connection information.

Return type:

dict

edisgo.io.db.ssh_tunnel(cred: dict) str[source]

Initialize an SSH tunnel to a remote host according to the input arguments. See https://sshtunnel.readthedocs.io/en/latest/ for more information.

Parameters:

cred (dict) – Complete DB connection information.

Returns:

Name of local port.

Return type:

str

edisgo.io.db.engine(path: pathlib.Path | str, ssh: bool = False) sqlalchemy.engine.base.Engine[source]

Engine for local or remote database.

Parameters:
  • path (str) – Path to configuration YAML file of egon-data database.

  • ssh (bool) – If True try to establish ssh tunnel from given information within the configuration YAML. If False try to connect to local database.

Returns:

Database engine

Return type:

sqlalchemy.Engine

edisgo.io.db.session_scope_egon_data(engine: sqlalchemy.engine.base.Engine)[source]

Provide a transactional scope around a series of operations.

edisgo.io.db.sql_grid_geom(edisgo_obj: edisgo.EDisGo) geoalchemy2.types.Geometry[source]
edisgo.io.db.get_srid_of_db_table(session: sqlalchemy.orm.session.Session, geom_col: sqlalchemy.orm.attributes.InstrumentedAttribute) int[source]
edisgo.io.db.sql_within(geom_a: geoalchemy2.types.Geometry, geom_b: geoalchemy2.types.Geometry, srid: int)[source]

Checks if geometry a is completely within geometry b.

Parameters:
  • geom_a (Geometry) – Geometry within geom_b.

  • geom_b (Geometry) – Geometry containing geom_a.

  • srid (int) – SRID geometries are transformed to in order to use the same SRID for both geometries.

edisgo.io.db.sql_intersects(geom_col: sqlalchemy.orm.attributes.InstrumentedAttribute, geom_shape: geoalchemy2.types.Geometry, srid: int)[source]