Merge pull request #23 from geopython/bbox-time-html

add bbox/time API support to ES backend, enhance HTML representation
This commit is contained in:
Jorge Samuel Mendes de Jesus
2018-04-04 08:52:45 +02:00
committed by GitHub
11 changed files with 145 additions and 112 deletions
+24 -3
View File
@@ -98,7 +98,7 @@ class API(object):
'rel': 'self',
'type': 'text/html',
'title': 'this document as HTML',
'href': '{}?f=html'.format(self.config['server']['url'])
'href': '{}/?f=html'.format(self.config['server']['url'])
}, {
'rel': 'self',
'type': 'application/openapi+json;version=3.0',
@@ -266,11 +266,21 @@ class API(object):
:returns: tuple of headers, status code, content
"""
print(args)
headers_ = {
'Content-type': 'application/json'
}
formats = ['json', 'html']
format_ = args.get('f')
if format_ is not None and format_ not in formats:
exception = {
'code': 'InvalidParameterValue',
'description': 'Invalid format'
}
LOGGER.error(exception)
return headers_, 400, json.dumps(exception)
LOGGER.debug('Processing query parameters')
try:
startindex = int(args.get('startindex'))
@@ -282,7 +292,12 @@ class API(object):
limit = self.config['server']['limit']
resulttype = args.get('resulttype') or 'results'
bbox = args.get('bbox')
try:
bbox = args.get('bbox').split(',')
except AttributeError:
bbox = []
time = args.get('time')
if dataset not in self.config['datasets'].keys():
@@ -338,6 +353,12 @@ class API(object):
content['timeStamp'] = datetime.utcnow().isoformat()
if format_ == 'html': # render
headers_['Content-type'] = 'text/html'
content = _render_j2_template(self.config, 'items.html',
content)
return headers_, 200, content
return headers_, 200, json.dumps(content)
def get_feature(self, headers, args, dataset, identifier):
+3 -2
View File
@@ -54,7 +54,7 @@ class CSVProvider(BaseProvider):
BaseProvider.__init__(self, provider_def)
def _load(self, startindex=0, limit=10, resulttype='results',
identifier=None):
identifier=None, bbox=[], time=None):
"""
Load CSV data
@@ -98,7 +98,8 @@ class CSVProvider(BaseProvider):
feature_collection['numberReturned'] = limit
return feature_collection
def query(self, startindex=0, limit=10, resulttype='results'):
def query(self, startindex=0, limit=10, resulttype='results',
bbox=[], time=None):
"""
CSV query
+7 -4
View File
@@ -65,14 +65,14 @@ class ElasticsearchProvider(BaseProvider):
self.es = Elasticsearch(self.es_host)
def query(self, startindex=0, limit=10, resulttype='results',
bbox=None, time=None):
bbox=[], time=None):
"""
query Elasticsearch index
:param startindex: starting record to return (default 0)
:param limit: number of records to return (default 10)
:param resulttype: return results or hit limit (default results)
:param bbox: bounding box (minx,miny,maxx,maxy)
:param bbox: bounding box [minx,miny,maxx,maxy]
:param time: temporal (datestamp or extent)
:returns: dict of 0..n GeoJSON features
@@ -90,9 +90,9 @@ class ElasticsearchProvider(BaseProvider):
LOGGER.debug('hits only specified')
limit = 0
if bbox is not None:
if bbox:
LOGGER.debug('processing bbox parameter')
minx, miny, maxx, maxy = bbox.split(',')
minx, miny, maxx, maxy = bbox
bbox_filter = {
'geo_shape': {
'geometry': {
@@ -140,6 +140,9 @@ class ElasticsearchProvider(BaseProvider):
except exceptions.RequestError as err:
LOGGER.error(err)
raise ProviderQueryError()
except exceptions.NotFoundError as err:
LOGGER.error(err)
raise ProviderQueryError()
feature_collection['numberMatched'] = results['hits']['total']
+2 -1
View File
@@ -85,7 +85,8 @@ class GeoJSONProvider(BaseProvider):
return data
def query(self, startindex=0, limit=10, resulttype='results'):
def query(self, startindex=0, limit=10, resulttype='results',
bbox=[], time=None):
"""
query the provider
+2 -1
View File
@@ -130,7 +130,8 @@ class SQLiteProvider(BaseProvider):
return cursor
def query(self, startindex=0, limit=10, resulttype='results'):
def query(self, startindex=0, limit=10, resulttype='results',
bbox=[], time=None):
"""
Query Sqlite for all the content.
e,g: http://localhost:5000/collections/countries/items?
+37
View File
@@ -0,0 +1,37 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="{{ config['server']['encoding'] }}">
<title>{% block title %}{{ config['metadata']['identification']['title'] }} -{% endblock %}</title>
<meta name="language" content="{{ config['server']['language'] }}">
<meta name="description" content="{{ config['metadata']['identification']['title'] }}">
<meta name="keywords" content="{{ config['metadata']['identification']['keywords']|join(',') }}">
<link rel="stylesheet" href="{{ config['server']['url'] }}/static/css/default.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
{% block extrahead %}
{% endblock %}
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}?f=html">{{ config['metadata']['identification']['title'] }}</a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>
{% block body %}
{% endblock %}
<hr/>
<footer>Powered by <a title="pygeoapi" href="https://github.com/geopython/pygeoapi">pygeoapi</a> {{ version }}</footer>
{% block extrafoot %}
{% endblock %}
</body>
</html>
+6 -26
View File
@@ -1,27 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="{{ config['server']['encoding'] }}">
<title>{{ config['metadata']['identification']['title'] }} - data['title']</title>
<meta name="language" content="{{ config['server']['language'] }}">
<meta name="description" content="{{ config['metadata']['identification']['title'] }}">
<meta name="keywords" content="{{ config['metadata']['identification']['keywords']|join(',') }}">
<link rel="stylesheet" href="static/css/default.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}">{{ config['metadata']['identification']['title'] }}</a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>
{% extends "base.html" %}
{% block title %}{{ super() }} {{ data['title'] }} {% endblock %}
{% block body %}
<section id="collection">
<h2>{{ data['title'] }}</h2>
<span>{{ data['description'] }}</span>
<div>{{ data['description'] }}</div>
<div><a title="Browse Features" href="{{ config['server']['url'] }}/collections/{{ data['name'] }}/items?f=html">Browse Features</a></div>
<h2>Links</h2>
<ul>
{% for link in data['links'] %}
@@ -29,7 +12,4 @@
{% endfor %}
</ul>
</section>
<hr/>
<footer>Powered by <a title="pygeoapi" href="https://github.com/geopython/pygeoapi">pygeoapi</a> {{ version }}</footer>
</body>
</html>
{% endblock %}
+4 -25
View File
@@ -1,24 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="{{ config['server']['encoding'] }}">
<title>{{ config['metadata']['identification']['title'] }} - Collections</title>
<meta name="language" content="{{ config['server']['language'] }}">
<meta name="description" content="{{ config['metadata']['identification']['title'] }}">
<meta name="keywords" content="{{ config['metadata']['identification']['keywords']|join(',') }}">
<link rel="stylesheet" href="static/css/default.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}">{{ config['metadata']['identification']['title'] }}</a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>
{% extends "base.html" %}
{% block title %}{{ super() }} Collections {% endblock %}
{% block body %}
<section id="collections">
<h2>Collections</h2>
<ul>
@@ -27,7 +9,4 @@
{% endfor %}
</ul>
</section>
<hr/>
<footer>Powered by <a title="pygeoapi" href="https://github.com/geopython/pygeoapi">pygeoapi</a> {{ version }}</footer>
</body>
</html>
{% endblock %}
+4 -25
View File
@@ -1,24 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="{{ config['server']['encoding'] }}">
<title>{{ config['metadata']['identification']['title'] }} - Conformance</title>
<meta name="language" content="{{ config['server']['language'] }}">
<meta name="description" content="{{ config['metadata']['identification']['title'] }}">
<meta name="keywords" content="{{ config['metadata']['identification']['keywords']|join(',') }}">
<link rel="stylesheet" href="static/css/default.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}">{{ config['metadata']['identification']['title'] }}</a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>
{% extends "base.html" %}
{% block title %}{{ super() }} Conformance {% endblock %}
{% block body %}
<section id="conformance">
<h2>Conformance</h2>
<ul>
@@ -27,7 +9,4 @@
{% endfor %}
</ul>
</section>
<hr/>
<footer>Powered by <a title="pygeoapi" href="https://github.com/geopython/pygeoapi">pygeoapi</a> {{ version }}</footer>
</body>
</html>
{% endblock %}
+52
View File
@@ -0,0 +1,52 @@
{% extends "base.html" %}
{% block title %}{{ super() }} {{ data['title'] }} {% endblock %}
{% block extrahead %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<style>
#items {
width: 80%;
}
#items-map {
width: 600px;
height: 400px;
}
</style>
{% endblock %}
{% block body %}
<section id="items">
<h2>{{ data['title'] }}</h2>
<span>{{ data['description'] }}</span>
<h2>Features</h2>
<table>
<tr>
<td>
<ul>
{% for feature in data['features'] %}
<li><a title="{{ feature['ID'] }}" href="./items/{{ feature['ID'] }}">{{ feature['ID'] }}</a></li>
{% endfor %}
</ul>
</td>
<td>
<div id="items-map"></div>
</td>
</tr>
</table>
</section>
{% endblock %}
{% block extrafoot %}
<script>
var map = L.map('items-map').setView([{{ 45 }}, {{ -75 }}], 5);
map.addLayer(new L.TileLayer(
'http://tile.osm.org/{z}/{x}/{y}.png', {
maxZoom: 18,
subdomains: '1234'
}
));
{% for feature in data['features'] %}
L.marker([{{ feature['geometry']['coordinates'][1] }}, {{ feature['geometry']['coordinates'][0] }}]).addTo(map).bindPopup('{{ feature['ID'] }} ')
{% endfor %}
</script>
{% endblock %}
+4 -25
View File
@@ -1,24 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="{{ config['server']['encoding'] }}">
<title>{{ config['metadata']['identification']['title'] }}</title>
<meta name="language" content="{{ config['server']['language'] }}">
<meta name="description" content="{{ config['metadata']['identification']['title'] }}">
<meta name="keywords" content="{{ config['metadata']['identification']['keywords']|join(',') }}">
<link rel="stylesheet" href="static/css/default.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<header>
<h1><a title="{{ config['metadata']['identification']['title'] }}" href="{{ config['server']['url'] }}/">{{ config['metadata']['identification']['title'] }}</a></h1>
<span itemprop="description">{{ config['metadata']['identification']['description'] }}</span>
</header>
{% extends "base.html" %}
{% block title %}{{ super() }} Home {% endblock %}
{% block body %}
<section id="service-metadata">
<h2>Service Metadata</h2>
<table>
@@ -42,7 +24,4 @@
{% endfor %}
</ul>
</section>
<hr/>
<footer>Powered by <a title="pygeoapi" href="https://github.com/geopython/pygeoapi">pygeoapi</a> {{ version }}</footer>
</body>
</html>
{% endblock %}