2006-05-30 08:38:58 +00:00
|
|
|
/**********************************************************************
|
2009-02-04 00:28:37 +00:00
|
|
|
* $Id$
|
2006-05-30 08:38:58 +00:00
|
|
|
*
|
|
|
|
* PostGIS - Spatial Types for PostgreSQL
|
|
|
|
* http://postgis.refractions.net
|
|
|
|
* Copyright 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.
|
2009-06-11 16:44:03 +00:00
|
|
|
*
|
2006-05-30 08:38:58 +00:00
|
|
|
**********************************************************************/
|
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-09-29 15:25:21 +00:00
|
|
|
#include <string.h>
|
2004-09-29 10:50:30 +00:00
|
|
|
#include "liblwgeom.h"
|
|
|
|
|
2004-09-30 08:18:06 +00:00
|
|
|
|
2009-01-08 17:04:00 +00:00
|
|
|
void
|
|
|
|
lwmpoly_release(LWMPOLY *lwmpoly)
|
|
|
|
{
|
2009-06-11 16:44:03 +00:00
|
|
|
lwgeom_release(lwmpoly_as_lwgeom(lwmpoly));
|
2009-01-08 17:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 03:13:33 +00:00
|
|
|
LWMPOLY *
|
|
|
|
lwmpoly_construct_empty(int srid, char hasz, char hasm)
|
|
|
|
{
|
|
|
|
LWMPOLY *ret = (LWMPOLY*)lwcollection_construct_empty(srid, hasz, hasm);
|
|
|
|
TYPE_SETTYPE(ret->type, MULTIPOLYGONTYPE);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-01-08 17:04:00 +00:00
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
LWMPOLY *
|
2005-02-10 10:52:53 +00:00
|
|
|
lwmpoly_deserialize(uchar *srl)
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
|
|
|
LWMPOLY *result;
|
|
|
|
LWGEOM_INSPECTED *insp;
|
|
|
|
int type = lwgeom_getType(srl[0]);
|
|
|
|
int i;
|
|
|
|
|
2008-05-31 09:56:44 +00:00
|
|
|
LWDEBUG(2, "lwmpoly_deserialize called");
|
2004-09-30 08:18:06 +00:00
|
|
|
|
2009-06-11 16:44:03 +00:00
|
|
|
if ( type != MULTIPOLYGONTYPE )
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
|
|
|
lwerror("lwmpoly_deserialize called on NON multipoly: %d",
|
2009-06-11 16:44:03 +00:00
|
|
|
type);
|
2004-09-29 10:50:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
insp = lwgeom_inspect(srl);
|
|
|
|
|
|
|
|
result = lwalloc(sizeof(LWMPOLY));
|
2004-10-04 13:53:42 +00:00
|
|
|
result->type = insp->type;
|
2004-09-29 10:50:30 +00:00
|
|
|
result->SRID = insp->SRID;
|
2004-09-30 08:18:06 +00:00
|
|
|
result->ngeoms = insp->ngeometries;
|
2010-02-01 17:35:55 +00:00
|
|
|
|
|
|
|
if ( insp->ngeometries )
|
2010-01-04 17:55:14 +00:00
|
|
|
{
|
|
|
|
result->geoms = lwalloc(sizeof(LWPOLY *)*insp->ngeometries);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->geoms = NULL;
|
|
|
|
}
|
2004-09-29 10:50:30 +00:00
|
|
|
|
2004-10-08 13:20:55 +00:00
|
|
|
if (lwgeom_hasBBOX(srl[0]))
|
2005-11-14 09:01:15 +00:00
|
|
|
{
|
|
|
|
result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
|
|
|
|
memcpy(result->bbox, srl+1, sizeof(BOX2DFLOAT4));
|
|
|
|
}
|
2004-10-08 13:20:55 +00:00
|
|
|
else result->bbox = NULL;
|
|
|
|
|
2004-09-29 10:50:30 +00:00
|
|
|
for (i=0; i<insp->ngeometries; i++)
|
|
|
|
{
|
2004-09-30 08:18:06 +00:00
|
|
|
result->geoms[i] = lwpoly_deserialize(insp->sub_geoms[i]);
|
2004-10-04 13:53:42 +00:00
|
|
|
if ( TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type) )
|
2004-09-29 10:50:30 +00:00
|
|
|
{
|
|
|
|
lwerror("Mixed dimensions (multipoly:%d, poly%d:%d)",
|
2009-06-11 16:44:03 +00:00
|
|
|
TYPE_NDIMS(result->type), i,
|
|
|
|
TYPE_NDIMS(result->geoms[i]->type)
|
|
|
|
);
|
2004-09-29 10:50:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-16 03:13:33 +00:00
|
|
|
LWMPOLY* lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
|
2004-10-01 14:49:34 +00:00
|
|
|
{
|
2010-03-16 03:13:33 +00:00
|
|
|
return (LWMPOLY*)lwcollection_add_lwgeom((LWCOLLECTION*)mobj, (LWGEOM*)obj);
|
2004-10-01 14:49:34 +00:00
|
|
|
}
|
2008-12-19 19:20:34 +00:00
|
|
|
|
2010-03-16 03:13:33 +00:00
|
|
|
|
2009-06-11 16:44:03 +00:00
|
|
|
void lwmpoly_free(LWMPOLY *mpoly)
|
2008-12-19 19:20:34 +00:00
|
|
|
{
|
|
|
|
int i;
|
2009-06-11 16:44:03 +00:00
|
|
|
if ( mpoly->bbox )
|
2008-12-19 19:20:34 +00:00
|
|
|
{
|
|
|
|
lwfree(mpoly->bbox);
|
|
|
|
}
|
2009-06-11 16:44:03 +00:00
|
|
|
for ( i = 0; i < mpoly->ngeoms; i++ )
|
2008-12-19 19:20:34 +00:00
|
|
|
{
|
2009-06-11 16:44:03 +00:00
|
|
|
if ( mpoly->geoms[i] )
|
|
|
|
{
|
2009-01-09 17:41:23 +00:00
|
|
|
lwpoly_free(mpoly->geoms[i]);
|
2008-12-19 19:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-11 16:44:03 +00:00
|
|
|
if ( mpoly->geoms )
|
2008-12-19 19:20:34 +00:00
|
|
|
{
|
|
|
|
lwfree(mpoly->geoms);
|
|
|
|
}
|
|
|
|
lwfree(mpoly);
|
2009-06-11 16:44:03 +00:00
|
|
|
|
2009-12-20 17:42:44 +00:00
|
|
|
}
|
2009-01-12 19:29:57 +00:00
|
|
|
|