diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 4a3ba99..50d6dc5 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -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): diff --git a/pygeoapi/provider/csv_.py b/pygeoapi/provider/csv_.py index 7826f86..952a107 100644 --- a/pygeoapi/provider/csv_.py +++ b/pygeoapi/provider/csv_.py @@ -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 diff --git a/pygeoapi/provider/elasticsearch_.py b/pygeoapi/provider/elasticsearch_.py index b0388c1..d5e765d 100644 --- a/pygeoapi/provider/elasticsearch_.py +++ b/pygeoapi/provider/elasticsearch_.py @@ -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'] diff --git a/pygeoapi/provider/geojson.py b/pygeoapi/provider/geojson.py index 67e3977..6d3deea 100644 --- a/pygeoapi/provider/geojson.py +++ b/pygeoapi/provider/geojson.py @@ -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 diff --git a/pygeoapi/provider/sqlite.py b/pygeoapi/provider/sqlite.py index e6b4b90..91205ec 100644 --- a/pygeoapi/provider/sqlite.py +++ b/pygeoapi/provider/sqlite.py @@ -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? diff --git a/pygeoapi/templates/base.html b/pygeoapi/templates/base.html new file mode 100644 index 0000000..9fc9421 --- /dev/null +++ b/pygeoapi/templates/base.html @@ -0,0 +1,37 @@ + + +
+ +
+
|
+ + + | +