Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OGC API - Moving Features support #1871

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ RUN \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*

ADD requirements-docker.txt requirements-admin.txt /pygeoapi/
ADD requirements-docker.txt requirements-admin.txt requirements-provider.txt /pygeoapi/

# Install remaining pygeoapi deps
RUN python3 -m pip install --no-cache-dir -r requirements-docker.txt \
&& python3 -m pip install --no-cache-dir -r requirements-admin.txt
&& python3 -m pip install --no-cache-dir -r requirements-admin.txt \
&& python3 -m pip install --no-cache-dir -r requirements-provider.txt

# If execute pytest
ADD requirements-dev.txt /pygeoapi/
RUN python3 -m pip install --no-cache-dir -r requirements-dev.txt

ADD . /pygeoapi

Expand All @@ -142,4 +147,3 @@ RUN \
&& cp /pygeoapi/docker/entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

54 changes: 54 additions & 0 deletions DockerfileMobiitydb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM postgis/postgis:17-3.5

# Configuration Parameters
LABEL maintainer="MobilityDB Project - https://github.com/MobilityDB/MobilityDB"
ENV MOBILITYDB_VERSION 1.2.0
ENV POSTGRES_DB=mobilitydb
ENV POSTGRES_USER=docker
ENV POSTGRES_PASSWORD=docker

# Fix the Release file expired problem
RUN echo "Acquire::Check-Valid-Until \"false\";\nAcquire::Check-Date \"false\";" | cat > /etc/apt/apt.conf.d/10no--check-valid-until


# Install Prerequisites
RUN apt-get update \
&& apt-get install -y \
build-essential \
cmake \
git \
libproj-dev \
g++ \
wget \
autoconf \
autotools-dev \
libgeos-dev \
libpq-dev \
libproj-dev \
libjson-c-dev \
protobuf-c-compiler \
xsltproc \
libgsl-dev \
libgslcblas0 \
postgresql-server-dev-${PG_MAJOR} \
&& rm -rf /var/lib/apt/lists/*

# Install MobilityDB
RUN wget -O MobilityDB.tar.gz "https://github.com/MobilityDB/MobilityDB/archive/v${MOBILITYDB_VERSION}.tar.gz" \
&& mkdir -p /usr/local/src/MobilityDB \
&& tar \
--extract \
--file MobilityDB.tar.gz \
--directory /usr/local/src/MobilityDB \
--strip-components 1 \
&& rm MobilityDB.tar.gz
RUN mkdir /usr/local/src/MobilityDB/build
RUN cd /usr/local/src/MobilityDB/build && \
cmake .. && \
make -j$(nproc) && \
make install

RUN rm /docker-entrypoint-initdb.d/10_postgis.sh
# Create mf-api table
COPY /docker/initdb-mobilitydb.sh /docker-entrypoint-initdb.d/
RUN chmod +x /docker-entrypoint-initdb.d/initdb-mobilitydb.sh
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.0'
services:
mf-api:
container_name: pygeoapi-mf-api
build:
context: .
dockerfile: Dockerfile
image: pygeoapi-mf-api
volumes:
- ./mf-api.config.yml:/pygeoapi/local.config.yml
ports:
- 5050:80

mobilitydb:
container_name: mobilitydb
ports:
- 25432:5432
environment:
- POSTGRES_DB=mobilitydb
- POSTGRES_USER=docker
- POSTGRES_PASSWORD=docker
build:
context: .
dockerfile: DockerfileMobiitydb
image: pygeoapi-mf-api-mobilitydb
restart: on-failure
62 changes: 62 additions & 0 deletions docker/initdb-mobilitydb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

echo "shared_preload_libraries = 'postgis-3.so'" >> $PGDATA/postgresql.conf

set -e

# Create the 'mobilitydb' extension in the mobilitydb database
echo "Loading MobilityDB extension into mobilitydb"
psql --user="$POSTGRES_USER" --dbname="mobilitydb" <<- 'EOSQL'
CREATE EXTENSION IF NOT EXISTS PostGIS;
CREATE EXTENSION IF NOT EXISTS mobilitydb CASCADE;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Table collection
CREATE TABLE public.collection (
collection_id uuid NOT NULL DEFAULT uuid_generate_v4(),
collection_property jsonb NULL,
PRIMARY KEY (collection_id)
);
-- Table MovingFeature
CREATE TABLE public.mfeature (
collection_id uuid NOT NULL,
mfeature_id uuid NOT NULL DEFAULT uuid_generate_v4(),
mf_geometry geometry NULL,
mf_property jsonb NULL,
lifespan tstzspan NULL,
PRIMARY KEY (collection_id, mfeature_id),
FOREIGN KEY (collection_id) REFERENCES collection(collection_id)
);
-- Table TemporalGeometry
CREATE TABLE public.tgeometry (
collection_id uuid NOT NULL,
mfeature_id uuid NOT NULL,
tgeometry_id uuid NOT NULL DEFAULT uuid_generate_v4(),
tgeometry_property tgeompoint NULL,
tgeog_property tgeompoint NULL,
PRIMARY KEY (collection_id, mfeature_id, tgeometry_id),
FOREIGN KEY (collection_id, mfeature_id) REFERENCES mfeature(collection_id, mfeature_id)
);
-- Table TemporalProperty
CREATE TABLE public.tproperties (
collection_id uuid NOT NULL,
mfeature_id uuid NOT NULL,
tproperties_name text NOT NULL,
tproperty jsonb NULL,
PRIMARY KEY (collection_id, mfeature_id, tproperties_name),
FOREIGN KEY (collection_id, mfeature_id) REFERENCES mfeature(collection_id, mfeature_id)
);

-- Table TemporalPropertyValue
CREATE TABLE public.tvalue (
collection_id uuid NOT NULL,
mfeature_id uuid NOT NULL,
tproperties_name text NOT NULL,
tvalue_id uuid NOT NULL DEFAULT uuid_generate_v4(),
datetime_group int4 NOT NULL,
pvalue_float tfloat NULL,
pvalue_text ttext NULL,
PRIMARY KEY (collection_id, mfeature_id, tproperties_name, tvalue_id),
FOREIGN KEY (collection_id, mfeature_id, tproperties_name) REFERENCES tproperties(collection_id, mfeature_id, tproperties_name)
);
EOSQL
1 change: 1 addition & 0 deletions docs/source/data-publishing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ return back data to the pygeoapi API framework in a plug and play fashion.
ogcapi-records
ogcapi-edr
stac
ogcapi-mfapi


.. seealso::
Expand Down
125 changes: 125 additions & 0 deletions docs/source/data-publishing/ogcapi-mfapi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
.. _ogcapi-mfapi:

Publishing data to OGC API - MF-API
=====================================

`OGC API - MF-API`_ provides provides a uniform way to access, communicate, and
anage data about moving features across different applications, data providers,
and data consumers.

To add moving features data to pygeoapi for standard interfaces,
which is defined in the OGC API - MovingFeatures - Part 1:Core.
you can use the dataset example in `Building Blocks specified in OGC API - Moving Features - Part 1 Core (1.0.0)`_
as a baseline and modify accordingly.

Configuration
-------------

In order to register data for Moving features, the DB must be created and the related tables must be initially set up.


PostgreSQL
^^^^^^^^^^
.. note::
Requires Python packages pymeos

Must have PostGIS installed and uuid-ossp

.. code-block:: yaml

server:
manager:
name: PostgreSQL
connection:
host: localhost
port: 5432
database: mobilitydb
user: postgres
password: ${POSTGRESQL_PASSWORD:-postgres}

.. note::
To run the process, create a table with `DDL <https://github.com/ogi-ts-shimizu/pygeoapi-ogi-mf-api/blob/mf-api-updates/tests/data/mf-api.sql>`_


.. code-block:: sh

psql -U postgres -h 127.0.0.1 -p 5432 mobilitydb < tests/data/mf-api.sql


Processing examples
-------------------

.. note::
`Here <https://github.com/ogi-ts-shimizu/pygeoapi-ogi-mf-api/tree/mf-api-updates/tests/data>`_ is the sample data specified by the -d option of the curl command.

.. code-block:: sh

# Register metadata about a collection of moving features.
curl -X POST http://localhost:5000/collections \
-H "Content-Type: application/json" \
-d "{\"title\": \"moving_feature_collection_sample\",
\"updateFrequency\": 1000,
\"description\": \"example\",
\"itemType\": \"movingfeature\"
}"

# Retrieve catalogs of a moving features collection.
curl http://localhost:5000/collections


# Insert a set of moving features or a moving feature into a collection with id {collectionId}.
curl -X POST http://localhost:5000/collections/{collectionId}/items \
-H "Content-Type: application/json" \
-d @mfapi_moving_feature.json

# Access a static data of a moving feature with id {mFeatureId}.
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}

# Add more movement data into a moving feature with id {mFeatureId}.
curl -X POST http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence \
-H "Content-Type: application/json" \
-d @mfapi_temporal_geometry.json

# Retrieve the movement data of the single moving feature
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence

# Get a time-to-(distance,velocity,acceleration) curve of a temporal primitive geometry
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence/{tGeometryId}/distance
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence/{tGeometryId}/velocity
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence/{tGeometryId}/acceleration

# Add new temporal property data into a moving feature with id {mFeatureId}.
curl -X POST http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties \
-H "Content-Type: application/json" \
-d @mfapi_temporal_properties.json

# Retrieve a set of the temporal property data
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties

# Add temporal primitive value data.
curl -X POST http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties/{tPropertyName} \
-H "Content-Type: application/json" \
-d @mfapi_temporal_property_value_data.json

# Retrieve a set of the temporal property data
curl http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties/{tPropertyName}

# Delete a singe temporal primitive value
curl -X DELETE http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties/{tPropertyName}/{tValueId}

# Delete a specified temporal property
curl -X DELETE http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tproperties/{tPropertyName}

# Delete a singe temporal primitive geometry
curl -X DELETE http://localhost:5000/collections/{collectionId}/items/{mFeatureId}/tgsequence/{tGeometryId}

# Delete a single moving feature
curl -X DELETE http://localhost:5000/collections/{collectionId}/items/{mFeatureId}

# Delete the collection
curl -X DELETE http://localhost:5000/collections/{collectionId}


.. _`OGC API - MF-API`: https://github.com/aistairc/pygeoapi-mf-api
.. _`Building Blocks specified in OGC API - Moving Features - Part 1 Core (1.0.0)`: https://developer.ogc.org/api/movingfeatures/index.html#tag/MovingFeatureCollection/operation/registerMetadata
.. _`see website`: https://mobilitydb.com/
64 changes: 64 additions & 0 deletions docs/source/tour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,67 @@ discover what is supported by the server.
.. _`Toronto, Ontario, Canada`: https://en.wikipedia.org/wiki/Toronto
.. _`Swagger`: https://en.wikipedia.org/wiki/Swagger_(software)
.. _`curl`: https://curl.se


MF-API Tour
-----------
The OGC API - Moving Features Standard is an extension of the OGC API - Common and the OGC API - Features Standards.
MovingFeatures – Part 1: Core is described in the `here <https://github.com/opengeospatial/ogcapi-movingfeatures/tree/master?tab=readme-ov-file>`_.


MovingFeatures Collection Catalog
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
http://localhost:5000/collections

Retrieve catalogs of a moving features collection.

MovingFeatures
^^^^^^^^^^^^^^
http://localhost:5000/{collectionId}/items

Retrieve the moving feature collection to access the static information of the moving feature by simple filtering and a limit.

MovingFeature
"""""""""""""
http://localhost:5000/{collectionId}/items/{mf_id}


Access the static data of the moving feature with id {mFeatureId}.
The static data of a moving feature is not included temporal geometries and temporal properties.

TemporalGeometrySequence
""""""""""""""""""""""""
http://localhost:5000/{collectionId}/items/{mf_id}/tgsequence

Retrieve the movement data of the single moving feature with id {mFeatureId}.

TemporalGeometryQuery
"""""""""""""""""""""
http://localhost:5000/{collectionId}/items/{mf_id}/tgsequence/{tGeometryId}

Get a time-to-distance curve of a temporal primitive geometry with id {tGeometryId}.

TemporalProperties
""""""""""""""""""
http://localhost:5000/{collectionId}/items/{mf_id}/tproperties

Retrieve the static information of the temporal property data that included a single moving feature with id {mFeatureId}.
The static data of a temporal property is not included temporal values (property values).

.. seealso::
:ref:`ogcapi-mfapi` for more OGC API - MF-API request examples.

Transactions
^^^^^^^^^^^^
Register metadata about a collection of moving features. (using `curl`_):

.. code-block:: sh

curl -X POST http://localhost:5000/collections \
-H "Content-Type: application/json" \
-d "{\"title\": \"moving_feature_collection_sample\",
\"updateFrequency\": 1000,
\"description\": \"example\",
\"itemType\": \"movingfeature\"
}"

5 changes: 5 additions & 0 deletions docs/source/transactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ Transactions
pygeoapi supports the `OGC API - Features - Part 4: Create, Replace, Update and Delete`_ draft specification, allowing
for transactional capabilities against feature and record data.

Furthermore, pygeoapi supports the `OGC API - Moving Features - Part 1: Core`_ international standard, allowing
for transactional capabilities against moving features.

To enable transactions in pygeoapi, a given resource provider needs to be editable (via the configuration resource provider
``editable: true`` property). Note that the feature or record provider MUST support create/update/delete. See the
:ref:`ogcapi-features` and :ref:`ogcapi-records` documentation for transaction support status of pygeoapi backends.
For MF-API transactions, please refer :ref:`ogcapi-mfapi`

Access control
^^^^^^^^^^^^^^
Expand All @@ -17,3 +21,4 @@ It should be made clear that authentication and authorization is beyond the resp
if a pygeoapi user enables transactions, they must provide access control explicitly via another service.

.. _`OGC API - Features - Part 4: Create, Replace, Update and Delete`: https://docs.ogc.org/DRAFTS/20-002.html
.. _`OGC API - Moving Features - Part 1: Core`: https://docs.ogc.org/is/22-003r3/22-003r3.html
Loading