]> granicus.if.org Git - postgis/commitdiff
Added wrappers for ewkb output
authorSandro Santilli <strk@keybit.net>
Fri, 23 Sep 2005 16:43:56 +0000 (16:43 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 23 Sep 2005 16:43:56 +0000 (16:43 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1926 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/liblwgeom.h
lwgeom/lwgeom.c
lwgeom/lwgeom.h
lwgeom/lwgeom_api.c

index c7601e5dc8e7e4e7ebb66edc24a64c6dff819de0..b30258ddbe6c0b2f0d8d46de85448e94b08966b8 100644 (file)
@@ -677,8 +677,6 @@ extern int pglwgeom_getSRID(PG_LWGEOM *lwgeom);
 extern int lwgeom_getsrid(uchar *serialized);
 extern PG_LWGEOM *pglwgeom_setSRID(PG_LWGEOM *lwgeom, int32 newSRID);
 
-extern PG_LWGEOM *pglwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
-
 
 //------------------------------------------------------
 // other stuff
@@ -1021,8 +1019,13 @@ extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist);
 extern uchar parse_hex(char *str);
 extern void deparse_hex(uchar str, uchar *result);
 extern uchar *parse_lwgeom_wkt(char *wkt_input);
+
 extern char *lwgeom_to_ewkt(LWGEOM *lwgeom);
 extern char *lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder);
+extern LWGEOM *lwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
+extern uchar *lwgeom_to_ewkb(LWGEOM *lwgeom, char byteorder, size_t *ewkblen);
+extern PG_LWGEOM *pglwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
+extern char *pglwgeom_to_ewkb(PG_LWGEOM *geom, char byteorder, size_t *ewkblen);
 
 extern void *lwalloc(size_t size);
 extern void *lwrealloc(void *mem, size_t size);
index 29d634500c8bd91289496035286a063e90b7e967..8267f10f86c3d0fde2d9ebe7b067e21c9570f79c 100644 (file)
@@ -387,6 +387,27 @@ lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder)
        return hexwkb;
 }
 
+/*
+ * Return an alloced string
+ */
+uchar *
+lwgeom_to_ewkb(LWGEOM *lwgeom, char byteorder, size_t *outsize)
+{
+       uchar *serialized = lwgeom_serialize(lwgeom);
+       char *hexwkb = unparse_WKB(serialized, lwalloc, lwfree,
+               byteorder, outsize, 0);
+       lwfree(serialized);
+       return hexwkb;
+}
+
+LWGEOM *
+lwgeom_from_ewkb(uchar *ewkb, size_t size)
+{
+       uchar *pglwgeom = (uchar *)pglwgeom_from_ewkb(ewkb, size);
+       LWGEOM *ret = lwgeom_deserialize(pglwgeom+4);
+       return ret;
+}
+
 // geom1 same as geom2
 //  iff
 //      + have same type                                                        //      + have same # objects
index b5384b085da1e412d5f158f95b660921fbd0418a..91574f3634020c7f07362214ef31c55163b3b562 100644 (file)
@@ -33,6 +33,8 @@ typedef struct LWGEOM_T *LWGEOM;
 extern char *lwgeom_to_wkt(LWGEOM lwgeom);
 extern char *lwgeom_to_ewkt(LWGEOM lwgeom);
 extern char *lwgeom_to_hexwkb(LWGEOM lwgeom, unsigned int byteorder);
+extern uchar *lwgeom_to_ewkb(char *ewkb, size_t size);
+extern LWGEOM lwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
 
 // Construction
 extern LWGEOM make_lwpoint2d(int SRID, double x, double y);
index 5394d7349774c12df46a59144a00c8d11632b840..b82142be5d279aa33f68c15a1ddda19cb58d6c8d 100644 (file)
@@ -6,13 +6,14 @@
 #include <errno.h>
 
 #include "liblwgeom.h"
+#include "wktparse.h"
 
 //#define PGIS_DEBUG 1
 
 // This is an implementation of the functions defined in lwgeom.h
 
 //forward decs
-extern uchar *parse_lwg(const char* geometry, lwallocator allocfunc, lwreporter errfunc);
+//extern uchar *parse_lwg(const char* geometry, lwallocator allocfunc, lwreporter errfunc);
 
 //*********************************************************************
 // BOX routines
@@ -1675,6 +1676,17 @@ pglwgeom_from_ewkb(uchar *ewkb, size_t ewkblen)
        return ret;
 }
 
+/*
+ * Return the EWKB (binary) representation for a PG_LWGEOM.
+ */
+char *
+pglwgeom_to_ewkb(PG_LWGEOM *geom, char byteorder, size_t *outsize)
+{
+       uchar *srl = &(geom->type);
+       return unparse_WKB(srl, lwalloc, lwfree,
+               byteorder, outsize, 0);
+}
+
 // Set the SRID of a PG_LWGEOM
 // Returns a newly allocated PG_LWGEOM object.
 // Allocation will be done using the lwalloc.