[postgis-tickets] r14696 - Support curves in centroid calculation via stroking
Paul Ramsey
pramsey at cleverelephant.ca
Thu Feb 25 07:58:40 PST 2016
Author: pramsey
Date: 2016-02-25 07:58:40 -0800 (Thu, 25 Feb 2016)
New Revision: 14696
Modified:
trunk/doc/reference_measure.xml
trunk/postgis/lwgeom_geos.c
trunk/regress/regress_ogc.sql
trunk/regress/regress_ogc_expected
Log:
Support curves in centroid calculation via stroking
https://github.com/postgis/postgis/pull/95 (Remi Cura)
Modified: trunk/doc/reference_measure.xml
===================================================================
--- trunk/doc/reference_measure.xml 2016-02-25 10:44:57 UTC (rev 14695)
+++ trunk/doc/reference_measure.xml 2016-02-25 15:58:40 UTC (rev 14696)
@@ -852,7 +852,12 @@
thought in terms of area. If an empty geometry is supplied, an empty
<varname>GEOMETRYCOLLECTION</varname> is returned. If
<varname>NULL</varname> is supplied, <varname>NULL</varname> is
- returned.</para>
+ returned.
+ If <varname>CIRCULARSTRING</varname> or <varname>COMPOUNDCURVE</varname>
+ are supplied, they are converted to linestring wtih CurveToLine first,
+ then same than for <varname>LINESTRING</varname>
+ </para>
+ <para>New in 2.3.0 : support <varname>CIRCULARSTRING</varname> and <varname>COMPOUNDCURVE</varname> (using CurveToLine)</para>
<para>The centroid is equal to the centroid of the set of component
Geometries of highest dimension (since the lower-dimension geometries
@@ -926,7 +931,20 @@
st_astext
------------------------------------------
POINT(2.30769230769231 3.30769230769231)
-(1 row)</programlisting>
+(1 row)
+
+SELECT ST_AsText(ST_centroid(g))
+FROM ST_GeomFromText('CIRCULARSTRING(0 2, -1 1,0 0, 0.5 0, 1 0, 2 1, 1 2, 0.5 2, 0 2)') AS g ;
+------------------------------------------
+POINT(0.5 1)
+
+
+SELECT ST_AsText(ST_centroid(g))
+FROM ST_GeomFromText('COMPOUNDCURVE(CIRCULARSTRING(0 2, -1 1,0 0),(0 0, 0.5 0, 1 0),CIRCULARSTRING( 1 0, 2 1, 1 2),(1 2, 0.5 2, 0 2))' ) AS g;
+------------------------------------------
+POINT(0.5 1)
+
+</programlisting>
</refsection>
<refsection>
Modified: trunk/postgis/lwgeom_geos.c
===================================================================
--- trunk/postgis/lwgeom_geos.c 2016-02-25 10:44:57 UTC (rev 14695)
+++ trunk/postgis/lwgeom_geos.c 2016-02-25 15:58:40 UTC (rev 14696)
@@ -1273,8 +1273,10 @@
Datum centroid(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom, *result;
- GEOSGeometry *geosgeom, *geosresult;
-
+ GEOSGeometry *geosgeom, *geosresult;
+ LWGEOM *igeom = NULL, *linear_geom = NULL;
+ int32 perQuad= 16;
+ int type = 0;
geom = PG_GETARG_GSERIALIZED_P(0);
/* Empty.Centroid() == Point Empty */
@@ -1288,6 +1290,21 @@
lwpoint_free(lwp);
PG_RETURN_POINTER(result);
}
+
+ type = gserialized_get_type(geom) ;
+ /* Converting curve geometry to linestring if necessary*/
+ if(type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
+ {/* curve geometry?*/
+ igeom = lwgeom_from_gserialized(geom);
+ PG_FREE_IF_COPY(geom, 0); /*free memory, we already have a lwgeom geometry copy*/
+ linear_geom = lwgeom_stroke(igeom, perQuad);
+ lwgeom_free(igeom);
+ if (linear_geom == NULL)
+ PG_RETURN_NULL();
+
+ geom = geometry_serialize(linear_geom);
+ lwgeom_free(linear_geom);
+ }
initGEOS(lwpgnotice, lwgeom_geos_error);
Modified: trunk/regress/regress_ogc.sql
===================================================================
--- trunk/regress/regress_ogc.sql 2016-02-25 10:44:57 UTC (rev 14695)
+++ trunk/regress/regress_ogc.sql 2016-02-25 15:58:40 UTC (rev 14696)
@@ -168,6 +168,11 @@
::geometry as g )
SELECT 'pointonsurface', ST_Contains(g, ST_pointonsurface(g)) from inp;
SELECT 'centroid', ST_astext(ST_centroid('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0),(2 2, 2 4, 4 4, 4 2, 2 2))'::geometry));
+SELECT 'centroid2', ST_astext(ST_centroid('LINESTRING(0 2, 0 0, 1 0, 1 2)'::geometry));
+SELECT 'centroid3', ST_astext(ST_centroid('MULTIPOINT(0 2, 0 0, 1 0, 1 2)'::geometry));
+SELECT 'centroid4', ST_astext(ST_centroid('CIRCULARSTRING(0 2, -1 1,0 0, 0.5 0, 1 0, 2 1, 1 2, 0.5 2, 0 2)'::geometry));
+SELECT 'centroid5', ST_astext(ST_centroid('COMPOUNDCURVE(CIRCULARSTRING(0 2, -1 1,0 0),(0 0, 0.5 0, 1 0),CIRCULARSTRING( 1 0, 2 1, 1 2),(1 2, 0.5 2, 0 2))'::geometry));
+
SELECT 'exteriorring', ST_astext(ST_exteriorring(ST_PolygonFromText('POLYGON((52 18,66 23,73 9,48 6,52 18),(59 18,67 18,67 13,59 13,59 18))')));
SELECT 'polygonize_garray', ST_astext(ST_polygonize('{0102000000020000000000000000000000000000000000000000000000000024400000000000000000:0102000000020000000000000000002440000000000000000000000000000000000000000000000000:0102000000020000000000000000002440000000000000244000000000000000000000000000000000:0102000000020000000000000000002440000000000000244000000000000024400000000000000000:0102000000020000000000000000002440000000000000244000000000000000000000000000002440:0102000000020000000000000000000000000000000000244000000000000000000000000000002440:0102000000020000000000000000000000000000000000244000000000000024400000000000002440:0102000000020000000000000000000000000000000000244000000000000000000000000000000000:0102000000020000000000000000000000000000000000244000000000000024400000000000000000}'::geometry[]));
Modified: trunk/regress/regress_ogc_expected
===================================================================
--- trunk/regress/regress_ogc_expected 2016-02-25 10:44:57 UTC (rev 14695)
+++ trunk/regress/regress_ogc_expected 2016-02-25 15:58:40 UTC (rev 14696)
@@ -96,6 +96,10 @@
equals|t
pointonsurface|t
centroid|POINT(5.08333333333333 5.08333333333333)
+centroid2|POINT(0.5 0.8)
+centroid3|POINT(0.5 1)
+centroid4|POINT(0.5 1)
+centroid5|POINT(0.5 1)
exteriorring|LINESTRING(52 18,66 23,73 9,48 6,52 18)
polygonize_garray|GEOMETRYCOLLECTION EMPTY
polygonize_garray|POLYGON((10 0,0 0,0 10,10 10,10 0))
More information about the postgis-tickets
mailing list