Commit Graph

20 Commits

Author SHA1 Message Date
Tom Kralidis f9fb2c6005 move to f-strings for string interpolation (#1064)
* update from format() to f-strings

* fix

* fix

* fix ref

* update headers
2022-12-08 16:09:19 -05:00
John A Stevenson 644281359a Add CQL to PostgreSQL provider (via pygeofilter and sqlalchemy) (#964)
* Add pygeofilter, unpin psycopg2

* Add pygeofilter SQLAlchemy query demo

* Add note about primary key

* Add todos to script

* Make script generic

* Add (commented out) PostgreSQL provider hotosm_bdi_waterways to config

* Update to use local test database

* Return result as dictionary

* Pass GEOM_FIELD as variable

* Add offset and limt, fix two names

* Implement order by

* Use function for cql query

* Add cql query block to query and test

* Link up to db engine

* Convert WKB geometry to GeoJSON

* Add shapely as explicit dependency

* Add tests for CQL queries

* Add test using CROSSES with LINESTRING

* Uncomment Docker PostGIS test layer

* First pass at wiring up API

The CQL is read from the request but the parser fails to convert to
AST.

* Turn logging to DEBUG

Example query
http://localhost:5000/collections/hot_osm_waterways/items?cql=%27osm_id%20BETWEEN%2080800000%20AND%2080900000%20AND%20name%20IS%20NULL%27

* Create dedicated pygeoapi-config.yml for testing PostgreSQL

* Add test for PostgreSQL CQL

* Return 400 for bad CQL

* Tidy up old files

* Bring API error type tests together

* Only reflect the table of interest

* Add pygeofilter to requirements

* Remove local setup_env.sh from .gitignore

* Remove lark exception handling

* Remove lark codes from tests, docstring change

* Split cql test into good and error

* Rename cql parameter to filter

* Add optional filter-lang parameter with test

* Initial changes

* Rename cql text parser

* Use CQL-JSON POST for PostgreSQL query

* Refactor to get data early and handle errors

* Add error tests for CQL-JSON PostgreSQL

* Add tests for prev/next and provider instantiation

* As filter-lang is set the block in not needed

* Clarify test fixtures

* Use filterq only in all CQL calls

* Make engine and table_model attributes of provider

* Handle different instantiation failures

* Use SQLAlchemy for get_fields()

* Minor doc edits

* Use SQLAlchemy for get()

* Simplify _sqlalchemy_to_feature

* Store database parameters in dedicated function

* Strip out non-SQLAlchemy code

* Add draft query() based on CQL filters

* Add property filtering to query()

* Implement select_properties and skip_geometry

* Implement bbox filter

* Implement properties subset defined in config

* Clean up materialized view test

We only need to test the fields that are present to be sure that the
view has been accessed, so other checks have been removed.

* Flake8 fixes and tidy up

* Add combined test for CQL with bbox and properties

* Create sessions directly where required

* Add Engine store to allow connection reuse

* Replace cql_ast with filterq

* Tidy up tests by using fixture for api

* Add authors

* Use Session() as context manager

A session requires a connection to the database, as provided by the
SQLAlchemy engine.  When the session goes out of scope, e.g. at exit
from the function when it was used, it should be garbage collected and
the connection freed.  However, during load testing it was found that
this wasn't happening.  This commit uses a context manager pattern to
start the session, which ensures that the session is closed at the end
of the `with` block.

* Return fields type as {'type': ...}

* Cache the table_model with the engine

Generating the table_model by "reflecting" the database is expensive but
the resulting model doesn't change.  If we cache the table_model with
the engine we save on a round-trip to the database and speed up response
time.

* Use separate stores for Engine and table_models

Using a combined store based on both engine and table_model meant that
a pygeoapi serving multiple tables on the same database would maintain
a connection pool for each table.  This could eventually saturate the
number of available connections.  This commit separates the store into
two parts.

* Update documentation with example

* Manage or post items based on POST content type

* ghcr build action

* only ghcr job

* run criteria edit

* Update README.md

* job = main

* remove success requirememt

* add tag

* tags: bgs-cql

* Update main.yml

* Update README.md

* remove binary

* update

* Update actions to latest versions

* Dockerfile refactor

* Dockerfile refactor

* restore dockerhub

* fix pygeoif version

* # 3.6 test & dockerhub ref

* Pin pygeoif version to less than 1

* Replace psycopg-binary with psycopg

* Split Docker build into sections

* Pin click version >7,<=8

* Add further cql examples

* Update workflows to match GeoPython repo

* update flake python version

* Unquote PostgreSQL column names

* Update container workflow uses versions

* flake8 use python version 3.7

* Use pre ping to get db connection

* Test that properties are set in provider

* Amendments as requested by @tomkralidis

* Correction

* Fix reviewed changes in api code

Co-authored-by: Colin Blackburn <colb@bgs.ac.uk>
Co-authored-by: KoalaGeo <eddlewis85@gmail.com>
Co-authored-by: Edd <edlew@bgs.ac.uk>
Co-authored-by: Colin Blackburn <ximenesuk@users.noreply.github.com>
2022-10-29 02:15:31 -04:00
David Bitner 15e7deabed Fix SQL injection vulnerability. Fix bug with schema prefixed tables. (#889)
* Do not use str.format() for database queries. Ensure that pg columns returned respect schema prefix.

* quotes not needed with %s

* use sorted on test array comparison

* linting
2022-04-25 20:37:02 -04:00
James Robinson eb891010b7 Add support for materialised views to postgres provider (#827) 2021-12-07 18:00:08 -05:00
James Robinson 3969fc0b19 Add support for config file properties to PostgreSQL provider (#829)
* 🐛 Add support for the properties keyword from the config file

* 🚨 Fixed flake8 errors

*  Added a test for config properties
2021-12-06 07:58:39 -05:00
Benjamin Webb a54fd6a908 Add postgres provider query parameters (#784)
* Add sortby, skip_geometry, and select_properties

* some pytest fixes

* Update main.yml

* Update main.yml

* fix geom in response feature

* more pytest fixes

* Update postgresql.py

* Update test_postgresql_provider.py

* Update test_postgresql_provider.py

* Add to docs, fix pytest

* fix for when when 'name' = None

* Update test_postgresql_provider.py

* Update test_postgresql_provider.py

* Remove optional comparator

* use secrets with default password

* Add secret to load postgres data
2021-09-25 07:03:38 -04:00
Tom Kralidis da824fba8f add support for OGC API - Coverages (#110) (#516)
* add support for OGC API - Coverages

* fix coverage CRS ref

* fix ref to OACov schemas for testing

* move spectral testing to after_success

* update docs

* add mask param to rasterio provider
2020-08-21 09:52:17 -04:00
Francesco Bartoli b8dbd9673c Catch http errors and item not found (#416)
Change class name


Fix flake8


Fix exceptions order


Add missing class name changes


Fix get function for geojson provider


Fix get function for ES provider


Fix ES tests


Fix ES tests


Change word


Fix get function for csv and mongo providers


Fix import


Fix flake8


Fix get function for sqlite/gpkg provider


Fix get function for PG provider


Fix postgres tests


Fix postgres tests


Fix postgres tests
2020-04-21 14:48:02 -04:00
Jorge S. Mendes de Jesus a16ac938cc where implementation on resulttype=hits 2020-02-23 08:34:35 +01:00
Andrew Yan 0b142f2991 Merge branch 'master' of github.com:geopython/pygeoapi into bbox-query 2019-11-04 08:50:21 -06:00
Mary Bucknell e4a36e7248 Add ability to filter by properties to postgresql provider. (#283)
* The json_serial function needs to be provided in order to dump decimal.Decimal values correctly.

* Added ability to filter on property values

* Added allow_property_filters config parameter.

* Added tests for ability to filter on properties

* Add comment to describe fields attribute

* Fixed PEP8 issues

* Missed a PEP8 lint error

* Added name to authors list

* Consistent string formatting

* Remove config parameter allow_property_filtering

* Revert logging statement
2019-11-02 06:25:29 -04:00
Andrew Yan 5df936d65e http://docs.opengeospatial.org/DRAFTS/17-069r1.html#_parameter_bbox specify that bbox queries should use intersect rather than contains 2019-11-01 09:06:23 -05:00
Andrew Yan fe4c02a388 Merge branch 'master' of github.com:geopython/pygeoapi into bbox-query 2019-10-28 16:43:33 -05:00
Andrew Yan f9685b3b86 cutdown excessively long lines 2019-10-23 14:51:45 -05:00
Andrew Yan 3bd7fc2724 switch spatial operator from intersects to contained-by 2019-10-23 14:03:01 -05:00
Andrew Yan 89d8905c8d support a bbox for the postgres provider 2019-10-23 13:39:22 -05:00
Jorge de Jesus d9d749ad8a implements search paths and user defined geom 2019-10-20 17:14:55 +02:00
Tom Kralidis fcc3b37693 fix GeoJSON response for PostgreSQL, SQLite and GeoPackage (#95) 2019-09-12 07:29:40 -04:00
Tom Kralidis 1fd8056b7c address OSGeo incubation committee comments 2019-06-04 03:17:00 +00:00
Jorge Samuel Mendes de Jesus c621b21391 Postgis provider support (#72)
* 	new file:   docker/Dockerfile
Dockerfile for pygeoapi

* testing postgis on travis

* testing 9.6

* install postgis as package

* create database

* postgis dataset - travis

* missing path

* 	modified:   tests/data/hotosm_bdi_waterways.sql.gz

Change in name of dataset

* postgresql code

* 	modified:   pygeoapi/provider/postgresql.py
update with origin

* Postgresql working provider, typo in geopackage

* update to travis. Change on gpkg

* missing dep (psycopg2)

* pytest

* problem with operator in travis

* ProviderConnectionError implementation

* postgresql with schema support

* Changes requested by @tomkralidis

* missing pygeoapi-config.yml

* delete openapi.yml

deleted openapi.yml
2018-11-16 11:53:31 -05:00