Skip to content

__geo_interface__ support #493

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

angusmcb
Copy link
Contributor

@angusmcb angusmcb commented Mar 27, 2025

Summary

This changes adds __geo_interface__ support: https://gist.github.com/sgillies/2217756

The geo_interface is a method of exchanging geospatial data between applications. For example, it makes it directly possible to read into geopandas:

import geopandas as gpd
gpd.GeoDataFrame.from_features(wn.junctions)

or with shapely:

from shapely.geometry import shape
shape(wn.links['link_name'].geometry)

or with any other package which supports geo_interface

As part of this I've changed added to the behaviour of WaterNetworkModel.junctions , pipes, etc. to act as a Mapping, which also implements the geo_interface, but which also maintains the existing behaviour when called. ( this means that their behaviour is more similar to WaterNetworkModel.nodes and links ).

This doesn't replace the gis modules (although it could be used to simplify the logic within to_gis()). It also doesn't require any dependencies.

As part of this I created a common class for both Node and Link to inherit from, and moved some of the shared methods over to it. In passing, I have also removed some other old uses of the six package and uses of Object.

Tests and documentation

I have not yet written the tests and document - I will do some refinements, writing tests and adding to the documentation if you agree in principle to the changes so far.

Acknowledgement

By contributing to this software project, I acknowledge that I have reviewed the software quality assurance guidelines and that my contributions are submitted under the Revised BSD License.

@angusmcb
Copy link
Contributor Author

Although marked as not yet ready for review, I would like some feedback on the principle of the changes.

@kbonney
Copy link
Collaborator

kbonney commented Apr 22, 2025

Hi @angusmcb , thanks for the PR. Could you help me understand what the __geo_interface__ implementation you have done is different from the data in produced by to_gis()? Are there any advantages of having this for the typical user?

@angusmcb
Copy link
Contributor Author

You're probably right that this functionality is super niche.

The advantage is mostly just that it bypasses having to convert to geopandas and the loss of some of the element parameters that is necessary in to_gis() (which I think is done mainly to allow writing to file).

Happy to drop it though.

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

Successfully merging this pull request may close these issues.

2 participants