Check-in Differences
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From 58849a0a8fd61b31 To 7f691c1e017837c1

2014-01-02
00:33
Remove point_to_tile functionality - no longer required by spec, and broken.

Also add missing gpkgBinary.c file. check-in: 89cec81bcc user: bradh tags: trunk

2014-01-01
10:29
Expose gaiaFromGeoPackageGeometryBlob function and use it as a fallback if we can't parse as spatialite geometry.

Also adds test. check-in: 7f691c1e01 user: bradh tags: trunk

06:24
Implement GeomFromGPB() and test cases. check-in: 58849a0a8f user: bradh tags: trunk
01:39
Add geopackage output geometry support (AsGPB() SQL function), based on existing WKB output. check-in: d26839b4fd user: bradh tags: trunk

Changes to src/gaiageo/gg_wkb.c.

54
55
56
57
58
59
60




61
62
63
64
65
66
67
....
1074
1075
1076
1077
1078
1079
1080











1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
#else
#include "config.h"
#endif

#include <spatialite/sqlite.h>

#include <spatialite/gaiageo.h>





static void
ParseWkbPoint (gaiaGeomCollPtr geo)
{
/* decodes a POINT from WKB */
    double x;
    double y;
................................................................................
gaiaFromSpatiaLiteBlobWkb (const unsigned char *blob, unsigned int size)
{
/* decoding from SpatiaLite BLOB to GEOMETRY */
    int type;
    int little_endian;
    int endian_arch = gaiaEndianArch ();
    gaiaGeomCollPtr geo = NULL;











    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 */

    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)
	little_endian = 1;
    else if (*(blob + 1) == GAIA_BIG_ENDIAN)







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>




>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
....
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
#else
#include "config.h"
#endif

#include <spatialite/sqlite.h>

#include <spatialite/gaiageo.h>

#ifdef ENABLE_GEOPACKAGE
#include <spatialite/geopackage.h>
#endif

static void
ParseWkbPoint (gaiaGeomCollPtr geo)
{
/* decodes a POINT from WKB */
    double x;
    double y;
................................................................................
gaiaFromSpatiaLiteBlobWkb (const unsigned char *blob, unsigned int size)
{
/* 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)
	little_endian = 1;
    else if (*(blob + 1) == GAIA_BIG_ENDIAN)

Changes to src/headers/spatialite/geopackage.h.

59
60
61
62
63
64
65

66
67
68
69
70
71
72
...
121
122
123
124
125
126
127



128
129
130
131
132
133
134
135
136
137
138
139
140
#include "sqlite.h"

#ifdef __cplusplus
extern "C"
{
#endif



/* Internal geopackage SQL function implementation */
    GEOPACKAGE_DECLARE void fnct_gpkgCreateBaseTables (sqlite3_context *
						       context, int argc,
						       sqlite3_value ** argv);
    GEOPACKAGE_DECLARE void fnct_gpkgCreateTilesTable (sqlite3_context *
						       context, int argc,
................................................................................
							  context, int argc,
							  sqlite3_value ** argv);   
    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);




/* Markers for unused arguments / variable */
#if __GNUC__
#define UNUSED __attribute__ ((__unused__))
#else
#define UNUSED
#endif

#ifdef __cplusplus
}
#endif

#endif







>







 







>
>
>













59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "sqlite.h"

#ifdef __cplusplus
extern "C"
{
#endif

#include <spatialite/gaiageo.h>

/* Internal geopackage SQL function implementation */
    GEOPACKAGE_DECLARE void fnct_gpkgCreateBaseTables (sqlite3_context *
						       context, int argc,
						       sqlite3_value ** argv);
    GEOPACKAGE_DECLARE void fnct_gpkgCreateTilesTable (sqlite3_context *
						       context, int argc,
................................................................................
							  context, int argc,
							  sqlite3_value ** argv);   
    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
#define UNUSED
#endif

#ifdef __cplusplus
}
#endif

#endif

Added test/sql_stmt_geopackage_tests/implicitgeopackagebinary1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
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