Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lafrech opened this issue Jul 18, 2016 · 5 comments
Closed

Comments

@lafrech
Copy link
Contributor

lafrech commented Jul 18, 2016

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
Copy link
Collaborator

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
Copy link
Contributor Author

lafrech commented Jul 18, 2016

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
Copy link
Collaborator

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
Copy link
Contributor Author

lafrech commented Jul 18, 2016

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

Sorry for the noise.

@frewsxcv
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants