double lwcurvepoly_perimeter(const LWCURVEPOLY *poly) { double result=0.0; int i; for (i=0; i<poly->nrings; i++) result += lwgeom_length(poly->rings[i]); return result; }
double lwgeom_length(const LWGEOM *geom) { int type = geom->type; if ( type == LINETYPE ) return lwline_length((LWLINE*)geom); else if ( type == CIRCSTRINGTYPE ) return lwcircstring_length((LWCIRCSTRING*)geom); else if ( type == COMPOUNDTYPE ) return lwcompound_length((LWCOMPOUND*)geom); else if ( lwgeom_is_collection(geom) ) { double length = 0.0; int i; LWCOLLECTION *col = (LWCOLLECTION*)geom; for ( i = 0; i < col->ngeoms; i++ ) length += lwgeom_length(col->geoms[i]); return length; } else return 0.0; }