Skip to main content

A SQLAlchemy Dialect and DBAPI 2.0 driver for GeoServer WFS

Project description

SQLAlchemy GeoServer Dialect

PyPI

A DB-API 2.0 driver and a SQLAlchemy Dialect designed to query GeoServer WFS layers using pseudo-SQL converted to valid underlying HTTP CQL_FILTER queries.

Installation

pip install sqlalchemy-geoserver

(Note: In the root of this repository, you may install locally using pip install -e .)

Connection String

The SQLAlchemy engine is created using the scheme geoserver+http:// or geoserver+https://. Provide the base URL to your GeoServer workspace's WFS endpoint:

engine = create_engine(
    "geoserver+http://localhost:8080/geoserver/workspace/ows"
)

If your GeoServer instance requires an authorization header, pass it via connect_args:

engine = create_engine(
    "geoserver+https://geoserver.example.com/geoserver/workspace/ows",
    connect_args={"headers": {"Authorization": "Bearer token123"}}
)

Usage

This driver acts as a "Read Only" interface fetching a FeatureCollection from a GeoServer WFS API request. It parses standard SQL SELECT queries that use standard logical operators (==, !=, <, >, IN, LIKE, etc.) and translates those to their equivalent GeoServer CQL.

from sqlalchemy import create_engine, MetaData, Table, select

# Create an engine to the geoserver host and specific workspace/layer path
engine = create_engine(
    "geoserver+http://localhost:8080/geoserver/workspace/ows"
)

# You can also pass authentication headers if required
# engine = create_engine(
#     "geoserver+https://geoserver.example.com/geoserver/workspace/ows",
#     connect_args={"headers": {"Authorization": "Bearer token123"}}
# )

metadata = MetaData()
metadata.reflect(bind=engine)

# Tables correspond to the layer names available at that endpoint
# Assuming there is a layer named 'layer_name'
layer_table = Table('layer_name', metadata, autoload_with=engine)

# Standard SQLAlchemy core query
stmt = select(layer_table).where(layer_table.c.property_name == 'value')

with engine.connect() as conn:
    results = conn.execute(stmt).fetchall()
    for row in results:
        print(row._mapping)

Local GeoServer Setup

To run a local GeoServer instance using Docker:

docker run -d -p 8080:8080 --name geoserver \
  -v ./geoserver_data/:/opt/geoserver_data \
  docker.osgeo.org/geoserver:3.0.x

GeoServer will be available at http://localhost:8080/geoserver. The WFS endpoint for a workspace named myworkspace would be:

geoserver+http://localhost:8080/geoserver/myworkspace/ows

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_geoserver-0.2.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_geoserver-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_geoserver-0.2.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_geoserver-0.2.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for sqlalchemy_geoserver-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bb785f83b814942a1241788114d9fe3736a5c0ef09636e6a4b7828bd258e7c37
MD5 fa92f6224bc43ea1c6365d5e6545a32b
BLAKE2b-256 336bbb5d97b1fad435ae62ba699842eac6085375502f3f4539f0989914be7b76

See more details on using hashes here.

File details

Details for the file sqlalchemy_geoserver-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_geoserver-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61818f08d507c573016c27eade2c15617b7a766617ebba59485345816583e455
MD5 5de051fde040f07bd788add174402cec
BLAKE2b-256 db37ad50bc40778337a00f3f7499d5f99e5fe2ade737fe4eedc1f28ed8243572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page