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 support for getting projected coordinates #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jorisvandenbossche
Copy link
Collaborator

@jorisvandenbossche jorisvandenbossche commented Mar 13, 2023

Just putting it here as draft PR to show what I was experimenting with (this just projects a single point at the moment).

The reason I started looking at this is because it would be nice to get the coordinates in a certain projection for quick plotting of spherely geography objects (https://dewey.dunnington.ca/post/2022/s2-version-1.1.0/#plotting, https://github.com/r-spatial/s2/blob/76e36ae9ef1348412726e780f6a5a9e4ba0805d8/R/plot.R).
But also in general we will want to expose methods to get all the coordinates, and then providing an option to get projected coordinates (in some basic projections that S2 supports) might be nice.

For the plotting, we will also need to add tesselation in the process of getting the projected coordinates (to correctly represent the shortest-path-on-the-sphere in a projection that uses "straight" lines)


// )pbdoc");

m.def("project_mercator", &project_mercator);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem with vectorizing a function like this is that it returns multiple values for each input value (so in numpy ufunc terms, it would be a generalize ufunc with a signature of "()->(n)" (adding one dimension)). But this is not something that py::vectorize supports AFAIK. So we might need to write this more manually (eg writing the loop ourselves, only supporting 1D input, which is what we do in shapely as well).

And for non-point geographies, it doesn't fit in the ufunc paradigm anyway, since you have a variable number of coordinate pairs that gets returned (like shapely.get_coordinates)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we follow shapely.get_coordinates API then? I.e., return a (N, 2) array with a flat index. I guess with tessellation enabled we'll almost always want to get the index.

@benbovy
Copy link
Owner

benbovy commented Mar 13, 2023

Thanks for looking into this @jorisvandenbossche. I agree it would be nice to have an option to get coordinates in a given projection with support for tessellation.

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