diff --git a/debian/control b/debian/control index f77cccd..be0ad48 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Git: https://github.com/geopython/pygeoapi.git Package: python-pygeoapi Architecture: all Depends: ${misc:Depends}, ${python:Depends}, python-pkg-resources, python-click, python-flask, python-yaml -Suggests: python-elasticsearch, python-geojson, python-shapely +Suggests: python-elasticsearch, python-geojson Homepage: https://github.com/geopython/pygeoapi Description: pygeoapi provides an API to geospatial data diff --git a/pygeoapi-config.yml b/pygeoapi-config.yml index adc193f..c1e3335 100644 --- a/pygeoapi-config.yml +++ b/pygeoapi-config.yml @@ -78,6 +78,9 @@ datasets: name: CSV data: tests/data/obs.csv id_field: id + geometry: + x_field: long + y_field: long ne_110m_populated_places_simple: title: Populated Places diff --git a/pygeoapi/provider/csv_.py b/pygeoapi/provider/csv_.py index f9a5cdc..2ccdc48 100644 --- a/pygeoapi/provider/csv_.py +++ b/pygeoapi/provider/csv_.py @@ -31,9 +31,6 @@ import csv import itertools import logging -from shapely import wkt -from shapely.geometry import mapping - from pygeoapi.provider.base import BaseProvider LOGGER = logging.getLogger(__name__) @@ -52,6 +49,8 @@ class CSVProvider(BaseProvider): """ BaseProvider.__init__(self, provider_def) + self.geometry_x = provider_def['geometry']['x_field'] + self.geometry_y = provider_def['geometry']['y_field'] def _load(self, startindex=0, limit=10, resulttype='results', identifier=None, bbox=[], time=None, properties=[]): @@ -84,7 +83,13 @@ class CSVProvider(BaseProvider): for row in itertools.islice(data_, startindex, startindex+limit): feature = {'type': 'Feature'} feature['ID'] = row.pop('id') - feature['geometry'] = mapping(wkt.loads(row.pop('geom'))) + feature['geometry'] = { + 'type': 'Point', + 'coordinates': [ + row.pop(self.geometry_x), + row.pop(self.geometry_y) + ] + } feature['properties'] = row if identifier is not None and feature['ID'] == identifier: found = True diff --git a/pygeoapi/provider/sqlite.py b/pygeoapi/provider/sqlite.py index 4ac7596..6c15edc 100644 --- a/pygeoapi/provider/sqlite.py +++ b/pygeoapi/provider/sqlite.py @@ -96,7 +96,7 @@ class SQLiteProvider(BaseProvider): feature_collection = {"features": [], "type": "FeatureCollection"} - feature_collection['numberMatched'] = str(hits) + feature_collection['numberMatched'] = hits return feature_collection diff --git a/requirements.txt b/requirements.txt index c464210..fe0426a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,3 @@ click elasticsearch Flask PyYAML -Shapely diff --git a/tests/data/obs.csv b/tests/data/obs.csv index f173d9c..0f9430f 100644 --- a/tests/data/obs.csv +++ b/tests/data/obs.csv @@ -1,6 +1,6 @@ -id,stn_id,datetime,value,geom -371,35,"2001-10-30T14:24:55Z",89.9,POINT(-75 45) -377,35,"2002-10-30T18:31:38Z",93.9,POINT(-75 45) -238,2147,"2007-10-30T08:57:29Z",103.5,POINT(-79 43) -297,2147,"2003-10-30T07:37:29Z",93.5,POINT(-79 43) -964,604,"2000-10-30T18:24:39Z",99.9,POINT(-122 49) +id,stn_id,datetime,value,lat,long +371,35,"2001-10-30T14:24:55Z",89.9,45,-75 +377,35,"2002-10-30T18:31:38Z",93.9,45,-75 +238,2147,"2007-10-30T08:57:29Z",103.5,43,-79 +297,2147,"2003-10-30T07:37:29Z",93.5,43,-79 +964,604,"2000-10-30T18:24:39Z",99.9,49,-122 diff --git a/tests/test_csv__provider.py b/tests/test_csv__provider.py index d315b9b..1539f79 100644 --- a/tests/test_csv__provider.py +++ b/tests/test_csv__provider.py @@ -37,12 +37,12 @@ path = '/tmp/pygeoapi-test.csv' @pytest.fixture() def fixture(): - data = """id,stn_id,datetime,value,geom -371,35,"2001-10-30T14:24:55Z",89.9,POINT(-75 45) -377,35,"2002-10-30T18:31:38Z",93.9,POINT(-75 45) -238,2147,"2007-10-30T08:57:29Z",103.5,POINT(-79 43) -297,2147,"2003-10-30T07:37:29Z",93.5,POINT(-79 43) -964,604,"2000-10-30T18:24:39Z",99.9,POINT(-122 49) + data = """id,stn_id,datetime,value,lat,long +371,35,"2001-10-30T14:24:55Z",89.9,45,-75 +377,35,"2002-10-30T18:31:38Z",93.9,45,-75 +238,2147,"2007-10-30T08:57:29Z",103.5,43,-79 +297,2147,"2003-10-30T07:37:29Z",93.5,43,-79 +964,604,"2000-10-30T18:24:39Z",99.9,49,-122 """ with open(path, 'w') as fh: fh.write(data) @@ -54,7 +54,11 @@ def config(): return { 'name': 'CSV', 'data': path, - 'id_field': 'id' + 'id_field': 'id', + 'geometry': { + 'x_field': 'long', + 'y_field': 'lat' + } }