1 #include <errno.h>
2 #include <limits.h>
3 #include <stdio.h>
4 #include <stddef.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 #include <spatialite/sqlite.h>
9 
10 #include "spatialite/debug.h"
11 
12 #include "spatialite.h"
13 #include <spatialite_private.h>
14 
15 #define GEOPACKAGE_HEADER_LEN 8
16 #define GEOPACKAGE_2D_ENVELOPE_LEN 32
17 #define GEOPACKAGE_3D_ENVELOPE_LEN 48
18 #define GEOPACKAGE_4D_ENVELOPE_LEN 64
19 #define GEOPACKAGE_MAGIC1 0x47
20 #define GEOPACKAGE_MAGIC2 0x50
21 #define GEOPACKAGE_VERSION 0x00
22 #define GEOPACKAGE_WKB_LITTLEENDIAN 0x01
23 #define GEOPACKAGE_WKB_EXTENDEDGEOMETRY_FLAG (0x01 << 5)
24 #define GEOPACKAGE_WKB_EMPTY_FLAG (0x01 << 4)
25 #define GEOPACKAGE_2D_ENVELOPE 0x01
26 #define GEOPACKAGE_3D_ENVELOPE 0x02
27 #define GEOPACKAGE_2DM_ENVELOPE 0x03
28 #define GEOPACKAGE_3DM_ENVELOPE 0x04
29 #define GEOPACKAGE_FLAGS_2D_LITTLEENDIAN ((GEOPACKAGE_2D_ENVELOPE << 1) | GEOPACKAGE_WKB_LITTLEENDIAN)
30 #define GEOPACKAGE_FLAGS_2DM_LITTLEENDIAN ((GEOPACKAGE_2DM_ENVELOPE << 1) | GEOPACKAGE_WKB_LITTLEENDIAN)
31 #define GEOPACKAGE_FLAGS_3D_LITTLEENDIAN ((GEOPACKAGE_3D_ENVELOPE << 1) | GEOPACKAGE_WKB_LITTLEENDIAN)
32 #define GEOPACKAGE_FLAGS_3DM_LITTLEENDIAN ((GEOPACKAGE_3DM_ENVELOPE << 1) | GEOPACKAGE_WKB_LITTLEENDIAN)
33 #define GEOPACKAGE_WKB_POINT 1
34 #define GEOPACKAGE_WKB_POINTZ 1001
35 #define GEOPACKAGE_WKB_POINTM 2001
36 #define GEOPACKAGE_WKB_POINTZM 3001
37 #define GEOPACKAGE_WKB_HEADER_LEN  ((sizeof(char) + sizeof(int)))
38 
39 #define GEOPACKAGE_DEFAULT_UNDEFINED_SRID 0
40 
41 GEOPACKAGE_DECLARE void gpkgSetHeader2DLittleEndian (unsigned char *ptr,
42 						     int srid, int endian_arch);
43 
44 GEOPACKAGE_DECLARE void gpkgSetHeader2DMbr (unsigned char *ptr, double min_x,
45 					    double min_y, double max_x,
46 					    double max_y, int endian_arch);
47