]> granicus.if.org Git - postgis/commitdiff
Made setSRID(geom, -1) actually *remove* srid from LWGEOM.
authorSandro Santilli <strk@keybit.net>
Tue, 21 Dec 2004 15:17:30 +0000 (15:17 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 21 Dec 2004 15:17:30 +0000 (15:17 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1173 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_api.c

index 1c9da6544c729d9dfec70057f85fa48a327adb9f..2cfa3eb64e3d3f1f3437d64678ea2fda0a329b0c 100644 (file)
@@ -1750,42 +1750,77 @@ lwgeom_setSRID(PG_LWGEOM *lwgeom, int32 newSRID)
 
        if (lwgeom_hasSRID(type))
        {
-               //we create a new one and copy the SRID in
-               result = lwalloc(len);
-               memcpy(result, lwgeom, len);
-               memcpy(result->data+bbox_offset, &newSRID,4);
+               if ( newSRID != -1 ) {
+                       //we create a new one and copy the SRID in
+                       result = lwalloc(len);
+                       memcpy(result, lwgeom, len);
+                       memcpy(result->data+bbox_offset, &newSRID,4);
+               } else {
+                       //we create a new one dropping the SRID
+                       result = lwalloc(len-4);
+                       result->size = len-4;
+                       result->type = lwgeom_makeType_full(
+                               TYPE_HASZ(type), TYPE_HASM(type),
+                               0, lwgeom_getType(type),
+                               lwgeom_hasBBOX(type));
+                       loc_new = result->data;
+                       loc_old = lwgeom->data;
+                       len_left = len-4-1;
+
+                       // handle bbox (if there)
+                       if (lwgeom_hasBBOX(type))
+                       {
+                               memcpy(loc_new, loc_old, sizeof(BOX2DFLOAT4));
+                               loc_new += sizeof(BOX2DFLOAT4);
+                               loc_old += sizeof(BOX2DFLOAT4);
+                               len_left -= sizeof(BOX2DFLOAT4);
+                       }
+
+                       // skip SRID, copy the remaining
+                       loc_old += 4;
+                       len_left -= 4;
+                       memcpy(loc_new, loc_old, len_left);
+
+               }
+
        }
-       else  // need to add one
+       else 
        {
-               len_new = len + 4;//+4 for SRID
-               result = lwalloc(len_new);
-               memcpy(result, &len_new, 4); // size copy in
-               result->type = lwgeom_makeType_full(
-                       TYPE_HASZ(type), TYPE_HASM(type),
-                       1, lwgeom_getType(type),lwgeom_hasBBOX(type));
-
-               loc_new = result->data;
-               loc_old = lwgeom->data;
+               // just copy input, already w/out a SRID
+               if ( newSRID == -1 ) {
+                       result = lwalloc(len);
+                       memcpy(result, lwgeom, len);
+               }
+               // need to add one
+               else {
+                       len_new = len + 4;//+4 for SRID
+                       result = lwalloc(len_new);
+                       memcpy(result, &len_new, 4); // size copy in
+                       result->type = lwgeom_makeType_full(
+                               TYPE_HASZ(type), TYPE_HASM(type),
+                               1, lwgeom_getType(type),lwgeom_hasBBOX(type));
 
-               len_left = len -4-1;// old length - size - type
+                       loc_new = result->data;
+                       loc_old = lwgeom->data;
 
-               // handle bbox (if there)
+                       len_left = len -4-1;// old length - size - type
 
-               if (lwgeom_hasBBOX(type))
-               {
-                       memcpy(loc_new, loc_old, sizeof(BOX2DFLOAT4)) ;//copy in bbox
-                       loc_new += sizeof(BOX2DFLOAT4);
-                       loc_old += sizeof(BOX2DFLOAT4);
-                       len_left -= sizeof(BOX2DFLOAT4);
-               }
+                       // handle bbox (if there)
 
-               //put in SRID
+                       if (lwgeom_hasBBOX(type))
+                       {
+                               memcpy(loc_new, loc_old, sizeof(BOX2DFLOAT4)) ;//copy in bbox
+                               loc_new += sizeof(BOX2DFLOAT4);
+                               loc_old += sizeof(BOX2DFLOAT4);
+                               len_left -= sizeof(BOX2DFLOAT4);
+                       }
 
-               memcpy(loc_new, &newSRID,4);
-               loc_new +=4;
-               memcpy(loc_new, loc_old, len_left);
+                       //put in SRID
 
-               // TODO: add SRID presence flag in type.
+                       memcpy(loc_new, &newSRID,4);
+                       loc_new +=4;
+                       memcpy(loc_new, loc_old, len_left);
+               }
        }
        return result;
 }