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 get_x and get_y vectorized functions (Point-only) #37

Merged
merged 9 commits into from
Nov 27, 2024

Conversation

jorisvandenbossche
Copy link
Collaborator

Awaiting a more complex function to get coordinates in general, adding a simple get_lng/get_lat functions just for points (so those can easily be vectorized)

@jorisvandenbossche
Copy link
Collaborator Author

I see that R's s2 (based on bigquery?) still calls this st_x and st_y, so should we also use get_x and get_y here?

@martinfleis
Copy link
Contributor

should we also use get_x and get_y here?

+1 on that as that is also consistent with shapely.

@jorisvandenbossche jorisvandenbossche changed the title Add get_lat and get_lng vectorized functions (Point-only) Add get_x and get_y vectorized functions (Point-only) Aug 19, 2024
Copy link
Owner

@benbovy benbovy left a comment

Choose a reason for hiding this comment

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

This is (almost) ready I guess?

Alternatively we could return NaN instead of returning an error for non-point geographies? Or expose a parameter that allows user choosing between the two behaviors (similarly to the SAFE prefix in bigquery)?

(also both functions can be added to the doc API reference).

src/coords.cpp Outdated
Comment on lines 19 to 23
auto point = static_cast<Point*>(geog);
auto s2point = point->s2point();
auto latlng = S2LatLng(std::move(s2point));
double lat = latlng.lat().degrees();
return lat;
Copy link
Owner

Choose a reason for hiding this comment

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

We could also just call s2geography::s2_y.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, at the time of writing this PR I didn't realize that existed, in the meantime I had noticed that as well.
I think that also has the behaviour of returning NaN for non-point geometries, as you suggested, if we would use it as is, without any validation before calling it.

I am not entirely following what the implementation is doing though: https://github.com/paleolimbot/s2geography/blob/5b06341403ec2e030b2a254bfa96d8c3386296f3/src/s2geography/accessors.cc#L165-L178
When is it possible that you need that for loop in there? Or does that mean that if you have a collection of two points, it will just give you the x/y of the first point? (I would find that a bit unexpected behaviour)

Copy link
Owner

Choose a reason for hiding this comment

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

Yes I was a bit confused by the implementation too. Probably safer to keep raising an error in case of non-point geographies for now.

@jorisvandenbossche jorisvandenbossche merged commit da0d66d into benbovy:main Nov 27, 2024
15 checks passed
@jorisvandenbossche jorisvandenbossche deleted the get-lat-lng branch November 27, 2024 12:34
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.

3 participants