Repository navigation
OGC record collections endpoints #1310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d079ea9
first draft for ogc views
lotte-amsterdam 26864c9
added records index view, tests and removed template for collection a…
lotte-amsterdam e0e0bf0
removed dataset_version for OGC records view
lotte-amsterdam 0c0bcb3
added OGC links to docs
lotte-amsterdam d27cfd8
changed after review
lotte-amsterdam 15b2ab7
fixed failing router tests
lotte-amsterdam b6c2f5b
removed copied routers file
lotte-amsterdam ec4deff
renamed ogc_dataset.html
lotte-amsterdam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import logging | ||
|
|
||
| from django.views.generic import TemplateView | ||
| from rest_framework.renderers import JSONRenderer | ||
| from rest_framework.response import Response | ||
| from rest_framework.views import APIView | ||
|
|
||
| from dso_api.dynamic_api.datasets import get_active_datasets | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class OGCIndexView(TemplateView): | ||
| """Overview of available OGC endpoints.""" | ||
|
|
||
| template_name = "dso_api/dynamic_api/ogc_index.html" | ||
| name = "OGC endpoints" | ||
| api_type = "OGC" | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
|
|
||
| base = self.request.build_absolute_uri("/").rstrip("/") | ||
| context["records_url"] = f"{base}/v1/ogc/records" | ||
|
|
||
| return context | ||
|
|
||
|
|
||
| class OGCRecordsIndexView(TemplateView): | ||
| """Overview of OGC Records endpoints.""" | ||
|
|
||
| template_name = "dso_api/dynamic_api/ogc_records.html" | ||
| name = "OGC records" | ||
| api_type = "OGC" | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
|
|
||
| base = self.request.build_absolute_uri("/").rstrip("/") | ||
| context["collection_url"] = f"{base}/v1/ogc/records/collections" | ||
|
|
||
| return context | ||
|
|
||
|
|
||
| class OGCRecordsCollectionView(APIView): | ||
| """Shows a JSON page with an overview of record collections.""" | ||
|
|
||
| renderer_classes = [JSONRenderer] | ||
| name = "Record Collections" | ||
|
|
||
| def get_datasets(self): | ||
| return [ | ||
| ds | ||
| for ds in get_active_datasets().db_enabled().order_by("name") | ||
| if ds.has_geometry_fields | ||
| ] | ||
|
|
||
| def get(self, request, *args, **kwargs): | ||
| base = request.build_absolute_uri("/").rstrip("/") | ||
| datasets = self.get_datasets() | ||
|
|
||
| collections = [] | ||
|
|
||
| for dataset in datasets: | ||
| collections.append( | ||
| { | ||
| "id": str(dataset.schema.id), | ||
| "title": dataset.schema.title or dataset.name, | ||
| "description": dataset.schema.description or "", | ||
| "links": [ | ||
| { | ||
| "rel": "self", | ||
| "type": "application/json", | ||
| "href": (f"{base}/v1/ogc/records/collections/{dataset.path}"), | ||
| } | ||
| ], | ||
| } | ||
| ) | ||
|
|
||
| return Response({"collections": collections}) | ||
|
|
||
|
|
||
| class OGCRecordsCollectionDetailView(APIView): | ||
| """An JSON page for a single OGC record collection (dataset).""" | ||
|
|
||
| renderer_classes = [JSONRenderer] | ||
| name = "Records" | ||
|
|
||
| def get_datasets(self): | ||
| return [ | ||
| ds | ||
| for ds in get_active_datasets().db_enabled().order_by("name") | ||
| if ds.has_geometry_fields | ||
| ] | ||
|
|
||
| def get(self, request, *args, **kwargs): | ||
| base = request.build_absolute_uri("/").rstrip("/") | ||
| datasets = self.get_datasets() | ||
| dataset_name = self.kwargs.get("dataset_name") | ||
| collection_url = f"{base}/v1/ogc/records/collections/{dataset_name}" | ||
| records = [] | ||
|
|
||
| ds = next( | ||
| (dataset for dataset in datasets if str(dataset.schema.id) == str(dataset_name)), | ||
| None, | ||
| ) | ||
|
|
||
| for version, _ in ds.schema.versions.items(): | ||
| records.extend( | ||
| self.build_record_collection( | ||
| ds=ds, | ||
| version=version, | ||
| collection_url=collection_url, | ||
| ) | ||
| ) | ||
|
|
||
| return Response({"records": records}) | ||
|
|
||
| def build_record_collection(self, ds, version, collection_url): | ||
| """Handle missing attributes and ensure each OGC field has the expected datatype.""" | ||
| metadata = { | ||
| "id": f"{ds.schema.id}_{version}", | ||
| "conformsTo": [], | ||
| "type": "Collection", | ||
| "itemType": "catalog", | ||
| "title": ds.schema.title or ds.schema.name, | ||
| "description": ds.schema.description or "", | ||
| "language": {"code": "nl", "name": "Dutch (Netherlands)"}, | ||
| "rights": list(ds.schema.auth), | ||
| "recordsArrayName": "records", | ||
| "links": [ | ||
| { | ||
| "rel": "self", | ||
| "type": "application/json", | ||
| "href": collection_url, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| if ds.schema.get("dateCreated"): | ||
| metadata["created"] = ds.schema.get("dateCreated") | ||
|
|
||
| if ds.schema.get("contactPoint"): | ||
| metadata["contacts"] = list(ds.schema.contactPoint) | ||
| else: | ||
| metadata["contacts"] = [{"name": "Datapunt", "email": "datapunt@amsterdam.nl"}] | ||
|
|
||
| if ds.schema.get("crs"): | ||
| metadata["crs"] = [ds.schema.get("crs")] | ||
|
|
||
| if ds.schema.get("theme"): | ||
| metadata["themes"] = [{"concepts": ds.schema.get("theme")}] | ||
|
|
||
| if ds.schema.get("keywords"): | ||
| metadata["keywords"] = list(ds.schema.get("keywords")) | ||
|
|
||
| if ds.schema.get("license"): | ||
| metadata["license"] = ds.schema.license | ||
|
|
||
| return [metadata] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {% extends "dso_api/dynamic_api/docs/base.html" %}{% load dso_api_tags %} | ||
|
|
||
|
|
||
| {% block breadcrumb %} | ||
| <li><a href="/v1/ogc">OGC endpoints</a></li> | ||
| {% endblock %} | ||
|
|
||
|
|
||
| {% block content %} | ||
| <blockquote style="border-color: #ec0101; margin-top: 1rem;"> | ||
| <p> | ||
| Het Open Geospatial Consortium (OGC) is een internationale organisatie die open standaarden ontwikkelt | ||
| voor het uitwisselen, publiceren en opvragen van geografische informatie. Deze standaarden zorgen ervoor | ||
| dat verschillende systemen en applicaties op een uniforme manier met ruimtelijke gegevens kunnen werken. | ||
| De OGC API-standaarden maken het mogelijk om geografische gegevens en bijbehorende metadata via web-API's | ||
| beschikbaar te stellen en te gebruiken. | ||
| </p> | ||
|
|
||
| <p> | ||
| De Records API wordt gebruikt om gegevensbronnen te ontdekken met metadata uit het Amsterdam Schema. | ||
| </p> | ||
| </blockquote> | ||
| <main> | ||
| <h2>OGC Endpoints</h2> | ||
| <dl class="row"> | ||
| {% if records_url %}<dt class="col-xs-2">Records</dt><dd><a href="{{ records_url }}">{{ records_url }}</a></dd>{% endif %} | ||
| </dl> | ||
|
|
||
| </main> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
|
|
||
| {% extends "dso_api/dynamic_api/docs/base.html" %}{% load i18n static dso_api_tags %} | ||
|
|
||
| {% block breadcrumb %} | ||
| <li><a href="/v1/ogc/records">OGC Records</a></li> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <blockquote style="border-color: #ec0101; margin-top: 1rem;"> | ||
| <p> | ||
| OGC Records worden gebruikt om datasets en de bijbehorende datasetversies volgens de OGC specificatie | ||
| op een gestandaardiseerde manier beschikbaar te stellen. Iedere DSO-dataset wordt ontsloten als een | ||
| record collection, met metadata over deze dataset uit het Amsterdam Schema en de beschikbare datasetversies. | ||
| Iedere datasetversie wordt vervolgens beschreven door een afzonderlijk OGC-record met de bijbehorende | ||
| metadata en links naar de relevante WFS- en WMS-services. Hierdoor kunnen kaartviewers zoals NL3D en | ||
| Geosquare deze datasets en datasetversies op een uniforme manier ontdekken en de bijbehorende geografische | ||
| gegevens raadplegen. | ||
| </p> | ||
| </blockquote> | ||
|
|
||
| <h2>Record collections</h2> | ||
| <p> | ||
| Een record collection van een dataset bevat metadata zoals een identificatie, titel, beschrijving en links | ||
| naar de bijbehorende records (datasetversies). Voor de OGC Records API documentatie, zie <a href='https://docs.ogc.org/is/20-004r1/20-004r1.html'>OGC API - Records.</a> | ||
| Voor een overzicht van bestaande record collections met metadata uit het schema, zie <a href="{{ collection_url }}">Record Collections.</a> | ||
| </p> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.