remove shapely dependency and cast CSV geometries as common use case of x/y columns
This commit is contained in:
Vendored
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -96,7 +96,7 @@ class SQLiteProvider(BaseProvider):
|
||||
|
||||
feature_collection = {"features": [],
|
||||
"type": "FeatureCollection"}
|
||||
feature_collection['numberMatched'] = str(hits)
|
||||
feature_collection['numberMatched'] = hits
|
||||
|
||||
return feature_collection
|
||||
|
||||
|
||||
@@ -2,4 +2,3 @@ click
|
||||
elasticsearch
|
||||
Flask
|
||||
PyYAML
|
||||
Shapely
|
||||
|
||||
+6
-6
@@ -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
|
||||
|
||||
|
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user