1 /*
2  * Copyright 2013 Luciad (http://www.luciad.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef GPKG_BLOBIO_H
17 #define GPKG_BLOBIO_H
18 
19 #include "geomio.h"
20 #include "wkb.h"
21 
22 /**
23  * The header of a geometry BLOB as stored in the database.
24  */
25 typedef struct {
26   /**
27    * The encoding version number.
28    */
29   uint8_t version;
30 
31   /**
32    * Indicates if the geometry is empty or not.
33    */
34   uint8_t empty;
35 
36   /**
37    * The SRID of the geometry.
38    */
39   int32_t srid;
40   /**
41    * The envelope of the geometry.
42    */
43   geom_envelope_t envelope;
44 } geom_blob_header_t;
45 
46 /**
47  * A geometry blob writer. geom_blob_writer_t instances can be used to generate a spatial database specific blobs based
48  * on any geometry source. Use geom_blob_writer_geom_consumer() to obtain a geom_consumer_t pointer that can be passed to
49  * geomtery sources.
50  */
51 typedef struct {
52   /** @private */
53   geom_consumer_t geom_consumer;
54   /** @private */
55   geom_blob_header_t header;
56   /** @private */
57   wkb_writer_t wkb_writer;
58 } geom_blob_writer_t;
59 
60 /**
61  * Returns a geometry blob writer as a geometry consumer. This function should be used
62  * to pass the writer to another function that takes a geom_consumer_t as input.
63  * @param writer the writer
64  */
65 geom_consumer_t *geom_blob_writer_geom_consumer(geom_blob_writer_t *writer);
66 
67 /**
68  * Returns a pointer to the data that was written by the given writer. The length of the returned
69  * buffer can be obtained using the gpb_writer_length() function.
70  * @param writer the writer
71  * @return a pointer to the data
72  */
73 uint8_t *geom_blob_writer_getdata(geom_blob_writer_t *writer);
74 
75 /**
76  * Returns the length of the buffer obtained using the geom_blob_writer_getdata() function.
77  * @param writer the writer
78  * @return the length of the data buffer
79  */
80 size_t geom_blob_writer_length(geom_blob_writer_t *writer);
81 
82 #endif
83