Changeset: 5f7bd5953413 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5f7bd5953413 Modified Files: geom/lib/libgeom.h geom/monetdb5/geom.c geom/monetdb5/geom.mal geom/sql/40_geom.sql geom/sql/Tests/All geom/sql/Tests/T24.stable.out Branch: geo Log Message:
centroid implementation: Enter commit message. Lines beginning with 'HG:' are removed. diffs (113 lines): diff --git a/geom/lib/libgeom.h b/geom/lib/libgeom.h --- a/geom/lib/libgeom.h +++ b/geom/lib/libgeom.h @@ -78,7 +78,8 @@ Flags values: Type values: -0 = GEOMETRY1 = POINT +0 = GEOMETRY +1 = POINT 2 = CURVE 3 = LINESTRING 4 = SURFACE diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c --- a/geom/monetdb5/geom.c +++ b/geom/monetdb5/geom.c @@ -108,6 +108,9 @@ geom_export str wkbDifference(wkb **out, geom_export str wkbSymDifference(wkb **out, wkb **a, wkb **b); geom_export str wkbBuffer(wkb **out, wkb **geom, dbl *distance); + +geom_export str wkbCentroid(wkb **out, wkb **geom); + bat * geom_prelude(void) { @@ -1201,3 +1204,25 @@ wkbBuffer(wkb **out, wkb **geom, dbl *di throw(MAL, "geom.Buffer", "GEOSBuffer failed"); } + + + +str +wkbCentroid(wkb **out, wkb **geom) +{ + GEOSGeom geosGeometry = wkb2geos(*geom); + + if (!geosGeometry) { + *out = geos2wkb(NULL); + return MAL_SUCCEED; + } + + *out = geos2wkb(GEOSGetCentroid(geosGeometry)); + + GEOSGeom_destroy(geosGeometry); + + if (GDKerrbuf && GDKerrbuf[0]) + throw(MAL, "geom.Centroid", "GEOSGetCentroid failed"); + return MAL_SUCCEED; + +} diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal --- a/geom/monetdb5/geom.mal +++ b/geom/monetdb5/geom.mal @@ -239,6 +239,11 @@ address wkbSymDifference comment "Returns a geometry that represents the point set semmetric difference of Geometry a with b."; +command Centroid(w:wkb) :wkb +address wkbCentroid +comment "Returns the centroid of this Geometry."; + + command prelude():void address geom_prelude; command epilogue():void address geom_epilogue; diff --git a/geom/sql/40_geom.sql b/geom/sql/40_geom.sql --- a/geom/sql/40_geom.sql +++ b/geom/sql/40_geom.sql @@ -87,7 +87,6 @@ CREATE FUNCTION Overlaps(a Geometry, b G CREATE FUNCTION Relate(a Geometry, b Geometry, pattern STRING) RETURNS BOOLEAN external name geom."Relate"; -- ogc Spatial Analysis methods - CREATE FUNCTION Area(g Geometry) RETURNS FLOAT external name geom."Area"; CREATE FUNCTION Length(g Geometry) RETURNS FLOAT external name geom."Length"; CREATE FUNCTION Distance(a Geometry, b Geometry) RETURNS FLOAT external name geom."Distance"; @@ -97,3 +96,6 @@ CREATE FUNCTION Intersection(a Geometry, CREATE FUNCTION "Union"(a Geometry, b Geometry) RETURNS Geometry external name geom."Union"; CREATE FUNCTION Difference(a Geometry, b Geometry) RETURNS Geometry external name geom."Difference"; CREATE FUNCTION SymDifference(a Geometry, b Geometry) RETURNS Geometry external name geom."SymDifference"; + + +CREATE FUNCTION Centroid(g Geometry) RETURNS Geometry external name geom."Centroid"; diff --git a/geom/sql/Tests/All b/geom/sql/Tests/All --- a/geom/sql/Tests/All +++ b/geom/sql/Tests/All @@ -41,7 +41,7 @@ T16 T21 # T22 no such unary operator 'numpoints(linestring)' # T23 no such binary operator 'pointn(linestring,tinyint)' -# T24 no such unary operator 'centroid(polygon)' +T24 # T25 no such unary operator 'pointonsurface(polygon)' T26 # T27 no such unary operator 'exteriorring(polygon)' diff --git a/geom/sql/Tests/T24.stable.out b/geom/sql/Tests/T24.stable.out --- a/geom/sql/Tests/T24.stable.out +++ b/geom/sql/Tests/T24.stable.out @@ -27,10 +27,10 @@ Ready. #SELECT AsText(Centroid(boundary)) FROM named_places WHERE name = 'Goose Island'; % sys.L # table_name -% intersection_centerline # name +% centroid_boundary # name % clob # type % 49 # length -[ "\"POINT (53.0000000000000000 15.5000000000000000)\"" ] +[ "\"POINT (63.0000000000000000 15.5000000000000000)\"" ] # 07:38:56 > # 07:38:56 > "Done." _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list