From eeea6cc611fb4786ee4883dd2d015fe46039b178 Mon Sep 17 00:00:00 2001 From: Marc Monnerat Date: Tue, 21 Jul 2020 13:22:59 +0200 Subject: [PATCH 1/4] convert collection to multi --- esrijson/geometry.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/esrijson/geometry.py b/esrijson/geometry.py index 1d65e3d..1e3f477 100644 --- a/esrijson/geometry.py +++ b/esrijson/geometry.py @@ -99,11 +99,21 @@ def from_shape(obj, wkid=None): if type_ == 'GeometryCollection': # No concept of GeometryCollection in esri_json therefore we take # the first one only + # We also may have a collections of collections if len(obj['geometries']) == 0: return esri_geom first = obj['geometries'][0] - type_ = first.pop('type') - coords = first.pop('coordinates') + if type(first) == list: + types_ = [d['type'] for d in first] + coords = [d['coordinates'] for d in first] + + if len(set(types_)) == 1 and types_[0] in ('Point', 'LineString', 'Polygon'): + type_ = 'Multi' + types_[0] + else: + raise TypeError('Cannot convert collection of different types into an Esri Multi(Point|LineString|Polygon)') + else: + type_ = first.pop('type') + coords = first.pop('coordinates') else: coords = obj.pop('coordinates') if type_: From 6198d0a08746daa10a272a19e4c7104c4c484110 Mon Sep 17 00:00:00 2001 From: Marc Monnerat Date: Tue, 21 Jul 2020 13:30:10 +0200 Subject: [PATCH 2/4] bumping version --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index aca8f8e..873eae0 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ long_description = fh.read() setup(name='esrijson', - version='0.4.3', + version='0.4.4', description='Bindings and utilities for EsriJSON', long_description=long_description, long_description_content_type="text/markdown", @@ -21,6 +21,7 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Scientific/Engineering :: GIS', 'Topic :: Software Development :: Libraries :: Python Modules' ], From 313cbf408998030a6d8c647763c709b42f7f3d6b Mon Sep 17 00:00:00 2001 From: Marc Monnerat Date: Tue, 21 Jul 2020 13:31:18 +0200 Subject: [PATCH 3/4] python3.8 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1ba79c7..e1f01b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: - 3.5 - 3.6 - 3.7 +- 3.8 install: - pip install nose - pip install flake8 From 1cbb26b5f5ba0f8fc33fd4d8a3a83aa4e2ca7cba Mon Sep 17 00:00:00 2001 From: Marc Monnerat Date: Tue, 21 Jul 2020 13:41:08 +0200 Subject: [PATCH 4/4] linting --- esrijson/geometry.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esrijson/geometry.py b/esrijson/geometry.py index 1e3f477..cf646da 100644 --- a/esrijson/geometry.py +++ b/esrijson/geometry.py @@ -106,11 +106,13 @@ def from_shape(obj, wkid=None): if type(first) == list: types_ = [d['type'] for d in first] coords = [d['coordinates'] for d in first] - - if len(set(types_)) == 1 and types_[0] in ('Point', 'LineString', 'Polygon'): + if len(set(types_)) == 1 and \ + types_[0] in ('Point', 'LineString', 'Polygon'): type_ = 'Multi' + types_[0] else: - raise TypeError('Cannot convert collection of different types into an Esri Multi(Point|LineString|Polygon)') + raise TypeError('Cannot convert collection of different ' + + 'types into an Esri Multi(Point|LineString' + + '|Polygon)') else: type_ = first.pop('type') coords = first.pop('coordinates')