From ec6fb380f3d3f74fbc12a38815a4072d691ec9cd Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:35:01 -0400 Subject: [PATCH] Updates to the sparql provider to match the mainstem query (#22) * Query Mainstems and Gages with SPARQL provider (7261757324) * Update SPARQL provider * Use pygeoapi root image * updates to the sparql provider to match the mainstem query * updated docker compose * update readme * Update pygeoapi.config.yml Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> * Update docker-compose.yml Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> * reversions * indent * indent again for diff * update sparql config * change back to error * add indent * Update pygeoapi.config.yml --------- Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> --- .gitignore | 3 + Dockerfile | 5 +- README.md | 18 ++++- docker-compose.yml | 30 +++++++- .../templates/collections/items/item.html | 2 +- .../templates/jsonld/hu06.jsonld | 2 +- pygeoapi.config.yml | 69 +++++++++---------- 7 files changed, 82 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 68bc17f..eaec569 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +*.sql.gz \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2bd7e12..d4eeb47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,11 @@ FROM geopython/pygeoapi:latest #pygeoapi last updated 2023-07-31 -#add requirements and mods -COPY ./pygeoapi.config.yml /pygeoapi/local.config.yml - # COPY ./schemas.opengis.net /opt/schemas.opengis.net COPY ./pygeoapi-skin-dashboard /skin-dashboard +COPY ./pygeoapi.config.yml /pygeoapi/local.config.yml + RUN pip3 install https://github.com/cgs-earth/pygeoapi-plugins/archive/refs/heads/master.zip COPY ./sitemap /sitemap diff --git a/README.md b/README.md index 57da026..0ddfe32 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,23 @@ These reference features are intended to be ["community reference locations"](ht ## Install -Generate a SQL Dump of the Hydroshare resource using [Hydrodump Action](https://github.com/cgs-earth/hydrodump-action). - -Then use docker compose to bring up the containers: +Use docker compose to bring up the containers: ``` docker compose up -d database docker compose up -d pygeoapi ``` + +Then generate a SQL Dump of the Hydroshare resource using [Hydrodump Action](https://github.com/cgs-earth/hydrodump-action). + +``` +docker compose up -d hydrodump +``` + +If you have a local hydrodump `reference.sql.gz` file, you can use that instead of regenerating the dump using + +``` +docker compose up -d local +``` + + diff --git a/docker-compose.yml b/docker-compose.yml index e510062..8981e6c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,11 @@ -# dont need this anymore, but useful for test deployment -# requires separate service providing postgres database services: pygeoapi: build: . container_name: reference-geoconnex-us ports: - 5000:80 + volumes: + - ./pygeoapi.config.yml:/pygeoapi/local.config.yml env_file: - .env @@ -14,6 +14,8 @@ services: image: postgis/postgis:14-3.2-alpine env_file: - .env + volumes: + - db_data:/var/lib/postgresql/data hydrodump: container_name: hydrodump @@ -21,3 +23,27 @@ services: command: ["hydrodump", "run"] env_file: - .env + + local: + # Instead of using a remote hydrodump, you can source a local database dump, reference.sql.gz + container_name: local + image: postgis/postgis:14-3.2-alpine + depends_on: + - database + volumes: + - ./reference.sql.gz:/docker-entrypoint-initdb.d/reference.sql.gz + entrypoint: > + sh -c " + export PGPASSWORD=${POSTGRES_PASSWORD} && \ + echo 'Waiting for database to be ready...' && \ + while ! pg_isready -h ${POSTGRES_HOST} -U ${POSTGRES_USER} -d ${POSTGRES_DB}; do + sleep 1 + done && \ + echo 'Database is ready. Starting migration...' && \ + gunzip -c /docker-entrypoint-initdb.d/reference.sql.gz | psql -h ${POSTGRES_HOST} -U ${POSTGRES_USER} -d ${POSTGRES_DB} + " + env_file: + - .env + +volumes: + db_data: diff --git a/pygeoapi-skin-dashboard/templates/collections/items/item.html b/pygeoapi-skin-dashboard/templates/collections/items/item.html index 0de346c..1b69afc 100644 --- a/pygeoapi-skin-dashboard/templates/collections/items/item.html +++ b/pygeoapi-skin-dashboard/templates/collections/items/item.html @@ -172,4 +172,4 @@

Datasets

map.addLayer(items); map.fitBounds(items.getBounds(), {maxZoom: 10}); -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/pygeoapi-skin-dashboard/templates/jsonld/hu06.jsonld b/pygeoapi-skin-dashboard/templates/jsonld/hu06.jsonld index 9a60f0a..4cec597 100644 --- a/pygeoapi-skin-dashboard/templates/jsonld/hu06.jsonld +++ b/pygeoapi-skin-dashboard/templates/jsonld/hu06.jsonld @@ -18,4 +18,4 @@ ], "gsp:hasGeometry": {{ data['gsp:hasGeometry'] | to_json }}, "geo": {{ data['schema:geo'] | to_json | safe }} -} +} \ No newline at end of file diff --git a/pygeoapi.config.yml b/pygeoapi.config.yml index e553bc8..17ee821 100644 --- a/pygeoapi.config.yml +++ b/pygeoapi.config.yml @@ -404,62 +404,57 @@ resources: bind: name: uri variable: '?mainstem' - select: '?mainstem ?monitoringLocation ?siteName ?datasetDescription ?type ?url ?variableMeasured ?variableUnit ?measurementTechnique ?temporalCoverage ?wkt' + select: '?mainstem ?monitoringLocation ?siteName ?datasetDescription ?type ?url ?variableMeasured ?variableUnit ?measurementTechnique ?temporalCoverage ?distributionName ?distributionURL ?distributionFormat ?wkt' where: - subject: '?monitoringLocation' - predicate: hyf:referencedPosition/hyf:HY_IndirectPosition/hyf:linearElement - object: '?mainstem' + predicate: 'hyf:HydroLocationType' + object: '?type' - subject: '?monitoringLocation' - predicate: schema:name - object: '?siteName' + predicate: 'hyf:referencedPosition/hyf:HY_IndirectPosition/hyf:linearElement' + object: '?mainstem' - subject: '?monitoringLocation' - predicate: schema:subjectOf + predicate: 'schema:subjectOf' object: '?dataset' + - subject: '?monitoringLocation' + predicate: 'gsp:hasGeometry/gsp:asWKT' + object: '?wkt' - subject: '?dataset' - predicate: schema:url + predicate: 'schema:variableMeasured' + object: '?var' + - subject: '?dataset' + predicate: 'schema:url' object: '?url' - subject: '?dataset' - predicate: schema:distribution + predicate: 'schema:distribution' object: '?distribution' - - subject: '?distribution' - predicate: schema:name - object: '?distributionName' - - subject: '?distribution' - predicate: schema:contentUrl - object: '?distributionURL' - - subject: '?distribution' - predicate: schema:encodingFormat - object: '?distributionFormat' - subject: '?dataset' - predicate: schema:description + predicate: 'schema:description' object: '?datasetDescription' - - subject: '?monitoringLocation' - predicate: hyf:HydroLocationType - object: '?type' - subject: '?dataset' - predicate: 'schema:variableMeasured' - object: '?variableMeasured_' - - subject: '?variableMeasured_' + predicate: 'schema:temporalCoverage' + object: '?temporalCoverage' + - subject: '?dataset' + predicate: 'schema:name' + object: '?siteName' + - subject: '?var' predicate: 'schema:name' object: '?variableMeasured' - - subject: '?variableMeasured_' + - subject: '?var' predicate: 'schema:unitText' object: '?variableUnit' - - subject: '?variableMeasured_' + - subject: '?var' predicate: 'schema:measurementTechnique' object: '?measurementTechnique' - - subject: '?variableMeasured_' - predicate: 'schema:name' - object: '?variableMeasured' - - subject: '?dataset' - predicate: 'schema:temporalCoverage' - object: '?temporalCoverage' - - subject: '?dataset' - predicate: 'schema:provider' - object: '?provider' - - subject: '?provider' + - subject: '?distribution' predicate: 'schema:name' - object: '?datasetProvider' + object: '?distributionName' + - subject: '?distribution' + predicate: 'schema:contentUrl' + object: '?distributionURL' + - subject: '?distribution' + predicate: 'schema:encodingFormat' + object: '?distributionFormat' + dams: # updated 2024-04-23 type: collection title: Reference Dams