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/geomfn: implement ST_MinimumBoundingCircle #55567

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

C0rWin
Copy link
Contributor

@C0rWin C0rWin commented Oct 15, 2020

This commit implements ST_MinimumBoundingCircle builtin function to
return polygon shape which approximates minimum bounding circle to
contain provided geometry.

Resolves: #48987

Signed-off-by: Artem Barger bartem@il.ibm.com

Release note (sql change): Returns polygon shape which approximates
minimum bounding circle to contain geometry

@blathers-crl
Copy link

blathers-crl bot commented Oct 15, 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 Oct 15, 2020
@blathers-crl blathers-crl bot requested a review from otan October 15, 2020 01:13
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@C0rWin C0rWin changed the title geo/geomfn: implement geo/geomfn: implement ST_MinimumBoundingCircle Oct 15, 2020
@blathers-crl
Copy link

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

@C0rWin C0rWin force-pushed the bound_circle branch 2 times, most recently from fca1ea9 to 107acd0 Compare October 15, 2020 08:10
@C0rWin
Copy link
Contributor Author

C0rWin commented Oct 15, 2020

Seems to fail logic tests in CI due to precision issues, are there any suggestions on how to overcome it, @otan ?

PS. Updated UT to work with ST_SnapToGrid.

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.

i'll review this one after you rebase with MinimumBoundingRadius when that merges!

@blathers-crl
Copy link

blathers-crl bot commented Oct 15, 2020

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

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

@C0rWin
Copy link
Contributor Author

C0rWin commented Oct 15, 2020

i'll review this one after you rebase with MinimumBoundingRadius when that merges!

Just rebased on top the previous one, though, still need to wait to merge MinimumBoundingRadius first.

@blathers-crl
Copy link

blathers-crl bot commented Oct 15, 2020

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

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

}
return tree.NewDGeometry(polygon), nil
},
Info: "Returns the smallest circle polygon that can fully contain a geometry. ",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove trailing space.

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

@@ -5539,6 +5539,28 @@ See http://developers.google.com/maps/documentation/utilities/polylinealgorithm`
Volatility: tree.VolatilityImmutable,
}),

"st_minimumboundingcircle": makeBuiltin(defProps(),
tree.Overload{
Types: tree.ArgTypes{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use geometryOverload1 for this

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

@blathers-crl
Copy link

blathers-crl bot commented Oct 15, 2020

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

🦉 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.

Hey -- read the docs over and noticed we're missing a permutation of this argument.

@@ -5539,6 +5539,19 @@ See http://developers.google.com/maps/documentation/utilities/polylinealgorithm`
Volatility: tree.VolatilityImmutable,
}),

"st_minimumboundingcircle": makeBuiltin(defProps(),
geometryOverload1(func(evalContext *tree.EvalContext, g *tree.DGeometry) (tree.Datum, error) {
polygon, _, _, err := geomfn.MinimumBoundingCircle(g.Geometry)
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like we're missing the "num_segs_per_qt_circ" arg here -- see https://postgis.net/docs/ST_MinimumBoundingCircle.html.

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 have noted this as well, however, didn't find in GEOS implementation where you can control this. Do you have suggestions?

extern GEOSGeometry GEOS_DLL *GEOSMinimumBoundingCircle_r(GEOSContextHandle_t handle,
                                                const GEOSGeometry* g, double* radius,
                                                GEOSGeometry** center);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I've found how to handle this in PostGis

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest using ST_Buffer on the center by the radius.

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 was going to suggest using ST_Buffer on the center by the radius.

Added implementation to do just this.

query T
SELECT ST_AsText(ST_SnapToGrid(ST_MinimumBoundingCircle(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING(55 75,125 150), POINT(20 80))')), 0.001));
----
POLYGON ((135.597000000000008 115, 134.384999999999991 102.689999999999998, 130.794000000000011 90.853999999999999, 124.963000000000008 79.945000000000007, 117.116 70.384, 107.555000000000007 62.536999999999999, 96.646000000000001 56.706000000000003, 84.810000000000002 53.115000000000002, 72.5 51.902999999999999, 60.189999999999998 53.115000000000002, 48.353999999999999 56.706000000000003, 37.445 62.536999999999999, 27.884 70.384, 20.036999999999999 79.945000000000007, 14.206 90.853999999999999, 10.615 102.689999999999998, 9.403 115, 10.615 127.310000000000002, 14.206 139.146000000000015, 20.036999999999999 150.055000000000007, 27.884 159.616000000000014, 37.445 167.462999999999994, 48.353999999999999 173.294000000000011, 60.189999999999998 176.884999999999991, 72.5 178.097000000000008, 84.810000000000002 176.884999999999991, 96.646000000000001 173.294000000000011, 107.555000000000007 167.462999999999994, 117.116 159.616000000000014, 124.963000000000008 150.055000000000007, 130.794000000000011 139.146000000000015, 134.384999999999991 127.310000000000002, 135.597000000000008 115))
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test for the minimum bounding circle of a single point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, sure.

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

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 for the update! a small stylistic comment and this is good to go :)

return nil, err
}
return tree.NewDGeometry(polygon), nil
}, types.Geometry,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line per argument, i.e.

geometryOverload1(
  func(evalContext *tree.EvalContext, g *tree.DGeometry) (tree.Datum, error) {
  },
  types,Geometry,
  infoBuilder{
    ...
  },
},
tree.Overload{ , / ...

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

return nil, err
}

polygon, err := geomfn.Buffer(centroid,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line per argument, i.e.

polygon, err := geomfn.Buffer(
   centroid,
   geomfn.MakeDefaultBufferParams().WithQuadrantSegments(int(numOfSeg)),
   radius,
)

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

@C0rWin
Copy link
Contributor Author

C0rWin commented Oct 19, 2020

thanks for the update! a small stylistic comment and this is good to go :)

small update + rebase.

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!

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 19, 2020

Build failed:

@otan
Copy link
Contributor

otan commented Oct 19, 2020 via email

This commit implements ST_MinimumBoundingCircle builtin function to
return polygon shape which approximates minimum bounding circle to
contain provided geometry.

Resolves: cockroachdb#48987

Signed-off-by: Artem Barger <bartem@il.ibm.com>

Release note (sql change): Returns polygon shape which approximates
minimum bounding circle to contain geometry
@C0rWin
Copy link
Contributor Author

C0rWin commented Oct 19, 2020

looks like a lint failure

apologies missed that one, fixed now

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

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 20, 2020

Build succeeded:

@craig craig bot merged commit e16811f into cockroachdb:master Oct 20, 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/geomfn: implement ST_MinimumBoundingCircle({geometry,int4})
3 participants