[postgis-tickets] r16608 - Unify geometry centroid functions
Darafei
komzpa at gmail.com
Tue Jun 5 07:40:45 PDT 2018
Author: komzpa
Date: 2018-06-05 07:40:45 -0700 (Tue, 05 Jun 2018)
New Revision: 16608
Modified:
trunk/NEWS
trunk/postgis/lwgeom_geos.c
trunk/postgis/postgis.sql.in
Log:
Unify geometry centroid functions
Make ST_Centroid call lwgeom_centroid.
Closes #3960
Closes https://github.com/postgis/postgis/pull/256
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2018-06-05 12:28:44 UTC (rev 16607)
+++ trunk/NEWS 2018-06-05 14:40:45 UTC (rev 16608)
@@ -51,10 +51,8 @@
- #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,7 +70,6 @@
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
@@ -79,6 +76,7 @@
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
Modified: trunk/postgis/lwgeom_geos.c
===================================================================
--- trunk/postgis/lwgeom_geos.c 2018-06-05 12:28:44 UTC (rev 16607)
+++ trunk/postgis/lwgeom_geos.c 2018-06-05 14:40:45 UTC (rev 16608)
@@ -1306,69 +1306,19 @@
Datum centroid(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom, *result;
- GEOSGeometry *geosgeom, *geosresult;
- LWGEOM *igeom = NULL, *linear_geom = NULL;
- int32 perQuad= 16;
- int type = 0;
+ LWGEOM *lwgeom, *lwresult;
+
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);
- }
+ lwgeom = lwgeom_from_gserialized(geom);
+ lwresult = lwgeom_centroid(lwgeom);
+ lwgeom_free(lwgeom);
+ PG_FREE_IF_COPY(geom, 0);
- 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();
+ if (!lwresult) PG_RETURN_NULL();
- geom = geometry_serialize(linear_geom);
- lwgeom_free(linear_geom);
- }
-
- initGEOS(lwpgnotice, lwgeom_geos_error);
-
- geosgeom = POSTGIS2GEOS(geom);
-
- 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);
-
- PG_FREE_IF_COPY(geom, 0);
-
+ result = geometry_serialize(lwresult);
+ lwgeom_free(lwresult);
PG_RETURN_POINTER(result);
}
Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in 2018-06-05 12:28:44 UTC (rev 16607)
+++ trunk/postgis/postgis.sql.in 2018-06-05 14:40:45 UTC (rev 16608)
@@ -3710,7 +3710,6 @@
--
--
-- 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
More information about the postgis-tickets
mailing list