-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
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. |
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. |
fca1ea9
to
107acd0
Compare
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 |
There was a problem hiding this 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!
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Just rebased on top the previous one, though, still need to wait to merge MinimumBoundingRadius first. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
pkg/sql/sem/builtins/geo_builtins.go
Outdated
} | ||
return tree.NewDGeometry(polygon), nil | ||
}, | ||
Info: "Returns the smallest circle polygon that can fully contain a geometry. ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove trailing space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/sql/sem/builtins/geo_builtins.go
Outdated
@@ -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{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
There was a problem hiding this 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.
pkg/sql/sem/builtins/geo_builtins.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
867f32e
to
2b700e1
Compare
There was a problem hiding this 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 :)
pkg/sql/sem/builtins/geo_builtins.go
Outdated
return nil, err | ||
} | ||
return tree.NewDGeometry(polygon), nil | ||
}, types.Geometry, |
There was a problem hiding this comment.
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{ , / ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/sql/sem/builtins/geo_builtins.go
Outdated
return nil, err | ||
} | ||
|
||
polygon, err := geomfn.Buffer(centroid, |
There was a problem hiding this comment.
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,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
small update + rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
bors r+
Build failed: |
looks like a lint failure
|
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
apologies missed that one, fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
bors r+
Build succeeded: |
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