]> granicus.if.org Git - postgis/commitdiff
Added LWGEOM_construct() function to easy the work of dealing
authorSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 14:47:25 +0000 (14:47 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 14:47:25 +0000 (14:47 +0000)
with SRID/BBOX optional embedding.

git-svn-id: http://svn.osgeo.org/postgis/trunk@735 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom.h
lwgeom/lwgeom_api.c

index b56d0dafcf5b40af3d9184146ec4c714af31634a..1013b27355a544db169b405e9fcd2e887e1b5c73 100644 (file)
@@ -179,6 +179,17 @@ extern int  lwgeom_getType(unsigned char type); // returns the tttt value
 extern unsigned char lwgeom_makeType(int ndims, char hasSRID, int type);
 extern unsigned char lwgeom_makeType_full(int ndims, char hasSRID, int type, bool hasBBOX);
 
+/*
+ * Construct a full LWGEOM type (including size header)
+ * from a serialized form.
+ * The constructed LWGEOM object will be allocated using palloc
+ * and the serialized form will be copied.
+ * If you specify a SRID other then -1 it will be set.
+ * If you request bbox (wantbbox=1) it will be extracted or computed
+ * from the serialized form.
+ */
+extern LWGEOM *LWGEOM_construct(char *serialized, int SRID, int wantbbox);
+
 // all the base types (point/line/polygon) will have a
 // basic constructor, basic de-serializer, basic serializer, and
 // bounding box finder.
index f6a8184b0236dd62cc79bdc5c96205ab55c8a8e7..a61db323c7b262771ad852ccaf29ae24156a1a6d 100644 (file)
@@ -2382,3 +2382,61 @@ LWGEOM *lwgeom_setSRID(LWGEOM *lwgeom, int32 newSRID)
        }
        return result;
 }
+
+LWGEOM *
+LWGEOM_construct(char *ser, int SRID, int wantbbox)
+{
+       int size;
+       char *iptr, *optr, *eptr;
+       int wantsrid = 0;
+       BOX2DFLOAT4 box;
+       LWGEOM *result;
+
+       size = lwgeom_seralizedformlength_simple(ser);
+       eptr = ser+size; // end of subgeom
+
+       iptr = ser+1; // skip type
+       if ( lwgeom_hasSRID(ser[0]) )
+       {
+               iptr += 4; // skip SRID
+               size -= 4;
+       }
+       if ( lwgeom_hasBBOX(ser[0]) )
+       {
+               iptr += sizeof(BOX2DFLOAT4); // skip BBOX
+               size -= sizeof(BOX2DFLOAT4);
+       }
+
+       if ( SRID != -1 )
+       {
+               wantsrid = 1;
+               size += 4;
+       }
+       if ( wantbbox )
+       {
+               size += sizeof(BOX2DFLOAT4);
+               getbox2d_p(ser, &box);
+       }
+
+       size+=4; // size header
+
+       result = palloc(size);
+       result->size = size;
+
+       result->type = lwgeom_makeType_full(lwgeom_ndims(ser[0]),
+               wantsrid, lwgeom_getType(ser[0]), wantbbox);
+       optr = result->data;
+       if ( wantbbox )
+       {
+               memcpy(optr, &box, sizeof(BOX2DFLOAT4));
+               optr += sizeof(BOX2DFLOAT4);
+       }
+       if ( wantsrid )
+       {
+               memcpy(optr, &SRID, 4);
+               optr += 4;
+       }
+       memcpy(optr, iptr, eptr-iptr);
+
+       return result;
+}