From 0b4f0bf23a27191767a6c0de343f5ae67a41cab7 Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Tue, 18 Jun 2024 13:34:12 +0200 Subject: [PATCH 1/3] [Vector.__geo_interface__] new method --- spatialist/vector.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spatialist/vector.py b/spatialist/vector.py index e3f37ae..fdd0323 100644 --- a/spatialist/vector.py +++ b/spatialist/vector.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ################################################################ # OGR wrapper for convenient vector data handling and processing -# John Truckenbrodt 2015-2022 +# John Truckenbrodt 2015-2024 ################################################################ @@ -118,6 +118,15 @@ def __str__(self): 'data source : {filename}'.format(**vals) return info + @property + def __geo_interface__(self): + if self.nfeatures > 1: + raise RuntimeError('multiple features are currently not supported') + with self.clone() as tmp: + tmp.reproject(4326) + out = tmp.getFeatureByIndex(0).ExportToJson(as_object=True)['geometry'] + return out + @staticmethod def __driver_autodetect(filename): path = os.path.dirname(os.path.realpath(__file__)) From 145b5ee1bb764fdafcd5601e004d1f752525efc7 Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Tue, 18 Jun 2024 13:40:23 +0200 Subject: [PATCH 2/3] [Vector.__geo_interface__] add docstring --- spatialist/vector.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spatialist/vector.py b/spatialist/vector.py index fdd0323..c9dd7b6 100644 --- a/spatialist/vector.py +++ b/spatialist/vector.py @@ -120,6 +120,14 @@ def __str__(self): @property def __geo_interface__(self): + """ + See https://gist.github.com/sgillies/2217756 + + Returns + ------- + dict + a GeoJSON dictionary + """ if self.nfeatures > 1: raise RuntimeError('multiple features are currently not supported') with self.clone() as tmp: From f0ff5cef4aa9a5ac738d201abeae15cd51b5735e Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Thu, 27 Jun 2024 12:09:18 +0200 Subject: [PATCH 3/3] [Vector.__geo_interface__] return full object, not just geometry --- spatialist/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spatialist/vector.py b/spatialist/vector.py index c9dd7b6..0054d81 100644 --- a/spatialist/vector.py +++ b/spatialist/vector.py @@ -132,7 +132,7 @@ def __geo_interface__(self): raise RuntimeError('multiple features are currently not supported') with self.clone() as tmp: tmp.reproject(4326) - out = tmp.getFeatureByIndex(0).ExportToJson(as_object=True)['geometry'] + out = tmp.getFeatureByIndex(0).ExportToJson(as_object=True) return out @staticmethod