]> granicus.if.org Git - postgis/commitdiff
Unify geometry centroid functions
authorDarafei Praliaskouski <me@komzpa.net>
Tue, 5 Jun 2018 14:40:45 +0000 (14:40 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Tue, 5 Jun 2018 14:40:45 +0000 (14:40 +0000)
Make ST_Centroid call lwgeom_centroid.

Closes #3960
Closes https://github.com/postgis/postgis/pull/256

git-svn-id: http://svn.osgeo.org/postgis/trunk@16608 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
postgis/lwgeom_geos.c
postgis/postgis.sql.in

diff --git a/NEWS b/NEWS
index 947a8b2beb69eb2bd1a01c6e85b8127060c95dfb..eeb88139d9c69834e3436535d48ceea8f91c1d03 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,10 +51,8 @@ PostGIS 2.5.0
   - #3097, Really allow MULTILINESTRING blades in ST_Split() (Paul Ramsey)
   - #3942, geojson: Do not include private header for json-c >= 0.13 (Björn Esser)
   - #3954, ST_GeometricMedian now supports point weights (Darafei Praliaskouski)
-  - #3965, ST_ClusterKMeans used to lose some clusters on initialization
-           (Darafei Praliaskouski)
-  - #3971, ST_ClusterKMeans now uses better initial seed (Darafei Praliaskouski)
-  - #3977, ST_ClusterKMeans is now faster and simpler (Darafei Praliaskouski)
+  - #3965, #3971, #3977, #4071 ST_ClusterKMeans rewritten: better initialization,
+           faster convergence, K=2 even faster (Darafei Praliaskouski)
   - #3982, ST_AsEncodedPolyline supports LINESTRING EMPTY and MULTIPOINT EMPTY
            (Darafei Praliaskouski)
   - #3986, ST_AsText now has second argument to limit decimal digits
@@ -72,13 +70,13 @@ PostGIS 2.5.0
            robustness issues. (Darafei Praliaskouski)
   - #4025, #4032 Fixed precision issue in ST_ClosestPointOfApproach,
            ST_DistanceCPA, and ST_CPAWithin (Paul Ramsey, Darafei Praliaskouski)
-  - #4071, ST_ClusterKMeans crash on NULL/EMPTY fixed (Darafei Praliaskouski)
   - #4076, Reduce use of GEOS in topology implementation (Björn Harrtell)
   - #4080, Add external raster band index to ST_BandMetaData
   - Add Raster Tips section to Documentation for information about
     Raster behavior (e.g. Out-DB performance, maximum open files)
   - #4084: Fixed wrong code-comment regarding front/back of BOX3D (Matthias Bay)
   - #4060, #4094, PostgreSQL JIT support (Raúl Marín, Laurenz Albe)
+  - #3960, ST_Centroid now uses lwgeom_centroid (Darafei Praliaskouski)
 
 PostGIS 2.4.4
 2018/04/08
index 2e91b7b369eb2fb51b02061df2161b98d81632cf..cf915affa9ddcde9e695ca048f4271c918f238c6 100644 (file)
@@ -1306,69 +1306,19 @@ PG_FUNCTION_INFO_V1(centroid);
 Datum centroid(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *geom, *result;
-       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 */
-       if ( gserialized_is_empty(geom) )
-       {
-               LWPOINT *lwp = lwpoint_construct_empty(
-                                  gserialized_get_srid(geom),
-                                  gserialized_has_z(geom),
-                                  gserialized_has_m(geom));
-               result = geometry_serialize(lwpoint_as_lwgeom(lwp));
-               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) PG_RETURN_NULL();
-
-               geom = geometry_serialize(linear_geom);
-               lwgeom_free(linear_geom);
-       }
-
-       initGEOS(lwpgnotice, lwgeom_geos_error);
-
-       geosgeom = POSTGIS2GEOS(geom);
+       LWGEOM *lwgeom, *lwresult;
 
-       if (!geosgeom)
-               HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
-
-       geosresult = GEOSGetCentroid(geosgeom);
-
-       if (!geosresult)
-       {
-               GEOSGeom_destroy(geosgeom);
-               HANDLE_GEOS_ERROR("GEOSGetCentroid");
-       }
-
-       GEOSSetSRID(geosresult, gserialized_get_srid(geom));
-
-       result = GEOS2POSTGIS(geosresult, gserialized_has_z(geom));
-
-       if (!result)
-       {
-               GEOSGeom_destroy(geosgeom);
-               GEOSGeom_destroy(geosresult);
-               elog(ERROR,"Error in GEOS-PGIS conversion");
-               PG_RETURN_NULL();
-       }
-       GEOSGeom_destroy(geosgeom);
-       GEOSGeom_destroy(geosresult);
+       geom = PG_GETARG_GSERIALIZED_P(0);
 
+       lwgeom = lwgeom_from_gserialized(geom);
+       lwresult = lwgeom_centroid(lwgeom);
+       lwgeom_free(lwgeom);
        PG_FREE_IF_COPY(geom, 0);
 
+       if (!lwresult) PG_RETURN_NULL();
+
+       result = geometry_serialize(lwresult);
+       lwgeom_free(lwresult);
        PG_RETURN_POINTER(result);
 }
 
index b99cefde83c3553aa439c7818e7a3791513cd2aa..6e878bd028719ba6de5d415274eee3bd883a85a6 100644 (file)
@@ -3710,7 +3710,6 @@ CREATE OR REPLACE FUNCTION ST_Node(g geometry)
 --
 --
 -- Availability: 2.1.0
--- Requires GEOS >= 3.4.0
 --
 CREATE OR REPLACE FUNCTION ST_DelaunayTriangles(g1 geometry, tolerance float8 DEFAULT 0.0, flags int4 DEFAULT 0)
        RETURNS geometry