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 <jo...@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.gill...@gmail.com>
-* Rene Buffat <buf...@gmail.com>
-* Kevin Wurster <wurst...@gmail.com>
-* Kelsey Jordahl <kjord...@enthought.com>
-* Patrick Young <patrick.mckendree.yo...@gmail.com>
-* Hannes Gräuler <graeu...@geoplex.de>
-* Ryan Grout <rgr...@continuum.io>
-* Michael Weisman <mweis...@gmail.com>
-* Joshua Arnott <j...@snorfalorpagus.net>
-* Jacob Wasserman <jwasser...@gmail.com>
-* Miro Hrončok <m...@hroncok.cz>
-* Michele Citterio <mich...@citterio.net>
-* Johan Van de Wauw <johan.vandew...@gmail.com>
-* fredj <frederic.ju...@camptocamp.com>
-* Brendan Ward <bcw...@consbio.org>
-* wilsaj <wilson.andrew.j+git...@gmail.com>
-* Stefano Costa <st...@iosa.it>
-* Oliver Tonnhofer <o...@bogosoft.com>
-* Martijn Visser <mgvis...@gmail.com>
-* Ludovic Delauné <ludo...@gmail.com>
-* Hannes Gräuler <hgrae...@uos.de>
-* dimlev <dim...@gmail.com>
-* Brandon Liu <b...@bdon.org>
-* Ariel Nunez <ingenieroar...@gmail.com>
+- Sean Gillies <sean.gill...@gmail.com>
+- Kevin Wurster <wurst...@gmail.com>
+- René Buffat <buf...@gmail.com>
+- Kelsey Jordahl <kjord...@enthought.com>
+- Patrick Young <patrick.yo...@digitalglobe.com>
+- Hannes Gräuler <graeu...@geoplex.de>
+- Johan Van de Wauw <johan.vandew...@gmail.com>
+- Jacob Wasserman <jwasser...@gmail.com>
+- Joshua Arnott <j...@snorfalorpagus.net>
+- Ryan Grout <rgr...@continuum.io>
+- Michael Weisman <mweis...@gmail.com>
+- Brendan Ward <bcw...@consbio.org>
+- Michele Citterio <mich...@citterio.net>
+- Miro Hrončok <m...@hroncok.cz>
+- fredj <frederic.ju...@camptocamp.com>
+- wilsaj <wilson.andrew.j+git...@gmail.com>
+- Brandon Liu <b...@bdon.org>
+- Hannes Gräuler <hgrae...@uos.de>
+- Ludovic Delauné <ludo...@gmail.com>
+- Martijn Visser <mgvis...@gmail.com>
+- Oliver Tonnhofer <o...@bogosoft.com>
+- Stefano Costa <st...@iosa.it>
+- dimlev <dim...@gmail.com>
+- Ariel Nunez <ingenieroar...@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))
+@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)
 
 
-@cligj.plugins.group(plugins=(
-        ep for ep in list(iter_entry_points('fiona.fio_commands')) +
-                     list(iter_entry_points('fiona.fio_plugins'))))
+@with_plugins(ep for ep in list(iter_entry_points('fiona.fio_commands')) +
+              list(iter_entry_points('fiona.fio_plugins')))
+@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

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to