- #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
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
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);
}