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/geogfn: implement ST_Project #49949

Merged
merged 1 commit into from
Jun 8, 2020
Merged

Conversation

hueypark
Copy link
Contributor

@hueypark hueypark commented Jun 7, 2020

Fixes #48402

Release note (sql change): This PR implement adds the ST_Project({geography,float8,float8})

@blathers-crl
Copy link

blathers-crl bot commented Jun 7, 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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Jun 7, 2020
@blathers-crl blathers-crl bot requested a review from otan June 7, 2020 15:36
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.

Thanks! I have a few suggestions on making this cleaner.

}

// Normalize azimuth
azimuth -= 2.0 * math.Pi * math.Floor(azimuth/(2.0*math.Pi))
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are using s1.Angle(), there is a Normalized function we can use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Check the distance validity.
if distance > (math.Pi * spheroid.Radius) {
return nil, errors.Newf("Distance must not be greater than %v", math.Pi*spheroid.Radius)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: errors start with lowercase.
does this error also appear in PostGIS? can we use %f instead?'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

y := point.Y()

projected := spheroid.Project(
s2.LatLng{Lat: s1.Angle(x), Lng: s1.Angle(y)},
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe you can use s2.LatLngFromDegrees(point.Y(), point.X()). I also Lat is x, Lng is y.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -128,3 +166,65 @@ func length(regions []s2.Region, useSphereOrSpheroid UseSphereOrSpheroid) (float
}
return totalLength, nil
}

// longitudeNormalize convert a longitude to the range of -Pi, Pi.
func longitudeNormalize(lon 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.

can we convert this to s1.Angle, and use s1.Angle(blah).Normalized()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


C.geod_direct(
&s.cRepr,
C.double(math.Pi*point.Lat/180.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use point.Lat.Degrees() for this, i believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

nil)

return s2.LatLng{
Lat: s1.Angle(float64(lat) * math.Pi / 180.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

s1.Angle(lat * s1.Degree) may be good here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed this with s2.LatLngFromDegrees.

The distance is given in meters. Negative values are supported.

The azimuth (also known as heading or bearing) is given in radians. It is measured clockwise from true north (azimuth zero).
East is azimuth π/2 (90 degrees); south is azimuth π (180 degrees); west is azimuth 3π/2 (270 degrees).
Copy link
Contributor

Choose a reason for hiding this comment

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

if you wanted extra new lines here to display in HTML format, you'll need an extra new line here.
This new line is otherwise displayed as spaces (see autogenerated code and how the

tags are missing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen functions.md, but I can't find anything wrong about the format. Can you explain it in more detail?

Copy link
Contributor

Choose a reason for hiding this comment

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


<p>The azimuth (also known as heading or bearing) is given in radians. It is measured clockwise from true north (azimuth zero).
East is azimuth π/2 (90 degrees); south is azimuth π (180 degrees); west is azimuth 3π/2 (270 degrees).
Negative azimuth values and values greater than 2π (360 degrees) are supported.</p>

if you wanted new line between them, you'd want


<p>The azimuth (also known as heading or bearing) is given in radians. It is measured clockwise from true north (azimuth zero).</p>
<p>East is azimuth π/2 (90 degrees); south is azimuth π (180 degrees); west is azimuth 3π/2 (270 degrees).</p>
<p>Negative azimuth values and values greater than 2π (360 degrees) are supported.</p>

then you need a new line between each here. if you're ok with just space difference, then this is ok. i'm up for either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for explain. I want to keep it as it is.

@hueypark
Copy link
Contributor Author

hueypark commented Jun 8, 2020

Thank you for the review.

@blathers-crl
Copy link

blathers-crl bot commented Jun 8, 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.

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.

two small things -- otherwise LGTM! thank you so much!

@@ -128,3 +166,32 @@ func length(regions []s2.Region, useSphereOrSpheroid UseSphereOrSpheroid) (float
}
return totalLength, nil
}

// latitudeNormalize convert a latitude to the range of -Pi/2, Pi/2.
func latitudeNormalize(lat 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.

nit: can you name this normalizeLatitude?
also shame there isn't something similar in s1/s2 :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

C.double(distance),
&lat,
&lng,
nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i prefer trailing commas and one arg per line, i.e.

  nil,
)

easier to git blame and less merge conflict-y.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

projected := spheroid.Project(
s2.LatLngFromDegrees(x, y),
distance,
azimuth)
Copy link
Contributor

Choose a reason for hiding this comment

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

trailing comma here too, and on geom.NewPointFlat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Fixes cockroachdb#48402

Release note (sql change): This PR implement adds the ST_Project({geography,float8,float8})
@otan
Copy link
Contributor

otan commented Jun 8, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 8, 2020

Build succeeded

@craig craig bot merged commit cb34350 into cockroachdb:master Jun 8, 2020
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/geogfn: implement ST_Project({geography,float8,float8})
3 participants