jazzband / geojson

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

Add __getitem__ and __setitem__ to provide direct access to coordinates #80

Closed lafrech closed 8 years ago

lafrech commented 8 years ago

Assuming

    p = geojson.Point((-115.81, 37.24))

If would be convenient to be able to write

    print(p[0])

rather than

    print(p['coordinates'][0])

Is this something you would consider?

I can send a PR.

frewsxcv commented 8 years ago

You should also be able to do p.coordinates[0]. I don't think we need another way to get the coordinates. Thanks for the idea though!

lafrech commented 8 years ago

Yes, I noticed that. It's a bit better.

My data model has a "position" attribute which is a geojson.Point. Currently, I need to write

my_object.position.coordinates[0]

which I'd happily simplify into

my_object.position[0]

This is not really a big deal, and I guess I could monkey patch geojson geometries or just live with it.

frewsxcv commented 8 years ago

There can be other properties on a Point besides coordinate, so I think it wouldn't be too obvious which one you're indexing into.

lafrech commented 8 years ago

Fair enough. I thought coordinates was the only list-like attribute, so it wouldn't be ambiguous.

Sorry for the noise.

frewsxcv commented 8 years ago

All good, no worries! Definitely a good idea that was worth considering :)