[fiona] 01/02: Revert "Revert "Merge tag 'upstream/1.6.1'""

Johan Van de Wauw johanvdw-guest at moszumanska.debian.org
Mon Sep 14 19:39:07 UTC 2015


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

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

commit d6cbc98cbf615b683742a5231db1d1b61558e70c
Author: Johan Van de Wauw <johan at vandewauw.be>
Date:   Mon Sep 14 21:12:20 2015 +0200

    Revert "Revert "Merge tag 'upstream/1.6.1'""
    
    This reverts commit 4190039733c9febc2f810f1370b97c2f138b1c86.
---
 CHANGES.txt         |  13 +++++
 CREDITS.txt         |  48 +++++++++----------
 fiona/__init__.py   |   2 +-
 fiona/fio/info.py   |  34 +++++++++----
 fiona/fio/main.py   |   8 ++--
 fiona/ogrext.pyx    |  24 +++++++++-
 setup.py            |   8 +++-
 tests/test_props.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 8 files changed, 228 insertions(+), 44 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index b6b043b..fbbf1ef 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,19 @@
 Changes
 =======
 
+All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
+
+1.6.1 (2015-08-12)
+------------------
+- Bug fix: Fiona now deserializes JSON-encoded string properties provided by
+  the OGR GeoJSON driver (#244, #245, #246).
+- Bug fix: proj4 data was not copied properly into binary distributions due to
+  a typo (#254).
+
+Special thanks to WFMU DJ Liz Berg for the awesome playlist that's fueling my
+release sprint. Check it out at http://wfmu.org/playlists/shows/62083. You
+can't unhear Love Coffin.
+
 1.6.0 (2015-07-21)
 ------------------
 - Upgrade Cython requirement to 0.22 (#214).
diff --git a/CREDITS.txt b/CREDITS.txt
index 03a2998..d4d28b7 100644
--- a/CREDITS.txt
+++ b/CREDITS.txt
@@ -3,30 +3,30 @@ Credits
 
 Fiona is written by:
 
-* Sean Gillies <sean.gillies at gmail.com>
-* Rene Buffat <buffat at gmail.com>
-* Kevin Wurster <wursterk at gmail.com>
-* Kelsey Jordahl <kjordahl at enthought.com>
-* Patrick Young <patrick.mckendree.young at gmail.com>
-* Hannes Gräuler <graeuler at geoplex.de>
-* Ryan Grout <rgrout at continuum.io>
-* Michael Weisman <mweisman at gmail.com>
-* Joshua Arnott <josh at snorfalorpagus.net>
-* Jacob Wasserman <jwasserman at gmail.com>
-* Miro Hrončok <miro at hroncok.cz>
-* Michele Citterio <michele at citterio.net>
-* Johan Van de Wauw <johan.vandewauw at gmail.com>
-* fredj <frederic.junod at camptocamp.com>
-* Brendan Ward <bcward at consbio.org>
-* wilsaj <wilson.andrew.j+github at gmail.com>
-* Stefano Costa <steko at iosa.it>
-* Oliver Tonnhofer <olt at bogosoft.com>
-* Martijn Visser <mgvisser at gmail.com>
-* Ludovic Delauné <ludotux at gmail.com>
-* Hannes Gräuler <hgraeule at uos.de>
-* dimlev <dimlev at gmail.com>
-* Brandon Liu <bdon at bdon.org>
-* Ariel Nunez <ingenieroariel at gmail.com>
+- Sean Gillies <sean.gillies at gmail.com>
+- Kevin Wurster <wursterk at gmail.com>
+- René Buffat <buffat at gmail.com>
+- Kelsey Jordahl <kjordahl at enthought.com>
+- Patrick Young <patrick.young at digitalglobe.com>
+- Hannes Gräuler <graeuler at geoplex.de>
+- Johan Van de Wauw <johan.vandewauw at gmail.com>
+- Jacob Wasserman <jwasserman at gmail.com>
+- Joshua Arnott <josh at snorfalorpagus.net>
+- Ryan Grout <rgrout at continuum.io>
+- Michael Weisman <mweisman at gmail.com>
+- Brendan Ward <bcward at consbio.org>
+- Michele Citterio <michele at citterio.net>
+- Miro Hrončok <miro at hroncok.cz>
+- fredj <frederic.junod at camptocamp.com>
+- wilsaj <wilson.andrew.j+github at gmail.com>
+- Brandon Liu <bdon at bdon.org>
+- Hannes Gräuler <hgraeule at uos.de>
+- Ludovic Delauné <ludotux at gmail.com>
+- Martijn Visser <mgvisser at gmail.com>
+- Oliver Tonnhofer <olt at bogosoft.com>
+- Stefano Costa <steko at iosa.it>
+- dimlev <dimlev at gmail.com>
+- Ariel Nunez <ingenieroariel at gmail.com>
 
 Fiona would not be possible without the great work of Frank Warmerdam and other
 GDAL/OGR developers.
diff --git a/fiona/__init__.py b/fiona/__init__.py
index 5eac18c..4c45226 100644
--- a/fiona/__init__.py
+++ b/fiona/__init__.py
@@ -63,7 +63,7 @@ writing modes) flush contents to disk when their ``with`` blocks end.
 """
 
 __all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
-__version__ = "1.6.0"
+__version__ = "1.6.1"
 
 import logging
 import os
diff --git a/fiona/fio/info.py b/fiona/fio/info.py
index 96080f4..fde48c0 100644
--- a/fiona/fio/info.py
+++ b/fiona/fio/info.py
@@ -53,7 +53,7 @@ def env(ctx, key):
 @click.pass_context
 def info(ctx, input, indent, meta_member):
     verbosity = (ctx.obj and ctx.obj['verbosity']) or 2
-    logger = logging.getLogger('rio')
+    logger = logging.getLogger('fio')
     try:
         with fiona.drivers(CPL_DEBUG=verbosity>2):
             with fiona.open(input) as src:
@@ -79,20 +79,34 @@ def info(ctx, input, indent, meta_member):
 # Insp command.
 @click.command(short_help="Open a dataset and start an interpreter.")
 @click.argument('src_path', type=click.Path(exists=True))
+ at click.option('--ipython', 'interpreter', flag_value='ipython',
+              help="Use IPython as interpreter.")
 @click.pass_context
-def insp(ctx, src_path):
+def insp(ctx, src_path, interpreter):
+
     verbosity = (ctx.obj and ctx.obj['verbosity']) or 2
     logger = logging.getLogger('fio')
+
+    banner = 'Fiona %s Interactive Inspector (Python %s)\n' \
+             'Type "src.schema", "next(src)", or "help(src)" ' \
+             'for more information.' \
+             % (fiona.__version__, '.'.join(map(str, sys.version_info[:3])))
+
     try:
-        with fiona.drivers(CPL_DEBUG=verbosity>2):
+        with fiona.drivers(CPL_DEBUG=verbosity > 2):
             with fiona.open(src_path) as src:
-                code.interact(
-                    'Fiona %s Interactive Inspector (Python %s)\n'
-                    'Type "src.schema", "next(src)", or "help(src)" '
-                    'for more information.' %  (
-                        fiona.__version__, '.'.join(
-                            map(str, sys.version_info[:3]))),
-                    local=locals())
+
+                scope = locals()
+
+                if not interpreter:
+                    code.interact(banner, local=scope)
+                elif interpreter == 'ipython':
+                    import IPython
+                    IPython.InteractiveShell.banner1 = banner
+                    IPython.start_ipython(argv=[], user_ns=scope)
+                else:
+                    raise click.ClickException('Interpreter %s is unsupported or missing '
+                                               'dependencies' % interpreter)
 
     except Exception:
         logger.exception("Exception caught during processing")
diff --git a/fiona/fio/main.py b/fiona/fio/main.py
index 758ff42..f1670f9 100644
--- a/fiona/fio/main.py
+++ b/fiona/fio/main.py
@@ -9,8 +9,8 @@ import warnings
 import sys
 
 import click
+from click_plugins import with_plugins
 from cligj import verbose_opt, quiet_opt
-import cligj.plugins
 
 from fiona import __version__ as fio_version
 
@@ -20,9 +20,9 @@ def configure_logging(verbosity):
     logging.basicConfig(stream=sys.stderr, level=log_level)
 
 
- at cligj.plugins.group(plugins=(
-        ep for ep in list(iter_entry_points('fiona.fio_commands')) +
-                     list(iter_entry_points('fiona.fio_plugins'))))
+ at with_plugins(ep for ep in list(iter_entry_points('fiona.fio_commands')) +
+              list(iter_entry_points('fiona.fio_plugins')))
+ at click.group()
 @verbose_opt
 @quiet_opt
 @click.version_option(fio_version)
diff --git a/fiona/ogrext.pyx b/fiona/ogrext.pyx
index 3434553..4defcb1 100644
--- a/fiona/ogrext.pyx
+++ b/fiona/ogrext.pyx
@@ -1,6 +1,7 @@
 # These are extension functions and classes using the OGR C API.
 
 import datetime
+import json
 import locale
 import logging
 import os
@@ -165,6 +166,7 @@ cdef class FeatureBuilder:
                     key,
                     ograpi.OGR_Fld_GetType(fdefn))
                 continue
+
             # TODO: other types
             fieldtype = FIELD_TYPES_MAP[fieldtypename]
             if not ograpi.OGR_F_IsFieldSet(feature, i):
@@ -173,14 +175,26 @@ cdef class FeatureBuilder:
                 props[key] = ograpi.OGR_F_GetFieldAsInteger(feature, i)
             elif fieldtype is float:
                 props[key] = ograpi.OGR_F_GetFieldAsDouble(feature, i)
+
             elif fieldtype is text_type:
                 try:
                     val = ograpi.OGR_F_GetFieldAsString(feature, i)
-                    props[key] = val.decode(encoding)
+                    val = val.decode(encoding)
                 except UnicodeDecodeError:
                     log.warn(
                         "Failed to decode %s using %s codec", val, encoding)
-                    props[key] = val
+
+                # Does the text contain a JSON object? Let's check.
+                # Let's check as cheaply as we can.
+                if val.startswith('{'):
+                    try:
+                        val = json.loads(val)
+                    except ValueError as err:
+                        log.warn(str(err))
+
+                # Now add to the properties object.
+                props[key] = val
+
             elif fieldtype in (FionaDateType, FionaTimeType, FionaDateTimeType):
                 retval = ograpi.OGR_F_GetFieldAsDateTime(
                     feature, i, &y, &m, &d, &hh, &mm, &ss, &tz)
@@ -253,6 +267,12 @@ cdef class OGRFeatureBuilder:
             i = ograpi.OGR_F_GetFieldIndex(cogr_feature, key_c)
             if i < 0:
                 continue
+
+            # Special case: serialize dicts to assist OGR.
+            if isinstance(value, dict):
+                value = json.dumps(value)
+
+            # Continue over the standard OGR types.
             if isinstance(value, integer_types):
                 ograpi.OGR_F_SetFieldInteger(cogr_feature, i, value)
             elif isinstance(value, float):
diff --git a/setup.py b/setup.py
index 0deb1fd..eaece39 100644
--- a/setup.py
+++ b/setup.py
@@ -122,7 +122,7 @@ if os.environ.get('PACKAGE_DATA'):
     projdatadir = os.environ.get('PROJ_LIB', '/usr/local/share/proj')
     if os.path.exists(projdatadir):
         log.info("Copying proj data from %s" % projdatadir)
-        copy_data_tree(projdatadir, 'finoa/proj_data')
+        copy_data_tree(projdatadir, 'fiona/proj_data')
 
 ext_options = dict(
     include_dirs=include_dirs,
@@ -153,7 +153,11 @@ else:
         Extension('fiona._err', ['fiona/_err.c'], **ext_options),
         Extension('fiona.ogrext', ['fiona/ogrext.c'], **ext_options)]
 
-requirements = ['cligj', 'six']
+requirements = [
+    'cligj',
+    'click-plugins',
+    'six'
+]
 if sys.version_info < (2, 7):
     requirements.append('argparse')
     requirements.append('ordereddict')
diff --git a/tests/test_props.py b/tests/test_props.py
index 41295f7..7f36a3b 100644
--- a/tests/test_props.py
+++ b/tests/test_props.py
@@ -1,20 +1,153 @@
-
+import json
+import os.path
 from six import text_type
+import tempfile
+
+import fiona
 from fiona import prop_type, prop_width
 from fiona.rfc3339 import FionaDateType
 
+
 def test_width_str():
     assert prop_width('str:254') == 254
     assert prop_width('str') == 80
 
+
 def test_width_other():
     assert prop_width('int') == None
     assert prop_width('float') == None
     assert prop_width('date') == None
 
+
 def test_types():
     assert prop_type('str:254') == text_type
     assert prop_type('str') == text_type
     assert prop_type('int') == type(0)
     assert prop_type('float') == type(0.0)
     assert prop_type('date') == FionaDateType
+
+
+def test_read_json_object_properties():
+    """JSON object properties are properly serialized"""
+    data = """
+{
+  "type": "FeatureCollection",
+  "features": [
+    {
+      "geometry": {
+        "type": "Polygon",
+        "coordinates": [
+          [
+            [
+              87.33588,
+              43.53139
+            ],
+            [
+              87.33588,
+              45.66894
+            ],
+            [
+              90.27542,
+              45.66894
+            ],
+            [
+              90.27542,
+              43.53139
+            ],
+            [
+              87.33588,
+              43.53139
+            ]
+          ]
+        ]
+      },
+      "type": "Feature",
+      "properties": {
+        "upperLeftCoordinate": {
+          "latitude": 45.66894,
+          "longitude": 87.91166
+        },
+        "tricky": "{gotcha"
+      }
+    }
+  ]
+}
+"""
+    tmpdir = tempfile.mkdtemp()
+    filename = os.path.join(tmpdir, 'test.json')
+
+    with open(filename, 'w') as f:
+        f.write(data)
+
+    with fiona.open(filename) as src:
+        ftr = next(src)
+        props = ftr['properties']
+        assert props['upperLeftCoordinate']['latitude'] == 45.66894
+        assert props['upperLeftCoordinate']['longitude'] == 87.91166
+        assert props['tricky'] == "{gotcha"
+
+
+def test_write_json_object_properties():
+    """Python object properties are properly serialized"""
+    data = """
+{
+  "type": "FeatureCollection",
+  "features": [
+    {
+      "geometry": {
+        "type": "Polygon",
+        "coordinates": [
+          [
+            [
+              87.33588,
+              43.53139
+            ],
+            [
+              87.33588,
+              45.66894
+            ],
+            [
+              90.27542,
+              45.66894
+            ],
+            [
+              90.27542,
+              43.53139
+            ],
+            [
+              87.33588,
+              43.53139
+            ]
+          ]
+        ]
+      },
+      "type": "Feature",
+      "properties": {
+        "upperLeftCoordinate": {
+          "latitude": 45.66894,
+          "longitude": 87.91166
+        },
+        "tricky": "{gotcha"
+      }
+    }
+  ]
+}
+"""
+    data = json.loads(data)['features'][0]
+    tmpdir = tempfile.mkdtemp()
+    filename = os.path.join(tmpdir, 'test.json')
+    with fiona.open(
+            filename, 'w',
+            driver='GeoJSON',
+            schema={
+                'geometry': 'Polygon',
+                'properties': {'upperLeftCoordinate': 'str', 'tricky': 'str'}}
+            ) as dst:
+        dst.write(data)
+
+    with fiona.open(filename) as src:
+        ftr = next(src)
+        props = ftr['properties']
+        assert props['upperLeftCoordinate']['latitude'] == 45.66894
+        assert props['upperLeftCoordinate']['longitude'] == 87.91166
+        assert props['tricky'] == "{gotcha"

-- 
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