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

geo: coerce invalid geography coordinates into geometry #50457

Merged

Conversation

sooryranga
Copy link
Contributor

This commit resolves: #50219

Previously geometry did not convert out of range lat-lngs into
correct range. This commit mimics the behavior found in PostGIS.
It converts out of range lat-lngs into correct range.

Release note (sql change): Geometry now coerce invalid
geography coordinates into correct geometry.

@blathers-crl
Copy link

blathers-crl bot commented Jun 21, 2020

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

I have added a few people who may be able to assist in reviewing:

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Jun 21, 2020
@blathers-crl blathers-crl bot requested a review from otan June 21, 2020 21:48
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@sooryranga
Copy link
Contributor Author

@otan if you want this PR to mimic the behaviour exactly, i could add NOTICE feature as well. Let me know, thanks!

@otan
Copy link
Contributor

otan commented Jun 21, 2020

Thanks for doing this!

This only applies to geography types - this code does geometry too. I also think the s2 library has normalise functions you can reuse.

pkg/geo/parse.go Outdated

// longitudeNormalize will normalize angles to
// spherical polar angles (-180 to 180)
func longitudeNormalize(log float64) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason we can't use s2.Angle(angle).Normalized()?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should call this lng, log is something else

pkg/geo/parse.go Outdated Show resolved Hide resolved
@otan
Copy link
Contributor

otan commented Jun 26, 2020 via email

@sooryranga
Copy link
Contributor Author

@otan yup! I was caught up other things last week, will update the pr today. Thanks for the insights.

@sooryranga
Copy link
Contributor Author

@otan I was able to get it running with your normalizing functions and s2.LatLngFromDegrees.
I will wait for that PR to get merge and re-use your normalizing functions.
Then I will update this pr for another round of reviews.

Thanks.

@otan
Copy link
Contributor

otan commented Jun 29, 2020

#50708 is being merged, but as a heads up, #50765 will affect you this too.

#50765 means that you'll need to update the coordinates before we calculate the bounding box in spatialObjectFromGeomT. but there's a param soType which will allow you to determine whether it is GEOMETRY or GEOGRAPHY (we only want to do this for GEOGRAPHY).

if you don't want to wait, feel to rebase to #50708 and i'll take care of the merge with #50765 - otherwise if you could wait a day or so I'd be very appreciative.

Again, thank you for dealing with this!

@sooryranga
Copy link
Contributor Author

@otan No worries, I will wait for your new PR ( #50765) to be merged before rebasing and updating this PR.

@otan
Copy link
Contributor

otan commented Jun 30, 2020

All ready to go! Thank you for your patience.

pkg/geo/parse.go Outdated Show resolved Hide resolved
pkg/geo/parse.go Outdated Show resolved Hide resolved
@sooryranga sooryranga force-pushed the arun/fix_invalid_geography_coordinates branch from 258a664 to e66767b Compare July 1, 2020 02:24
@blathers-crl blathers-crl bot requested a review from otan July 1, 2020 02:24
@blathers-crl
Copy link

blathers-crl bot commented Jul 1, 2020

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@sooryranga
Copy link
Contributor Author

@otan updated the PR. Good call on using flatbuffers, makes it a lot more simpler.

Thanks for the feedback!

@sooryranga sooryranga force-pushed the arun/fix_invalid_geography_coordinates branch from e66767b to a22c16f Compare July 1, 2020 02:30
Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

have some style nits to make this neater!

pkg/geo/geo.go Outdated Show resolved Hide resolved
pkg/geo/geo.go Show resolved Hide resolved
pkg/geo/parse.go Outdated Show resolved Hide resolved
pkg/geo/geo.go Outdated Show resolved Hide resolved
pkg/geo/geo.go Outdated Show resolved Hide resolved
pkg/geo/geo.go Outdated Show resolved Hide resolved
This commit resolves: cockroachdb#50219

Previously geometry did not convert out of range lat-lngs into
correct range. This commit mimics the behavior found in PostGIS.
It converts out of range lat-lngs into correct range.

Release note (sql change): Geometry now coerce invalid
geography coordinates into correct geometry.
@sooryranga sooryranga force-pushed the arun/fix_invalid_geography_coordinates branch from a22c16f to 1184c63 Compare July 1, 2020 13:50
@blathers-crl blathers-crl bot requested a review from otan July 1, 2020 13:50
Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@otan
Copy link
Contributor

otan commented Jul 1, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 1, 2020

Build succeeded

@craig craig bot merged commit e99e7a8 into cockroachdb:master Jul 1, 2020
@SWDevAngel
Copy link

@Arun4rangan LAST DAY TO ORDER!!!
Hi Arun. Thank you for contributing to CockroachDB this year. As a token of our appreciation we would like to send you a gift. We tried to reach you via GitHub or on email, but if you didn’t see the message please DM me on our community Slack @lisa so I can send you a link to order your gift. (If you don’t want a gift, we also have a charitable contribution choice.) All orders must be in by December 13 (that’s tomorrow!), so please send this asap. :)

@sooryranga sooryranga deleted the arun/fix_invalid_geography_coordinates branch August 4, 2023 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community X-blathers-triaged blathers was able to find an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geo: coerce invalid geography coordinates into geometry
4 participants