Opened 10 years ago

Closed 9 years ago

#2869 closed enhancement (fixed)

St_Centroid doesn't work on curved geom

Reported by: remic Owned by: pramsey
Priority: medium Milestone: PostGIS 2.2.0
Component: postgis Version: 2.1.x
Keywords: Cc:

Description

When trying SELECT ST_AsText(ST_centroid(geom)) FROM st_geomfromtext('circularstring(0 0 , 1 1, 2 0)') as geom

Error is: ERROR: Exception in LWGEOM2GEOS: curved geometry not supported.

Centroid of such a curve would only be centroid(ST_DumpPoints(circularstring)) , so maybe easy to add?

Change History (4)

comment:1 by remic, 10 years ago

After some thinking : better define the centroid as the centroid of (point1, point3). Cheers, Rémi-C

comment:2 by remic, 10 years ago

Here is a wrapper , totally non optimal

DROP FUNCTION IF EXISTS public.rc_centroid( igeom GEOMETRY); CREATE OR REPLACE FUNCTION public.rc_centroid(

igeom GEOMETRY ) RETURNS GEOMETRY AS

$BODY$

—@brief : this function is a thin wrapper around st_centroid than enable to use it with circularstring —@param : a geom whose centroid we want —@return : teh centroid

DECLARE BEGIN

—RAISE EXCEPTION 'hello, % , %', st_astext(igeom), st_geometrytype(igeom) ;

IF ST_GeometryType(igeom) ILIKE '%CircularString%' THEN

—special case, we cast the circularstring to multipoint

RETURN ST_Centroid(ST_Collect(dmp.geom)) FROM ST_DumpPoints(igeom) as dmp WHERE dmp.path =ARRAY[1] OR dmp.path =ARRAY[3];

END IF ; —cicular string

RETURN ST_Centroid(igeom) ;

END ;

—test —SELECT ST_AsText(rc_centroid(geom )) —FROM st_geomfromtext('circularstring(0 0 , 1 1, 2 0)') as geom ;

$BODY$

LANGUAGE plpgsql IMMUTABLE STRICT;

comment:3 by pramsey, 10 years ago

Milestone: PostGIS 2.2.0

comment:4 by pramsey, 9 years ago

Resolution: fixed
Status: newclosed

Done at r13764

Note: See TracTickets for help on using tickets.