Skip to content
Commits on Source (4)
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)
------------------
......
......@@ -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
......
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 <sebastic@debian.org> Thu, 05 Jul 2018 11:06:32 +0200
-- Bas Couwenberg <sebastic@debian.org> Thu, 18 Oct 2018 14:52:47 +0200
python-geojson (2.4.0-1) unstable; urgency=medium
......
__version__ = "2.4.0"
__version__ = "2.4.1"
__version_info__ = tuple(map(int, __version__.split(".")))
......@@ -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
"""
......
......@@ -10,7 +10,14 @@ def coords(obj):
:return: A generator with coordinate tuples from the geometry or feature.
:rtype: generator
"""
# 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:
if isinstance(obj, (tuple, list)):
coordinates = obj
elif 'geometry' in obj:
......
......@@ -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')
......