mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-24 17:12:35 +00:00
62203821fa
serialized_lwgeom_size lwgeom_size_subgeom lwgeom_size_point lwgeom_size_line lwgeom_size_circstring lwgeom_size_poly lwgeom_size_triangle lwgeom_deserialize lwpoint_deserialize lwline_deserialize lwpoly_deserialize lwtriangle_deserialize lwcircstring_deserialize lwmpoint_deserialize lwmline_deserialize lwmpoly_deserialize lwcollection_deserialize lwcompound_deserialize lwcurvepoly_deserialize lwmcurve_deserialize lwmsurface_deserialize lwpsurface_deserialize lwtin_deserialize printMULTI lwgeom_inspect lwgeom_getpoint_inspected lwgeom_getpoint lwgeom_getline_inspected lwgeom_getline lwgeom_getpoly lwgeom_getpoly_inspected lwgeom_gettriangle lwgeom_gettriangle_inspected lwgeom_getcircstring_inspected lwgeom_getgeom_inspected lwgeom_getsubgeometry lwgeom_getsubgeometry_inspected lwgeom_getsubtype lwgeom_getsubtype_inspected lwgeom_getnumgeometries lwgeom_getnumgeometries_inspected git-svn-id: http://svn.osgeo.org/postgis/trunk@8018 b70326c6-7e19-0410-871a-916f4a2858ee
136 lines
3.1 KiB
C
136 lines
3.1 KiB
C
/**********************************************************************
|
|
*
|
|
* PostGIS - Spatial Types for PostgreSQL
|
|
* http://postgis.refractions.net
|
|
*
|
|
* Copyright (C) 2001-2006 Refractions Research Inc.
|
|
*
|
|
* This is free software; you can redistribute and/or modify it under
|
|
* the terms of the GNU General Public Licence. See the COPYING file.
|
|
*
|
|
**********************************************************************/
|
|
|
|
/* basic LWCURVEPOLY manipulation */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "liblwgeom_internal.h"
|
|
#include "lwgeom_log.h"
|
|
|
|
|
|
LWCURVEPOLY *
|
|
lwcurvepoly_construct_empty(int srid, char hasz, char hasm)
|
|
{
|
|
LWCURVEPOLY *ret;
|
|
|
|
ret = lwalloc(sizeof(LWCURVEPOLY));
|
|
ret->type = CURVEPOLYTYPE;
|
|
ret->flags = gflags(hasz, hasm, 0);
|
|
ret->srid = srid;
|
|
ret->nrings = 0;
|
|
ret->maxrings = 1; /* Allocate room for sub-members, just in case. */
|
|
ret->rings = lwalloc(ret->maxrings * sizeof(LWGEOM*));
|
|
ret->bbox = NULL;
|
|
|
|
return ret;
|
|
}
|
|
|
|
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
|
|
{
|
|
int i;
|
|
|
|
/* Can't do anything with NULLs */
|
|
if( ! poly || ! ring )
|
|
{
|
|
LWDEBUG(4,"NULL inputs!!! quitting");
|
|
return LW_FAILURE;
|
|
}
|
|
|
|
/* Check that we're not working with garbage */
|
|
if ( poly->rings == NULL && (poly->nrings || poly->maxrings) )
|
|
{
|
|
LWDEBUG(4,"mismatched nrings/maxrings");
|
|
lwerror("Curvepolygon is in inconsistent state. Null memory but non-zero collection counts.");
|
|
}
|
|
|
|
/* Check that we're adding an allowed ring type */
|
|
if ( ! ( ring->type == LINETYPE || ring->type == CIRCSTRINGTYPE || ring->type == COMPOUNDTYPE ) )
|
|
{
|
|
LWDEBUGF(4,"got incorrect ring type: %s",lwtype_name(ring->type));
|
|
return LW_FAILURE;
|
|
}
|
|
|
|
|
|
/* In case this is a truly empty, make some initial space */
|
|
if ( poly->rings == NULL )
|
|
{
|
|
poly->maxrings = 2;
|
|
poly->nrings = 0;
|
|
poly->rings = lwalloc(poly->maxrings * sizeof(LWGEOM*));
|
|
}
|
|
|
|
/* Allocate more space if we need it */
|
|
if ( poly->nrings == poly->maxrings )
|
|
{
|
|
poly->maxrings *= 2;
|
|
poly->rings = lwrealloc(poly->rings, sizeof(LWGEOM*) * poly->maxrings);
|
|
}
|
|
|
|
/* Make sure we don't already have a reference to this geom */
|
|
for ( i = 0; i < poly->nrings; i++ )
|
|
{
|
|
if ( poly->rings[i] == ring )
|
|
{
|
|
LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", poly->rings[i], ring);
|
|
return LW_SUCCESS;
|
|
}
|
|
}
|
|
|
|
/* Add the ring and increment the ring count */
|
|
poly->rings[poly->nrings] = (LWGEOM*)ring;
|
|
poly->nrings++;
|
|
return LW_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* This should be rewritten to make use of the curve itself.
|
|
*/
|
|
double
|
|
lwcurvepoly_area(const LWCURVEPOLY *curvepoly)
|
|
{
|
|
double area = 0.0;
|
|
LWPOLY *poly;
|
|
if( lwgeom_is_empty((LWGEOM*)curvepoly) )
|
|
return 0.0;
|
|
poly = lwcurvepoly_segmentize(curvepoly, 32);
|
|
area = lwpoly_area(poly);
|
|
lwpoly_free(poly);
|
|
return area;
|
|
}
|
|
|
|
|
|
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
|
|
lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
|
|
{
|
|
double result=0.0;
|
|
int i;
|
|
|
|
for (i=0; i<poly->nrings; i++)
|
|
result += lwgeom_length_2d(poly->rings[i]);
|
|
|
|
return result;
|
|
}
|