jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
915 stars 121 forks source link

geojson.map_coords.__doc___ confusing #75

Closed disarticulate closed 8 years ago

disarticulate commented 8 years ago

I'm doing this test case: print(geojson.map_coords.__doc__)

Returns the coordinates from a Geometry after applying the provided
function to the tuples.
:param func: Function to apply to tuples
:type func: function
:param obj: A geometry or feature to extract the coordinates from.
:type obj: Point, LineString, MultiPoint, MultiLineString, Polygon,
MultiPolygon
:return: The result of applying the function to each coordinate array.
:rtype: list
:raises ValueError: if the provided object is not a Geometry.
     for item in geoj:
         print(item)
         #geoj_proj = geojson.utils.map_coords(lambda x: conversions.LFtoLongLat(x), item)
         geoj_proj = geojson.utils.map_coords(lambda x: print(x), item)
         break

{"coordinates": [[4493.178634548326, 3454.400914449211], [4483.730689118465, 3449.566045195004], [4500, 3452.474407915964]], "type": "LineString"} 4493.178634548326 3454.400914449211 4483.730689118465 3449.566045195004 4500 3452.474407915964

I expected print(x) to bu a tuple? As the doc says 'after applying the provided function to the tuples. Am I missing something? My conversions.LFtoLongLat expect a tuple, as I'm doing an affine transformation.

disarticulate commented 8 years ago

It looks like I don't understand the underlying map issue.

frewsxcv commented 8 years ago

The source for reference

Also the documentation in the readme

    ...
    elif obj['type'] in ['LineString', 'MultiPoint']:
        coordinates = [tuple(map(func, c)) for c in obj['coordinates']]
    ...

This code causes func to get applied on every numeric value within a coordinate for all coordinates.

If it were:

    ...
    elif obj['type'] in ['LineString', 'MultiPoint']:
        coordinates = [tuple(map(func, obj['coordinates']))]
    ...

Then it would like you say and apply func on every coordinate tuple.

If you know a way to make the documentation more clear about this, feel free to open a pull request. Let me know if you have any other issues!

disarticulate commented 8 years ago

I've added two forks. One to update the documentation to clarify the dimension of the mapping function. Another with a general utility based on the mapping function to take a function which operates on tuples. https://github.com/disarticulate/python-geojson/commit/8492796a7c4ef5d5b1df2b4f996a214670a01d55 https://github.com/disarticulate/python-geojson/commit/c58f1cbdee3b55269e334b4503ed4fd766b378ba