1
/**********************************************************************
2
* $Id: lwmline.c 2369 2006-05-30 08:38:58Z strk $
4
* PostGIS - Spatial Types for PostgreSQL
5
* http://postgis.refractions.net
6
* Copyright 2001-2006 Refractions Research Inc.
8
* This is free software; you can redistribute and/or modify it under
9
* the terms of the GNU General Public Licence. See the COPYING file.
11
**********************************************************************/
16
#include "liblwgeom.h"
19
lwmline_deserialize(uchar *srl)
22
LWGEOM_INSPECTED *insp;
23
int type = lwgeom_getType(srl[0]);
26
if ( type != MULTILINETYPE )
28
lwerror("lwmline_deserialize called on NON multiline: %d",
33
insp = lwgeom_inspect(srl);
35
result = lwalloc(sizeof(LWMLINE));
36
result->type = insp->type;
37
result->SRID = insp->SRID;
38
result->ngeoms = insp->ngeometries;
39
result->geoms = lwalloc(sizeof(LWLINE *)*insp->ngeometries);
41
if (lwgeom_hasBBOX(srl[0]))
43
result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
44
memcpy(result->bbox, srl+1, sizeof(BOX2DFLOAT4));
46
else result->bbox = NULL;
49
for (i=0; i<insp->ngeometries; i++)
51
result->geoms[i] = lwline_deserialize(insp->sub_geoms[i]);
52
if ( TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type) )
54
lwerror("Mixed dimensions (multiline:%d, line%d:%d)",
55
TYPE_NDIMS(result->type), i,
56
TYPE_NDIMS(result->geoms[i]->type)
66
* Add 'what' to this multiline at position 'where'.
69
* Returns a MULTILINE or a COLLECTION
72
lwmline_add(const LWMLINE *to, uint32 where, const LWGEOM *what)
79
if ( where == -1 ) where = to->ngeoms;
80
else if ( where < -1 || where > to->ngeoms )
82
lwerror("lwmline_add: add position out of range %d..%d",
87
/* dimensions compatibility are checked by caller */
89
/* Construct geoms array */
90
geoms = lwalloc(sizeof(LWGEOM *)*(to->ngeoms+1));
91
for (i=0; i<where; i++)
93
geoms[i] = lwgeom_clone((LWGEOM *)to->geoms[i]);
95
geoms[where] = lwgeom_clone(what);
96
for (i=where; i<to->ngeoms; i++)
98
geoms[i+1] = lwgeom_clone((LWGEOM *)to->geoms[i]);
101
if ( TYPE_GETTYPE(what->type) == LINETYPE ) newtype = MULTILINETYPE;
102
else newtype = COLLECTIONTYPE;
104
col = lwcollection_construct(newtype,
106
to->ngeoms+1, geoms);
108
return (LWGEOM *)col;