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 ST_Length(SphericalGeography) #12552

Merged
merged 1 commit into from
Apr 3, 2019
Merged

Add ST_Length(SphericalGeography) #12552

merged 1 commit into from
Apr 3, 2019

Conversation

seanbarker
Copy link
Contributor

Adds ST_Length(SphericalGeography) which computes the length of a LINESTRING on the surface of a spherical model of Earth's surface, i.e. the sum of great-circle distances between adjacent points along the linestring.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@seanbarker Sean, thanks for implementing this function. I noticed that there are build failures. Looks like style check is reporting some issue. Would you take a look?

ST_Length is defined for both linestring and multi-linestring. Would you add multi-linestring support?

Some more comments inline.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@seanbarker Sean, thanks for the updates. Here are some additional comments.

@Test
public void testLength()
{
double distance1 = 1365691.096620299;
Copy link
Contributor

Choose a reason for hiding this comment

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

distance1 and distance2 variables are used only once to compute length; it is clearer to use assign length to a pre-computed constant value.

assertLength(lineString, expectedLength, 1e-4);
}

private void assertFunctionImprecise(String function, Double expected, double tolerance)
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is used only once, let's inline it

assertLength("LINESTRING (-122.41 37.77, -87.62 41.87, -71.05 42.36)", length);

// Path north pole -> south pole -> north pole should be roughly the circumference of the Earth
assertLength("LINESTRING (0.0 90.0, 0.0 -90.0, 0.0 90.0)", 4.0075e7, 1e-2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use the default tolerance 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.

The test fails with the default tolerance, but the difference in the output is only about 44 km. I can either change the estimate of earth's circumference and use the default tolerance or use the lower tolerance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change the estimate.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@seanbarker Sean, looks great. Just a couple of minor comments.

CC: @zhenxiao

assertFunction(function, DOUBLE, expectedLength);
}
else {
// assert the function returns the expected value, within the given error tolerance
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is redundant, it restates the code in the next line; please, remove

@Test
public void testLength()
{
double length = 4350866.6362;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move this variable closer to its first usage

@mbasmanova mbasmanova merged commit bb51fe3 into prestodb:master Apr 3, 2019
@mbasmanova
Copy link
Contributor

@seanbarker Sean, thank you for the contribution.

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