[python-geojson] 01/04: New upstream version 2.3.0

Bas Couwenberg sebastic at debian.org
Tue Sep 19 05:49:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository python-geojson.

commit 4fd172ecdcc2881a01be5dc5501873d9461269cc
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Tue Sep 19 07:38:46 2017 +0200

    New upstream version 2.3.0
---
 CHANGELOG.rst       |  8 ++++++++
 README.rst          | 17 ++++++++++++++++-
 geojson/_version.py |  2 +-
 geojson/feature.py  |  6 ++++++
 geojson/geometry.py |  6 ++++++
 5 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 1449f32..8ba172c 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,14 @@
 Changes
 =======
 
+2.3.0 (2017-09-18)
+------------------
+
+- Add ``__getitem__`` methods to sequence-like objects
+
+  - https://github.com/frewsxcv/python-geojson/pull/103
+
+
 2.2.0 (2017-09-17)
 ------------------
 
diff --git a/README.rst b/README.rst
index d71aaa1..1c6303d 100644
--- a/README.rst
+++ b/README.rst
@@ -37,6 +37,10 @@ This library implements all the `GeoJSON Objects`_ described in `The GeoJSON For
 
 .. _GeoJSON Objects: https://tools.ietf.org/html/rfc7946#section-3
 
+All object keys can also be used as attributes.
+
+The objects contained in GeometryCollection and FeatureCollection can be indexed directly.
+
 Point
 ~~~~~
 
@@ -153,9 +157,17 @@ GeometryCollection
 
   >>> my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])
 
-  >>> GeometryCollection([my_point, my_line])  # doctest: +ELLIPSIS
+  >>> geo_collection = GeometryCollection([my_point, my_line])
+
+  >>> geo_collection  # doctest: +ELLIPSIS
   {"geometries": [{"coordinates": [23.53..., -63.1...], "type": "Point"}, {"coordinates": [[-152.6..., 51.2...], [5.2..., 10.6...]], "type": "LineString"}], "type": "GeometryCollection"}
 
+  >>> geo_collection[1]
+  {"coordinates": [[-152.62, 51.21], [5.21, 10.69]], "type": "LineString"}
+
+  >>> geo_collection[0] == geo_collection.geometries[0]
+  True
+
 Visualize the result of the example above `here <https://gist.github.com/frewsxcv/6ec8422e97d338a101b0>`__. General information about GeometryCollection can be found in `Section 3.1.8`_ and `Appendix A: GeometryCollections`_ within `The GeoJSON Format Specification`_.
 
 .. _Section 3.1.8: https://tools.ietf.org/html/rfc7946#section-3.1.8
@@ -202,6 +214,9 @@ FeatureCollection
   >>> feature_collection.errors()
   []
 
+  >>> (feature_collection[0] == feature_collection['features'][0], feature_collection[1] == my_other_feature)
+  (True, True)
+
 Visualize the result of the example above `here <https://gist.github.com/frewsxcv/34513be6fb492771ef7b>`__. General information about FeatureCollection can be found in `Section 3.3`_ within `The GeoJSON Format Specification`_.
 
 .. _Section 3.3: https://tools.ietf.org/html/rfc7946#section-3.3
diff --git a/geojson/_version.py b/geojson/_version.py
index 4bde90e..724d433 100644
--- a/geojson/_version.py
+++ b/geojson/_version.py
@@ -1,2 +1,2 @@
-__version__ = "2.2.0"
+__version__ = "2.3.0"
 __version_info__ = tuple(map(int, __version__.split(".")))
diff --git a/geojson/feature.py b/geojson/feature.py
index 260a568..970d0da 100644
--- a/geojson/feature.py
+++ b/geojson/feature.py
@@ -53,3 +53,9 @@ class FeatureCollection(GeoJSON):
 
     def errors(self):
         return self.check_list_errors(lambda x: x.errors(), self.features)
+
+    def __getitem__(self, key):
+        try:
+            return self.get("features", ())[key]
+        except (KeyError, TypeError, IndexError):
+            return super(GeoJSON, self).__getitem__(key)
diff --git a/geojson/geometry.py b/geojson/geometry.py
index 1bcc006..17aef45 100644
--- a/geojson/geometry.py
+++ b/geojson/geometry.py
@@ -69,6 +69,12 @@ class GeometryCollection(GeoJSON):
         errors = [geom.errors() for geom in self['geometries']]
         return [err for err in errors if err]
 
+    def __getitem__(self, key):
+        try:
+            return self.get("geometries", ())[key]
+        except (KeyError, TypeError, IndexError):
+            return super(GeoJSON, self).__getitem__(key)
+
 
 # Marker classes.
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-geojson.git



More information about the Pkg-grass-devel mailing list