Bas Couwenberg pushed to branch master at Debian GIS Project / python-geojson
Commits: 1de69b33 by Bas Couwenberg at 2018-10-18T12:52:00Z New upstream version 2.4.1 - - - - - fe6bfbe4 by Bas Couwenberg at 2018-10-18T12:52:02Z Merge tag 'upstream/2.4.1' Upstream version 2.4.1 - - - - - d65f77a4 by Bas Couwenberg at 2018-10-18T12:52:23Z New upstream release. - - - - - 77481118 by Bas Couwenberg at 2018-10-18T12:53:03Z Set distribution to unstable. - - - - - 7 changed files: - CHANGELOG.rst - README.rst - debian/changelog - geojson/_version.py - geojson/geometry.py - geojson/utils.py - tests/test_coords.py Changes: ===================================== CHANGELOG.rst ===================================== @@ -1,6 +1,13 @@ Changes ======= +2.4.1 (2018-10-17) +------------------ + +- Allow ``FeatureCollections`` to be passed to ``coords`` + + - https://github.com/frewsxcv/python-geojson/pull/117 + 2.4.0 (2018-05-21) ------------------ ===================================== README.rst ===================================== @@ -224,7 +224,7 @@ Visualize the result of the example above `here <https://gist.github.com/frewsxc GeoJSON encoding/decoding ------------------------- -All of the GeoJSON Objects implemented in this library can be encoded and decoded into raw GeoJSON with the ``geojson.dump``, ``geojson.dumps``, ``geojson.load``, and ``geojson.loads`` functions. +All of the GeoJSON Objects implemented in this library can be encoded and decoded into raw GeoJSON with the ``geojson.dump``, ``geojson.dumps``, ``geojson.load``, and ``geojson.loads`` functions. Note that each of these functions is a wrapper around the core `json` function with the same name, and will pass through any additional arguments. This allows you to control the JSON formatting or parsing behavior with the underlying core `json` functions. .. code:: python ===================================== debian/changelog ===================================== @@ -1,11 +1,13 @@ -python-geojson (2.4.0-2) UNRELEASED; urgency=medium +python-geojson (2.4.1-1) unstable; urgency=medium + * Team upload. + * New upstream release. * Bump Standards-Version to 4.2.1, no changes. * Drop autopkgtests to test installability & module import. * Add lintian override for testsuite-autopkgtest-missing. * Update watch file to limit matches to archive path. - -- Bas Couwenberg <[email protected]> Thu, 05 Jul 2018 11:06:32 +0200 + -- Bas Couwenberg <[email protected]> Thu, 18 Oct 2018 14:52:47 +0200 python-geojson (2.4.0-1) unstable; urgency=medium ===================================== geojson/_version.py ===================================== @@ -1,2 +1,2 @@ -__version__ = "2.4.0" +__version__ = "2.4.1" __version_info__ = tuple(map(int, __version__.split("."))) ===================================== geojson/geometry.py ===================================== @@ -21,7 +21,7 @@ class Geometry(GeoJSON): Initialises a Geometry object. :param coordinates: Coordinates of the Geometry object. - :type coordinates: tuple + :type coordinates: tuple or list of tuple :param crs: CRS :type crs: CRS object """ ===================================== geojson/utils.py ===================================== @@ -10,19 +10,26 @@ def coords(obj): :return: A generator with coordinate tuples from the geometry or feature. :rtype: generator """ - - if isinstance(obj, (tuple, list)): - coordinates = obj - elif 'geometry' in obj: - coordinates = obj['geometry']['coordinates'] + # Handle recursive case first + if 'features' in obj: + for f in obj['features']: + # For Python 2 compatibility + # See https://www.reddit.com/r/learnpython/comments/4rc15s/yield_from_and_python_27/ # noqa: E501 + for c in coords(f): + yield c else: - coordinates = obj.get('coordinates', obj) - for e in coordinates: - if isinstance(e, (float, int)): - yield tuple(coordinates) - break - for f in coords(e): - yield f + if isinstance(obj, (tuple, list)): + coordinates = obj + elif 'geometry' in obj: + coordinates = obj['geometry']['coordinates'] + else: + coordinates = obj.get('coordinates', obj) + for e in coordinates: + if isinstance(e, (float, int)): + yield tuple(coordinates) + break + for f in coords(e): + yield f def map_coords(func, obj): ===================================== tests/test_coords.py ===================================== @@ -27,6 +27,14 @@ class CoordsTestCase(unittest.TestCase): self.assertEqual(pairs[0], (3.78, 9.28)) self.assertEqual(pairs[-1], (23.18, -34.29)) + def test_featurecollection(self): + p1 = geojson.Feature(geometry=geojson.Point((-115.11, 37.11))) + p2 = geojson.Feature(geometry=geojson.Point((-115.22, 37.22))) + itr = coords(geojson.FeatureCollection([p1, p2])) + pairs = list(itr) + self.assertEqual(pairs[0], (-115.11, 37.11)) + self.assertEqual(pairs[1], (-115.22, 37.22)) + def test_map_point(self): result = map_coords(lambda x: x, geojson.Point((-115.81, 37.24))) self.assertEqual(result['type'], 'Point') View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geojson/compare/0d7a9e0b04779a51eba3d8118bcae5eece9834dc...7748111871950e078a5370964fa22a2657c9aa27 -- View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geojson/compare/0d7a9e0b04779a51eba3d8118bcae5eece9834dc...7748111871950e078a5370964fa22a2657c9aa27 You're receiving this email because of your account on salsa.debian.org.
_______________________________________________ Pkg-grass-devel mailing list [email protected] https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-grass-devel
