Skip to main content

geometry

Functions

aws_locator

def aws_locator(pair: tuple | list) -> dict

Function to perform reverse geocoding to collect address information using AWS Locations.

Arguments:

  • pair tuple | list - Input coordinate pair, use normal lat long format.

Raises:

  • Exception - reverse geocoding was impossible

Returns:

  • dict - object contains address information like Street and Number.

Examples:

aws_locator(
pair=[1.0, 1.0]
)

clean_geom

def clean_geom(workspace: str,
layername: str,
connection,
column: str = "geom") -> None

Function to clean empty geometries from table

Arguments:

  • workspace str - Input name of workspace.
  • layername str - Input layer name.
  • connection (psycopg2.connection()) - database connection.
  • column str, optional - name of the column to check. Defaults to "geom".

Returns:

None

data_uploader

def data_uploader(workspace: str,
layername: str,
data: List[dict],
connection,
template: str = "") -> None

Function to wreck database tables. This one leverages execute_values() to insert tons of rows in 1 transaction. The function is aimed for data uploads and will skip any geom attributes.

Arguments:

  • workspace str - Input name of workspace.
  • layername str - Input layer name.
  • data List[dict] - array containing dictionaries keys are the column names and values the, well, values.
  • connection (psycopg2.connection()) - database connection.
  • template str, optional - Input alphabetically ordered column names to resolve the execute_many() check examples on its format. Defaults to "".

Examples:

data_uploader(
workspace="opusinsights_1_nld_1",
layername="contourlines",
data=[
{"foo": 1, "bar": "test"},
{"foo": 3, "bar": "test2"}
],
connection=connection(),
template="(%(date)s, %(elev)s, %(uid)s, %(wkt)s)"
)

upload_geom

def upload_geom(workspace: str,
layername: str,
connection,
crs: int,
date: str,
wkt: str = "",
on_premise: bool = True,
drop_wkt: bool = True,
id_column: str = "id") -> None

Function to upload geometry to a PostGIS enabled PostgreSQL database

Arguments:

  • workspace str - Input name of workspace.
  • layername str - Input layer name.
  • connection (psycopg2.connection()) - database connection.
  • crs int - Input CRS as integer (EPSG:4326 -> 4326).
  • date str - Input date of geometry to handle constrained updates.
  • wkt str, optional - Input Well Known Text, mutually exclusive with on_premise. Defaults to "".
  • on_premise bool, optional - Switch to create geometries on existing WKT attribute in table mutually exclusive with wkt. Defaults to True.
  • drop_wkt bool, optional - Drop the WKT string in the table after uploading, will skip if WKT is not present in table. Defaults to True.
  • id_column str, optional - ID column used to count the number of rows. Defaults to "id".

Examples:

upload_geom(
workspace="opusinsights_1_nld_1",
layername="contourlines",
date="2021-01-01",
connection=DB_connection,
crs=4326,
wkt="POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))",
on_premise=False,
drop_wkt=False
)

This example only works when attribute geom in present in table.

upload_geom(
workspace="opusinsights_1_nld_1",
layername="contourlines",
date="2021-01-01",
connection=DB_connection,
crs=4326,
wkt="",
on_premise=True,
drop_wkt=True,
id_column="id_0"
)