Skip to content

Commit

Permalink
Merge pull request #130 from jazzband/utils-feature-support
Browse files Browse the repository at this point in the history
Streamline support for Feature objects in coord mapping utils
  • Loading branch information
Asif Saif Uddin committed Jul 13, 2019
2 parents 813117e + d049655 commit 7a1b814
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
11 changes: 2 additions & 9 deletions geojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,8 @@ def map_geometries(func, obj):
geoms = [func(geom) if geom else None for geom in obj['geometries']]
return {'type': obj['type'], 'geometries': geoms}
elif obj['type'] == 'Feature':
geom = func(obj['geometry']) if obj['geometry'] else None
result = {
'type': obj['type'],
'geometry': geom,
'properties': obj['properties'],
}
if 'id' in obj:
result['id'] = obj['id']
return result
obj['geometry'] = func(obj['geometry']) if obj['geometry'] else None
return obj
elif obj['type'] == 'FeatureCollection':
feats = [map_geometries(func, feat) for feat in obj['features']]
return {'type': obj['type'], 'features': feats}
Expand Down
23 changes: 7 additions & 16 deletions tests/test_coords.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

import geojson
from geojson.utils import coords, map_coords, map_tuples
from geojson.utils import coords, map_coords


class CoordsTestCase(unittest.TestCase):
Expand Down Expand Up @@ -67,23 +67,14 @@ def test_map_multipolygon(self):
self.assertEqual(result['coordinates'][-1][-1][-1], (23.18, -34.29))

def test_map_feature(self):
f = geojson.Feature(
id='0',
geometry=geojson.Point([-77.1291115237051, 38.7993076720178]),
properties={
'name': 'Van Dorn Street',
'marker-col': '#0000ff',
'marker-sym': 'rail-metro',
'line': 'blue',
},
g = geojson.Feature(
id='123',
geometry=geojson.Point([-115.81, 37.24])
)
result = map_tuples(lambda t: t, f)
result = map_coords(lambda x: x, g)
self.assertEqual(result['type'], 'Feature')
self.assertEqual(result['id'], '0')
self.assertEqual(
result['geometry']['coordinates'],
(-77.1291115237051, 38.7993076720178)
)
self.assertEqual(result['id'], '123')
self.assertEqual(result['geometry']['coordinates'], (-115.81, 37.24))

def test_map_invalid(self):
with self.assertRaises(ValueError):
Expand Down

0 comments on commit 7a1b814

Please sign in to comment.