From 5e14929da3686583f580fd0bb88a8d7ca17b2cd2 Mon Sep 17 00:00:00 2001 From: alex-mathew <35272003+alex-mathew@users.noreply.github.com> Date: Thu, 27 Aug 2020 19:30:38 +0530 Subject: [PATCH] Issue 499 : Fixing geojson provider (#522) * moved id field to root in sample geojson provider files (geopython#499) * modified geojson data provider to get id from root (geopython#499) * updated geojson provider tests (geopython#499) * updated position of id field (geopython#499) * refactored code (geopython#499) * refactored geojson provider (geopython#499) * fixed geojson provider (geopython#499) --- pygeoapi/provider/geojson.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygeoapi/provider/geojson.py b/pygeoapi/provider/geojson.py index 02e1f3e..4924ae8 100644 --- a/pygeoapi/provider/geojson.py +++ b/pygeoapi/provider/geojson.py @@ -103,7 +103,9 @@ class GeoJSONProvider(BaseProvider): # Must be a FeatureCollection assert data['type'] == 'FeatureCollection' # All features must have ids, TODO must be unique strings - + for i in data['features']: + if 'id' not in i and self.id_field in i['properties']: + i['id'] = i['properties'][self.id_field] return data def query(self, startindex=0, limit=10, resulttype='results', @@ -146,9 +148,7 @@ class GeoJSONProvider(BaseProvider): all_data = self._load() # if matches for feature in all_data['features']: - id = feature.get(self.id_field, None) or\ - feature['properties'].get(self.id_field, None) - if id == identifier: + if str(feature.get('id')) == identifier: return feature # default, no match err = 'item {} not found'.format(identifier)