Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 12 additions & 0 deletions locale/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,18 @@ msgstr ""
msgid "Display Tiles of"
msgstr ""

#: pygeoapi/templates/collections/collection.html:92
msgid "Coverages"
msgstr ""

#: pygeoapi/templates/collections/collection.html:96
msgid "Display Coverage"
msgstr ""

#: pygeoapi/templates/collections/collection.html:97
msgid "Display Coverage of"
msgstr ""

#: pygeoapi/templates/collections/index.html:13
msgid "Type"
msgstr ""
Expand Down
25 changes: 15 additions & 10 deletions pygeoapi/api/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,7 @@ def gen_collection(api, request, dataset: str,
'rel': f'{OGC_RELTYPES_BASE}/schema',
'title': l10n.translate('Schema of collection in HTML', locale_),
'href': f'{api.get_collections_url()}/{dataset}/schema?f={F_HTML}'
}])

if is_vector_tile or collection_data_type in ['feature', 'record']:
# TODO: translate
data['itemType'] = collection_data_type
LOGGER.debug('Adding feature/record based links')
data['links'].extend([{
}, {
'type': 'application/schema+json',
'rel': f'{OGC_RELTYPES_BASE}/queryables',
'title': l10n.translate('Queryables for this collection as JSON', locale_), # noqa
Expand All @@ -244,7 +238,13 @@ def gen_collection(api, request, dataset: str,
'rel': f'{OGC_RELTYPES_BASE}/queryables',
'title': l10n.translate('Queryables for this collection as HTML', locale_), # noqa
'href': f'{api.get_collections_url()}/{dataset}/queryables?f={F_HTML}' # noqa
}, {
}])

if is_vector_tile or collection_data_type in ['feature', 'record']:
# TODO: translate
LOGGER.debug('Adding feature/record based links')
data['itemType'] = collection_data_type
data['links'].extend([{
'type': 'application/geo+json',
'rel': 'items',
'title': l10n.translate('Items as GeoJSON', locale_),
Expand Down Expand Up @@ -278,12 +278,17 @@ def gen_collection(api, request, dataset: str,

elif collection_data_type == 'coverage':
LOGGER.debug('Adding coverage based links')
data['links'].append({
data['links'].extend([{
'type': 'application/prs.coverage+json',
'rel': f'{OGC_RELTYPES_BASE}/coverage',
'title': l10n.translate('Coverage data', locale_),
'href': f'{api.get_collections_url()}/{dataset}/coverage?f={F_JSON}' # noqa
})
}, {
'type': 'text/html',
'rel': f'{OGC_RELTYPES_BASE}/coverage',
'title': l10n.translate('Coverage data', locale_),
'href': f'{api.get_collections_url()}/{dataset}/coverage?f={F_HTML}' # noqa
}])
if collection_data_format is not None:
title_ = l10n.translate('Coverage data as', locale_)
title_ = f"{title_} {collection_data_format['name']}"
Expand Down
44 changes: 42 additions & 2 deletions pygeoapi/api/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
import logging
from http import HTTPStatus
from typing import Tuple
import urllib

from pygeoapi import l10n
from pygeoapi.formats import F_JSON
from pygeoapi.formats import F_JSON, F_COVERAGEJSON, F_HTML
from pygeoapi.openapi import get_oas_30_parameters
from pygeoapi.plugin import load_plugin
from pygeoapi.provider.base import ProviderGenericError, ProviderTypeError
from pygeoapi.provider import get_provider_by_type
from pygeoapi.util import filter_dict_by_key_value, to_json
from pygeoapi.util import filter_dict_by_key_value, to_json, render_j2_template

from . import (
APIRequest, API, SYSTEM_LOCALE, validate_bbox, validate_datetime,
Expand Down Expand Up @@ -86,6 +87,8 @@ def get_collection_coverage(

# Force response content type and language (en-US only) headers
headers = request.get_response_headers(SYSTEM_LOCALE, **api.api_headers)
collections = filter_dict_by_key_value(api.config['resources'],
'type', 'collection')

LOGGER.debug('Loading provider')
try:
Expand Down Expand Up @@ -142,6 +145,10 @@ def get_collection_coverage(
query_args['datetime_'] = datetime_
query_args['format_'] = format_

if request.format == F_HTML:
# Request as JSON to render HTML
query_args['format_'] = F_COVERAGEJSON

properties = request.params.get('properties')
if properties:
LOGGER.debug('Processing properties parameter')
Expand Down Expand Up @@ -191,6 +198,39 @@ def get_collection_coverage(

headers['Content-Type'] = collection_def['format']['mimetype']
return headers, HTTPStatus.OK, data
elif format_ == F_HTML: # render
tpl_config = api.get_dataset_templates(dataset)

uri = f'{api.get_collections_url()}/{dataset}/coverage'
serialized_query_params = ''
for k, v in request.params.items():
if k != 'f':
serialized_query_params += '&'
serialized_query_params += urllib.parse.quote(k, safe='')
serialized_query_params += '='
serialized_query_params += urllib.parse.quote(str(v), safe=',')

data['query_path'] = uri
data['dataset_path'] = '/'.join(uri.split('/')[:-1])
data['collections_path'] = api.get_collections_url()

data['links'] = [{
'rel': 'collection',
'title': collections[dataset]['title'],
'href': data['dataset_path']
}, {
'type': 'application/vnd.cov+json',
'rel': request.get_linkrel(F_COVERAGEJSON),
'title': l10n.translate('This document as CoverageJSON', request.locale), # noqa
'href': f'{uri}?f={F_COVERAGEJSON}{serialized_query_params}'
}]

content = render_j2_template(api.tpl_config, tpl_config,
'collections/coverages/coverage.html',
data, api.default_locale)

return headers, HTTPStatus.OK, content

elif format_ == F_JSON:
headers['Content-Type'] = 'application/prs.coverage+json'
return headers, HTTPStatus.OK, to_json(data, api.pretty_print)
Expand Down
40 changes: 30 additions & 10 deletions pygeoapi/templates/collections/collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,40 @@ <h3>{% trans %}Schema{% endtrans %}</h3>
{% trans %}Display Schema of{% endtrans %} "{{ data['title'] }}"</a></div>
</li>
</ul>
{% endif %}

{% for provider in config['resources'][data['id']]['providers'] %}
{% if 'tile' in provider['type'] %}
<h3>{% trans %}Tiles{% endtrans %}</h3>
<ul>
<li>
<div>
<a title="{% trans %}Display Tiles{% endtrans %}" href="{{ data['collections_path'] }}/{{ data['id'] }}/tiles">{% trans %}Display Tiles of{% endtrans %} "{{ data['title'] }}"</a>
</div>
</li>
</ul>
<h3>{% trans %}Tiles{% endtrans %}</h3>
<ul>
<li>
<div>
<a title="{% trans %}Display Tiles{% endtrans %}" href="{{ data['collections_path'] }}/{{ data['id'] }}/tiles">{% trans %}Display Tiles of{% endtrans %} "{{ data['title'] }}"</a>
</div>
</li>
</ul>
{% endif %}

{% if 'coverage' in provider['type'] %}
<h3>{% trans %}Coverage{% endtrans %}</h3>
<ul>
<li>
<div>
<a title="{% trans %}Display Coverage{% endtrans %}" href="{{ data['collections_path'] }}/{{ data['id'] }}/coverage">
{% trans %}Display Coverage of{% endtrans %} "{{ data['title'] }}"</a></div>
Comment thread
webb-ben marked this conversation as resolved.
</li>
</ul>
<h3>{% trans %}Schema{% endtrans %}</h3>
<ul>
<li>
<div>
<a title="{% trans %}Display Schema{% endtrans %}" href="{{ data['collections_path'] }}/{{ data['id'] }}/schema">
{% trans %}Display Schema of{% endtrans %} "{{ data['title'] }}"</a></div>
</li>
</ul>
{% endif %}
{% endfor %}
{% endif %}

{% endfor %}
{%- if data['data_queries'] -%}
<h3>Data Queries</h3>
<table class="table table-striped table-bordered">
Expand Down
Loading
Loading