]> granicus.if.org Git - postgis/commitdiff
Canonical binary reverted back to EWKB, now supporting SRID inclusion.
authorSandro Santilli <strk@keybit.net>
Tue, 21 Dec 2004 15:19:01 +0000 (15:19 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 21 Dec 2004 15:19:01 +0000 (15:19 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1174 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_inout.c
lwgeom/lwgparse.c
lwgeom/wktunparse.c

index ad0278a3777209703a78228a4b0aee882620bfb2..0e7699aa75fbc2cab7e5503a8e45119779675543 100644 (file)
@@ -155,70 +155,6 @@ Datum LWGEOM_to_text(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(text_result);
 }
 
-//
-// LWGEOM_to_bytea(LWGEOM)
-// bytea contains canonical binary form, being
-// internal representation with additional byte containing 
-// byte order
-//
-PG_FUNCTION_INFO_V1(LWGEOM_to_bytea);
-Datum LWGEOM_to_bytea(PG_FUNCTION_ARGS)
-{
-       bytea *ret;
-       PG_LWGEOM *pglwg;
-
-       pglwg = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-
-       ret = (bytea *)palloc(pglwg->size+5);
-       VARATT_SIZEP(ret) = pglwg->size+1;
-       *(VARDATA(ret)) = getMachineEndian();
-       memcpy((void *)(VARDATA(ret)+1), SERIALIZED_FORM(pglwg),
-               pglwg->size-4);
-
-#if DEBUG
-       elog(NOTICE, "LWGEOM_to_bytea returning %d bytes (machine endian: %d)",
-               VARSIZE(ret), getMachineEndian());
-#endif
-
-       PG_RETURN_POINTER(ret);
-}
-
-// LWGEOM_from_bytea(bytea)
-// bytea contains canonical binary form, being
-// internal representation with additional byte containing 
-// byte order
-//
-PG_FUNCTION_INFO_V1(LWGEOM_from_bytea);
-Datum LWGEOM_from_bytea(PG_FUNCTION_ARGS)
-{
-       bytea *in;
-       PG_LWGEOM *ret;
-       char flipbytes=0;
-
-       in = (bytea *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-
-       ret = (PG_LWGEOM *)palloc(VARSIZE(in)-1);
-       ret->size = VARSIZE(in)-1;
-
-       if ( *(VARDATA(in)) != getMachineEndian() ) flipbytes = 1;
-       if ( flipbytes )
-       {
-               elog(ERROR, "Unable to handle bytes flipping");
-               PG_RETURN_NULL();
-       }
-       else
-       {
-               memcpy(SERIALIZED_FORM(ret), VARDATA(in)+1, VARSIZE(in)-5);
-       }
-
-#if DEBUG
-       elog(NOTICE, "LWGEOM_from_bytea returning %d bytes", ret->size);
-#endif
-
-       PG_RETURN_POINTER(ret);
-}
-
-
 // LWGEOMFromWKB(wkb,  [SRID] )
 // NOTE: wkb is in *binary* not hex form.
 //
@@ -528,7 +464,7 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
 
        /* Call LWGEOM_from_bytea function... */
        result = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1(
-               LWGEOM_from_bytea, PointerGetDatum(wkb)));
+               LWGEOMFromWKB, PointerGetDatum(wkb)));
 
 #ifdef DEBUG
        elog(NOTICE, "LWGEOM_recv advancing StringInfo buffer");
@@ -552,14 +488,44 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_send);
 Datum LWGEOM_send(PG_FUNCTION_ARGS)
 {
-       PG_LWGEOM *result;
+       bytea *result;
 
 #ifdef DEBUG
        elog(NOTICE, "LWGEOM_send called");
 #endif
 
+       result = (bytea *)DatumGetPointer(DirectFunctionCall1(
+               WKBFromLWGEOM, PG_GETARG_DATUM(0)));
+
+        PG_RETURN_POINTER(result);
+}
+
+PG_FUNCTION_INFO_V1(LWGEOM_to_bytea);
+Datum LWGEOM_to_bytea(PG_FUNCTION_ARGS)
+{
+       bytea *result;
+
+#ifdef DEBUG
+       elog(NOTICE, "LWGEOM_to_bytea called");
+#endif
+
+       result = (bytea *)DatumGetPointer(DirectFunctionCall1(
+               WKBFromLWGEOM, PG_GETARG_DATUM(0)));
+
+        PG_RETURN_POINTER(result);
+}
+
+PG_FUNCTION_INFO_V1(LWGEOM_from_bytea);
+Datum LWGEOM_from_bytea(PG_FUNCTION_ARGS)
+{
+       PG_LWGEOM *result;
+
+#ifdef DEBUG
+       elog(NOTICE, "LWGEOM_from_bytea start");
+#endif
+
        result = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1(
-               LWGEOM_to_bytea, PG_GETARG_DATUM(0)));
+               LWGEOMFromWKB, PG_GETARG_DATUM(0)));
 
         PG_RETURN_POINTER(result);
 }
index 6947ef5fa07f131c8e2b185b207435464087adac..61d9a43802fdba16783df565e46ea0df94311558 100644 (file)
@@ -738,6 +738,7 @@ parse_wkb(const char** b)
        int4 type;
        byte xdr = read_wkb_byte(b);
        swap_order=0;
+       int4 localsrid;
 
        if ( xdr != getMachineEndian() )
        {
@@ -765,8 +766,13 @@ parse_wkb(const char** b)
 
        if (type & WKBSRIDFLAG )
        {
-               the_geom.hasZ = 1;
-               the_geom.ndims++;
+               // local (in-EWKB) srid spec overrides SRID=#; 
+               localsrid = read_wkb_int(b);
+               if ( localsrid != -1 )
+               {
+                       if ( the_geom.srid == -1 ) the_geom.alloc_size += 4;
+                       the_geom.srid = localsrid;
+               }
        }
 
        type &=0x0f;
index 6e6a3384a5e8bc3cb176596c9ac73b001416e4ea..a2ff9b431ad41886e71f3ea6a80ab76388dccd6f 100644 (file)
@@ -444,12 +444,6 @@ output_wkb(byte* geom)
                geom+=16;
        }
 
-       if ( TYPE_HASSRID(type) ) {
-               write_str("SRID=");
-               write_int(read_int(&geom));
-               write_str(";");
-       }
-
        //type&=0x0f;
        wkbtype = TYPE_GETTYPE(type); 
 
@@ -457,12 +451,20 @@ output_wkb(byte* geom)
                 wkbtype |= WKBZOFFSET;
        if ( TYPE_HASM(type) )
                 wkbtype |= WKBMOFFSET;
+       if ( TYPE_HASSRID(type) ) {
+               wkbtype |= WKBSRIDFLAG;
+       }
+
 
        // Write byteorder (as from WKB specs...)
        write_wkb_bytes(&endianbyte,1,1);
 
        write_wkb_int(wkbtype);
 
+       if ( TYPE_HASSRID(type) ) {
+               write_wkb_int(read_int(&geom));
+       }
+
        switch(TYPE_GETTYPE(type)){
                case POINTTYPE:
                        geom=output_wkb_point(geom);
@@ -543,6 +545,9 @@ unparse_WKB(byte* serialized, allocator alloc, freeor free, char endian)
 
 /******************************************************************
  * $Log$
+ * Revision 1.15  2004/12/21 15:19:01  strk
+ * Canonical binary reverted back to EWKB, now supporting SRID inclusion.
+ *
  * Revision 1.14  2004/12/17 11:08:53  strk
  * Moved getMachineEndian from parser to liblwgeom.{h,c}.
  * Added XDR and NDR defines.