External Database
This module provides functionality for working with external databases.
- class DBCredentials(db_type, host, port, db_name, username, password, schemas=None)[source]
Bases:
objectDatabase connection credentials
- Parameters:
db_type (DBType)
host (str)
port (str)
db_name (str)
username (str)
password (str)
schemas (str | None)
- host: str
e.g. localhost or 192.168.1.10
- port: str
e.g. 5432
- db_name: str
e.g. mygeodb
- username: str
e.g. postgres
- password: str
password
- schemas: str | None = None
Comma-separated list of PostgreSQL schemas to include. Leave empty to scan all schemas e.g. public, myapp (leave empty for all schemas)
- class DatabaseTable(api, database, data=None)[source]
Bases:
Base- Parameters:
api (GeoboxClient)
database (Database)
data (Dict | None)
- BASE_ENDPOINT = 'dbImport/'
- __init__(api, database, data=None)[source]
Constructs all the necessary attributes for the DatabaseTable object.
- Parameters:
api (GeoboxClient) – The GeoboxClient instance.
database (Database) – the Database instance.
data (Dict, optional) – The data of the table.
- __repr__()[source]
Return a string representation of the DatabaseTable object.
- Returns:
A string representation of the DatabaseTable object.
- Return type:
str
- import_spatial(table_name=None, out_layer_name=None, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
Import a spatial table/layer from an external database and publish it as a vector layer.
- Parameters:
table_name (str, optional) – Source table or layer name in the external database
out_layer_name (str, optional) – Name for the new vector layer to create
input_srid (int, optional) – Source coordinate reference system EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.db_connection import Database, DBCredentials, DBType >>> client = GeoboxClient() >>> creds = DBCredentials(...)
>>> tables = Database.get_database_tables(client, creds) or >>> tables = client.get_database_tables(creds)
>>> tables[0].import_spatial()
- import_non_spatial(table_name=None, out_table_name=None, report_errors=False, user_id=False)[source]
Import a non-spatial table from an external database and publish it as a Geobox Table.
- Parameters:
table_name (str, optional) – Source table name in the external database
out_table_name (str, optional) – Name for the new table to create
report_errors (bool, optional) – Include per-row import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.db_connection import Database, DBCredentials, DBType >>> client = GeoboxClient() >>> creds = DBCredentials(...)
>>> tables = Database.get_database_tables(client, creds) or >>> tables = client.get_database_tables(creds)
>>> tables[0].import_non_spatial()
- import_spatial_into_layer(layer_uuid, table_name=None, is_view=False, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
Import a spatial table/layer from an external database and append its features into an existing vector layer identified by layer_uuid.
- Parameters:
layer_uuid (str) – UUID of the existing vector layer to import into
table_name (str, optional) – Source table or layer name in the external database
is_view (bool, optional) – Whether the target layer is a vector layer view. default: False
input_srid (int, optional) – Source CRS EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.db_connection import Database, DBCredentials, DBType >>> client = GeoboxClient() >>> creds = DBCredentials(...)
>>> layer = client.get_vectors()[0]
>>> tables = Database.get_database_tables(client, creds) or >>> tables = client.get_database_tables(creds)
>>> tables[0].import_spatial_into_layer(layer_uuid=layer.uuid)
- import_table(table_name=None, out_name=None, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
Import a spatial table/layer from an external database and append its features into an existing vector layer identified by layer_uuid.
This method acts as a dispatcher that automatically routes the import request to the appropriate method (import_spatial for tables with geometry columns or import_non_spatial for tables without geometry).
- Parameters:
table_name (str, optional) – Source table or layer name in the external database.
out_name (str, optional) – Name for the output resource (vector layer or table) in Geobox.
input_srid (int, optional) – Source CRS EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.db_connection import Database, DBCredentials, DBType >>> client = GeoboxClient() >>> creds = DBCredentials(...)
>>> layer = client.get_vectors()[0]
>>> tables = Database.get_database_tables(client, creds) or >>> tables = client.get_database_tables(creds)
>>> tables[0].import()
See also
import_spatial(): For explicitly importing spatial tables
import_non_spatial(): For explicitly importing non-spatial tables
import_spatial_into_layer(): For importing into an existing layer
- class Database(api, creds)[source]
Bases:
Base- Parameters:
api (GeoboxClient)
creds (DBCredentials)
- BASE_ENDPOINT = 'dbImport/'
- __init__(api, creds)[source]
Constructs all the necessary attributes for the Database object.
- Parameters:
api (GeoboxClient) – The GeoboxClient instance.
creds (DBCredentials) – the database connection credentials
- __repr__()[source]
Return a string representation of the Database object.
- Returns:
A string representation of the Database object.
- Return type:
str
- classmethod get_database_tables(api, creds)[source]
Get the list of tha database tables
- Parameters:
api (GeoboxClient) – The GeoboxClient instance.
creds (DBCredentials) – the database connection credentials
- Returns:
list of the database tables
- Return type:
List[DatabaseTable]
Example
>>> from geobox import GeoboxClient >>> from geobox.db_connection import Database, DBCredentials, DBType >>> client = GeoboxClient() >>> creds = DBCredentials(...)
>>> tables = Database.get_database_tables(client, creds) or >>> tables = client.get_database_tables(creds)