PostGIS  3.4.0dev-r@@SVN_REVISION@@
mvt.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2016-2017 Björn Harrtell <bjorn@wololo.org>
22  *
23  **********************************************************************/
24 
25 #ifndef MVT_H_
26 #define MVT_H_ 1
27 
28 #include <stdlib.h>
29 #include "postgres.h"
30 #include "utils/builtins.h"
31 #include "utils/array.h"
32 #include "utils/typcache.h"
33 #include "utils/lsyscache.h"
34 #include "catalog/pg_type.h"
35 #include "catalog/namespace.h"
36 #include "executor/executor.h"
37 #include "access/htup_details.h"
38 #include "access/htup.h"
39 #include "../postgis_config.h"
40 #include "liblwgeom.h"
41 #include "lwgeom_pg.h"
42 #include "lwgeom_log.h"
43 
44 #ifdef HAVE_LIBPROTOBUF
45 
46 #include "vector_tile.pb-c.h"
47 
48 typedef struct mvt_column_cache
49 {
50  uint32_t *column_keys_index;
51  uint32_t *column_oid;
52  Datum *values;
53  bool *nulls;
54  TupleDesc tupdesc;
56 
57 typedef struct mvt_agg_context
58 {
59  /* Temporal memory context using during during pgis_asmvt_transfn and deleted after
60  * pgis_asmvt_serialfn. This is to have a faster and simpler way to delete the temporal
61  * objects in parallel runs */
62  MemoryContext trans_context;
63  char *name;
64  uint32_t extent;
65 
66  /* Name and position of the property that sets the feature id */
67  char *id_name;
68  uint32_t id_index;
69 
70  /* Name and position of the property that sets the feature geometry */
71  char *geom_name;
72  uint32_t geom_index;
73 
74  HeapTupleHeader row;
75  /* The layer which stores all the aggregated features. Aggregation can only yield a single layer. */
76  VectorTile__Tile__Layer *layer;
77  /* The size of the features array in the layer */
79  /* The cached result of the aggregation. It can only be set once the operation is complete. */
80  VectorTile__Tile *tile;
81 
82  /* Hash table holding the feature keys */
84 
85  /* Hash tables holding the feature values, one per type */
92 
93  /* Total number of values stored (for all combined value hash tables) */
94  uint32_t values_hash_i;
95  /* Total number of keys stored */
96  uint32_t keys_hash_i;
97 
100 
101 /* Prototypes */
102 LWGEOM *mvt_geom(LWGEOM *geom, const GBOX *bounds, uint32_t extent, uint32_t buffer, bool clip_geom);
105 bytea *mvt_agg_finalfn(mvt_agg_context *ctx);
107 mvt_agg_context * mvt_ctx_deserialize(const bytea *ba);
109 
110 
111 #endif /* HAVE_LIBPROTOBUF */
112 
113 #endif
This library is the generic geometry handling section of PostGIS.
mvt_agg_context * mvt_ctx_combine(mvt_agg_context *ctx1, mvt_agg_context *ctx2)
Definition: mvt.c:1264
mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
Definition: mvt.c:1141
struct mvt_column_cache mvt_column_cache
bytea * mvt_agg_finalfn(mvt_agg_context *ctx)
Finalize aggregation.
Definition: mvt.c:1297
bytea * mvt_ctx_serialize(mvt_agg_context *ctx)
Definition: mvt.c:1126
LWGEOM * mvt_geom(LWGEOM *geom, const GBOX *bounds, uint32_t extent, uint32_t buffer, bool clip_geom)
Transform a geometry into vector tile coordinate space.
Definition: mvt.c:932
void mvt_agg_init_context(mvt_agg_context *ctx)
Initialize aggregation context.
Definition: mvt.c:989
void mvt_agg_transfn(mvt_agg_context *ctx)
Aggregation step.
Definition: mvt.c:1031
struct mvt_agg_context mvt_agg_context
Datum buffer(PG_FUNCTION_ARGS)
uint32_t geom_index
Definition: mvt.h:72
uint32_t values_hash_i
Definition: mvt.h:94
char * id_name
Definition: mvt.h:67
struct mvt_kv_value * uint_values_hash
Definition: mvt.h:89
char * geom_name
Definition: mvt.h:71
size_t features_capacity
Definition: mvt.h:78
MemoryContext trans_context
Definition: mvt.h:62
VectorTile__Tile__Layer * layer
Definition: mvt.h:76
uint32_t keys_hash_i
Definition: mvt.h:96
struct mvt_kv_key * keys_hash
Definition: mvt.h:83
struct mvt_kv_value * float_values_hash
Definition: mvt.h:87
VectorTile__Tile * tile
Definition: mvt.h:80
struct mvt_kv_value * bool_values_hash
Definition: mvt.h:91
struct mvt_kv_value * string_values_hash
Definition: mvt.h:86
uint32_t extent
Definition: mvt.h:64
struct mvt_kv_value * double_values_hash
Definition: mvt.h:88
uint32_t id_index
Definition: mvt.h:68
HeapTupleHeader row
Definition: mvt.h:74
mvt_column_cache column_cache
Definition: mvt.h:98
struct mvt_kv_value * sint_values_hash
Definition: mvt.h:90
char * name
Definition: mvt.h:63
bool * nulls
Definition: mvt.h:53
TupleDesc tupdesc
Definition: mvt.h:54
uint32_t * column_keys_index
Definition: mvt.h:50
Datum * values
Definition: mvt.h:52
uint32_t * column_oid
Definition: mvt.h:51
Definition: mvt.c:64