Index: src/gaiageo/gg_wkb.c ================================================================== --- src/gaiageo/gg_wkb.c +++ src/gaiageo/gg_wkb.c @@ -56,10 +56,14 @@ #endif #include #include + +#ifdef ENABLE_GEOPACKAGE +#include +#endif static void ParseWkbPoint (gaiaGeomCollPtr geo) { /* decodes a POINT from WKB */ @@ -1076,14 +1080,26 @@ /* decoding from SpatiaLite BLOB to GEOMETRY */ int type; int little_endian; int endian_arch = gaiaEndianArch (); gaiaGeomCollPtr geo = NULL; +#ifdef ENABLE_GEOPACKAGE + if (size < 24) + return NULL; /* cannot be spatialite or geopackage blob */ + if (*(blob + 0) != GAIA_MARK_START) + { + /* Try geopackage binary, since it is not a standard spatialite blob */ + return gaiaFromGeoPackageGeometryBlob(blob, size); + } + if (size < 45) + return NULL; /* cannot be an internal BLOB WKB geometry */ +#else if (size < 45) return NULL; /* cannot be an internal BLOB WKB geometry */ if (*(blob + 0) != GAIA_MARK_START) return NULL; /* failed to recognize START signature */ +#endif if (*(blob + (size - 1)) != GAIA_MARK_END) return NULL; /* failed to recognize END signature */ if (*(blob + 38) != GAIA_MARK_MBR) return NULL; /* failed to recognize MBR signature */ if (*(blob + 1) == GAIA_LITTLE_ENDIAN) Index: src/headers/spatialite/geopackage.h ================================================================== --- src/headers/spatialite/geopackage.h +++ src/headers/spatialite/geopackage.h @@ -61,10 +61,11 @@ #ifdef __cplusplus extern "C" { #endif +#include /* Internal geopackage SQL function implementation */ GEOPACKAGE_DECLARE void fnct_gpkgCreateBaseTables (sqlite3_context * context, int argc, sqlite3_value ** argv); @@ -123,10 +124,13 @@ GEOPACKAGE_DECLARE void fnct_ToGPB (sqlite3_context * context, int argc, sqlite3_value ** argv); GEOPACKAGE_DECLARE void fnct_GeomFromGPB (sqlite3_context * context, int argc, sqlite3_value ** argv); + + GEOPACKAGE_DECLARE gaiaGeomCollPtr gaiaFromGeoPackageGeometryBlob (const unsigned char *gpb, + unsigned int gpb_len); /* Markers for unused arguments / variable */ #if __GNUC__ #define UNUSED __attribute__ ((__unused__)) #else ADDED test/sql_stmt_geopackage_tests/implicitgeopackagebinary1.testcase Index: test/sql_stmt_geopackage_tests/implicitgeopackagebinary1.testcase ================================================================== --- test/sql_stmt_geopackage_tests/implicitgeopackagebinary1.testcase +++ test/sql_stmt_geopackage_tests/implicitgeopackagebinary1.testcase @@ -0,0 +1,7 @@ +implicit geopackage binary 1 +:memory: #use in-memory database +SELECT Hex(CastToLineString(AsGPB(GeomFromText("LINESTRING(136 -35, 134 -33, 135 -32)", 4326)))) +1 # rows (not including the header row) +1 # columns +Hex(CastToLineString(AsGPB(GeomFromText("LINESTRING(136 -35, 134 -33, 135 -32)", 4326)))) +0001E61000000000000000C0604000000000008041C0000000000000614000000000000040C07C0200000003000000000000000000614000000000008041C00000000000C0604000000000008040C00000000000E0604000000000000040C0FE