[fiona] 01/03: Imported Upstream version 1.7.4

Johan Van de Wauw johanvdw-guest at moszumanska.debian.org
Mon Feb 20 19:08:25 UTC 2017


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

johanvdw-guest pushed a commit to branch master
in repository fiona.

commit f21c36320523047b0333a233be0721a9fe41d4aa
Author: Johan Van de Wauw <johan.vandewauw at gmail.com>
Date:   Mon Feb 20 19:48:01 2017 +0100

    Imported Upstream version 1.7.4
---
 CHANGES.txt                   | 10 ++++++++++
 fiona/__init__.py             |  2 +-
 fiona/collection.py           | 14 ++++++++++----
 tests/data/grenada.geojson    |  1 +
 tests/test_bytescollection.py | 21 +++++++++++++++++++++
 5 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index e8304c5..1bc4476 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,16 @@ Changes
 
 All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
 
+1.7.4 (2017-02-20)
+------------------
+
+Bug fixes:
+
+- OGR's EsriJSON detection fails when certain keys aren't found in the first
+  6000 bytes of data passed to `BytesCollection` (#422). A .json file extension
+  is now explicitly given to the in-memory file behind `BytesCollection` when
+  the `driver='GeoJSON'` keyword argument is given (#423). 
+
 1.7.3 (2017-02-14)
 ------------------
 
diff --git a/fiona/__init__.py b/fiona/__init__.py
index 88e7407..fca185b 100644
--- a/fiona/__init__.py
+++ b/fiona/__init__.py
@@ -81,7 +81,7 @@ import uuid
 
 
 __all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
-__version__ = "1.7.3"
+__version__ = "1.7.4"
 __gdal_version__ = get_gdal_release_name().decode('utf-8')
 
 log = logging.getLogger('Fiona')
diff --git a/fiona/collection.py b/fiona/collection.py
index f249fd4..f19c1a7 100644
--- a/fiona/collection.py
+++ b/fiona/collection.py
@@ -447,15 +447,21 @@ class BytesCollection(Collection):
         # it is garbage collected while in use.
         self.bytesbuf = bytesbuf
 
-        # Map the buffer to a file. If the buffer contains a zipfile we
-        # take extra steps in naming the buffer and in opening it.
+        # Map the buffer to a file. If the buffer contains a zipfile
+        # we take extra steps in naming the buffer and in opening
+        # it. If the requested driver is for GeoJSON, we append an an
+        # appropriate extension to ensure the driver reads it.
         filetype = get_filetype(self.bytesbuf)
-        ext = '.zip' if filetype == 'zip' else ''
+        ext = ''
+        if filetype == 'zip':
+            ext = '.zip'
+        elif kwds.get('driver') == "GeoJSON":
+            ext = '.json'
         self.virtual_file = buffer_to_virtual_file(self.bytesbuf, ext=ext)
 
         # Instantiate the parent class.
         super(BytesCollection, self).__init__(self.virtual_file, vsi=filetype,
-                                              **kwds)
+                                              encoding='utf-8', **kwds)
 
     def close(self):
         """Removes the virtual file associated with the class."""
diff --git a/tests/data/grenada.geojson b/tests/data/grenada.geojson
new file mode 100644
index 0000000..42dea4b
--- /dev/null
+++ b/tests/data/grenada.geojson
@@ -0,0 +1 @@
+{"features":[{"geometry":{"coordinates":[[[[-61.173214300000005,12.516654800000001],[-61.3827217,12.5301363],[-61.665747100000004,12.5966532],[-61.6661847,12.596],[-61.66814250000001,12.593],[-61.6700247,12.59],[-61.6718337,12.587],[-61.673571700000004,12.584],[-61.6752407,12.581],[-61.6768427,12.578],[-61.678379400000004,12.575000000000001],[-61.6803295,12.571],[-61.6830501,12.565000000000001],[-61.68553430000001,12.559000000000001],[-61.687063699999996,12.555000000000001],[-61.6884946, [...]
diff --git a/tests/test_bytescollection.py b/tests/test_bytescollection.py
index ebce7f5..92c4d5b 100644
--- a/tests/test_bytescollection.py
+++ b/tests/test_bytescollection.py
@@ -223,3 +223,24 @@ def test_zipped_bytes_collection():
 
     with fiona.BytesCollection(zip_file_bytes) as col:
         assert col.name == 'coutwildrnp'
+
+
+def test_grenada_bytes_geojson():
+    """Read grenada.geojson as BytesCollection.
+
+    grenada.geojson is an example of geojson that GDAL's GeoJSON
+    driver will fail to read successfully unless the file's extension
+    reflects its json'ness.
+    """
+    with open('tests/data/grenada.geojson', 'rb') as src:
+        bytes_grenada_geojson = src.read()
+    
+    # We expect an exception if the GeoJSON driver isn't specified.
+    with pytest.raises(fiona.errors.FionaValueError):
+        with fiona.BytesCollection(bytes_grenada_geojson) as col:
+            pass
+
+    # If told what driver to use, we should be good.
+    with fiona.BytesCollection(bytes_grenada_geojson, driver='GeoJSON') as col:        
+        assert len(col) == 1
+        

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



More information about the Pkg-grass-devel mailing list