~ubuntu-branches/ubuntu/trusty/postgis/trusty-security

« back to all changes in this revision

Viewing changes to postgis/SERIALIZED_FORM

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2009-12-11 13:10:34 UTC
  • mfrom: (1.1.9 upstream) (5.2.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20091211131034-wmsz69wxvt95pe5r
Tags: 1.4.0-2
* Upload to unstable.
* Better parameterized debian/rules against postgis $(VERSION).
* Added dblatex and libcunit1-dev among build-deps.
* Added postgis_comments.sql to contrib/ SQL templates.
* Dropping 8.3 support, no more supported for squeeze.
  (closes: #559587)
* Do not stop on error in postrm if the target dir does not exist.
  (closes: #560409)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
===PostGIS Serialized Geometry Format===
 
2
 
 
3
 
 
4
==Introduction==
 
5
 
 
6
 
 
7
This document describe the serialied form of
 
8
Geometries as implemented starting from version 1.x.
 
9
 
 
10
Prior versions used a different format.
 
11
 
 
12
The new format is aimed at reducing geometries size, for
 
13
this reason we refer to the old format as HWGEOM (High Weight GEOMetry)
 
14
and to the new one as LWGEOM (Light Weight GEOMetry).
 
15
 
 
16
 
 
17
==Serialized Form and PostgreSQL varlena objects==
 
18
 
 
19
 
 
20
PostGIS serialized form is a recursive structure, where
 
21
elements in a collection (multi* or geometrycollections)
 
22
are complete serialized forms themself.
 
23
 
 
24
PostgreSQL requires to add an header to variable-lenght
 
25
user defined types, for this reason, the type actually
 
26
stored on disk is a SERIALIZED geometry wrapped in this
 
27
required header. We call the complete PostgreSQL type
 
28
``PG_LWGEOM''.
 
29
 
 
30
 
 
31
==Geometry Type byte==
 
32
 
 
33
 
 
34
All serialiezd geometries start with a single byte
 
35
encoding geometry type (lower nibble) and flags
 
36
(higher nibble). 
 
37
 
 
38
Geometry Type Byte:
 
39
 
 
40
     [BSZM] [TTTT]
 
41
 
 
42
Flags values:
 
43
 
 
44
      B = 16 byte BOX2DFLOAT4 follows (probably not aligned) [before SRID]
 
45
      S = 4 byte SRID attached (0= not attached (-1), 1= attached)
 
46
      ZM = dimensionality (hasZ, hasM)
 
47
 
 
48
Type values:
 
49
 
 
50
      wkbPoint = 1
 
51
      wkbLineString = 2
 
52
      wkbPolygon = 3
 
53
      wkbMultiPoint = 4
 
54
      wkbMultiLineString = 5
 
55
      wkbMultiPolygon = 6
 
56
      wkbGeometryCollection = 7
 
57
 
 
58
* Note that the following values do not correspond to wkb type values.
 
59
      CircularString = 8
 
60
      CompoundCurve = 9
 
61
      CurvePolygon = 13
 
62
      MultiCurve = 14
 
63
      MultiSurface = 15
 
64
 
 
65
==Bounding box and SRID==
 
66
 
 
67
 
 
68
Following the Geometry type byte we find optional bounding box
 
69
and/or SRID values. Presence of them is encoded in the type byte.
 
70
 
 
71
If both objects are present the bounding box come first.
 
72
 
 
73
Bounding box is composed by 4 32-bit float:
 
74
 
 
75
        [FLOAT32] [FLOAT32] [FLOAT32] [FLOAT32]
 
76
           xmin      ymin      xmax      ymax
 
77
 
 
78
SRID is composed by a 32-bit integer:
 
79
 
 
80
        [INT32]
 
81
         SRID
 
82
 
 
83
 
 
84
==Ordinate Arrays==
 
85
 
 
86
 
 
87
When it comes to ordinate values all geometries use arrays of 64-bit
 
88
floats. Number and semantic of values depend on the dimension flags
 
89
on the geometry type byte:
 
90
 
 
91
         2D (ZM=0x00)
 
92
                [FLOAT64] [FLOAT64]
 
93
                    x         y
 
94
 
 
95
        3DM (ZM=0x01)
 
96
                [FLOAT64] [FLOAT64] [FLOAT64]
 
97
                    x         y         m
 
98
 
 
99
        3DZ (ZM=0x10)
 
100
                [FLOAT64] [FLOAT64] [FLOAT64]
 
101
                    x         y         z
 
102
 
 
103
         4D (ZM=0x11)
 
104
                [FLOAT64] [FLOAT64] [FLOAT64] [FLOAT64]
 
105
                    x         y         z         m
 
106
 
 
107
 
 
108
==Geometry types==
 
109
 
 
110
What you find after the type byte and optional bbox and SRID
 
111
(COMMON_HEADER from now on) depends on actual geometry type.
 
112
 
 
113
=Point=
 
114
 
 
115
A Point geometry is as follows:
 
116
 
 
117
        <COMMON_HEADER>
 
118
        <ORDINATE_ARRAY> -- single element
 
119
 
 
120
=LineString=
 
121
 
 
122
A LineString geometry is as follows:
 
123
 
 
124
        <COMMON_HEADER>
 
125
        <UINT32> -- number of elements in following ORDINATE_ARRAY
 
126
        <ORDINATE_ARRAY>
 
127
 
 
128
=CircularString=
 
129
 
 
130
A CircularString geometry is as follows:
 
131
 
 
132
        <COMMON_HEADER>
 
133
        <UINT32> -- number of elements in following ORDINATE_ARRAY
 
134
        <ORDINATE_ARRAY>
 
135
 
 
136
=CompoundString=
 
137
 
 
138
A CompoundString geometry is as follows:
 
139
 
 
140
        <COMMON_HEADER>
 
141
        <UINT32> -- number of segments
 
142
        One or more geometries as specified by previous uint32:
 
143
                <SERIALIZED_GEOMETRY> -- Must be some combination of 
 
144
                                         LineStrings and CircularStrings.
 
145
 
 
146
=Polygon=
 
147
 
 
148
A Polygon geometry is as follows:
 
149
 
 
150
        <COMMON_HEADER>
 
151
 
 
152
        <UINT32> -- number of ORDINATE_ARRAYs (at least 1, the shell)
 
153
 
 
154
        One or more arrays (rings) as specified by previous uint32:
 
155
 
 
156
                <UINT32> -- number of elements in following ORDINATE_ARRAY
 
157
                <ORDINATE_ARRAY> -- single element
 
158
 
 
159
=CurvePolygon=                
 
160
 
 
161
A CurvePolygon geometry is as follows:
 
162
 
 
163
        <COMMON_HEADER>
 
164
        <UINT32> -- number of rings
 
165
        One or more geometries as specified by previous uint32:
 
166
                <SERIALIZED_GEOMETRY> -- Must be some combination of 
 
167
                                         LineStrings and CircularStrings.
 
168
                                         CompoundString are not yet supported.
 
169
 
 
170
=Collections=
 
171
 
 
172
All collection types (MultiPoint, MultiLineString, MultiPolygon,
 
173
GeometryCollection) have the same structure. Real type is just
 
174
an hint on what one should expect from element geometries.
 
175
Note that the GeometryCollection type is also used for EMPTY
 
176
Geometries (number_of_geometries is set to 0 in this case).
 
177
 
 
178
A Collection geometry is as follows:
 
179
 
 
180
        <COMMON_HEADER>
 
181
 
 
182
        <UINT32> -- number of GEOMETRIES
 
183
 
 
184
        Zero (EMPTY) or more geometries as specified by previous uint32:
 
185
 
 
186
                <SERIALIZED_GEOMETRY> -- starting from type byte again
 
187
 
 
188
 
 
189
==Examples==
 
190
 
 
191
 
 
192
=3DZ point, no bounding box, no SRID=
 
193
 
 
194
        <char>   TYPE - flags:__Z_  type:1
 
195
        <double> X
 
196
        <double> Y
 
197
        <double> Z
 
198
 
 
199
=3DM point, bounding box, no SRID=
 
200
 
 
201
        <char>   TYPE - flags:B__M  type:1
 
202
        <float>  XMIN
 
203
        <float>  YMIN
 
204
        <float>  XMAX
 
205
        <float>  YMAX
 
206
        <double> X
 
207
        <double> Y
 
208
        <double> M
 
209
 
 
210
=2D LineString, no bounding box, SRID=
 
211
 
 
212
        <char>   TYPE - flags:_S__  type:2
 
213
 
 
214
        <uint32> NPOINTS - 3
 
215
 
 
216
        <uint32> SRID
 
217
 
 
218
        <double> X0
 
219
        <double> Y0
 
220
 
 
221
        <double> X1
 
222
        <double> Y1
 
223
 
 
224
        <double> X2
 
225
        <double> Y2
 
226
 
 
227
=2D polygon, no bounding box, no SRID=
 
228
 
 
229
        <char>   TYPE - flags:____  type:3
 
230
 
 
231
        <uint32> NRINGS - 2
 
232
 
 
233
        <uint32> NPOINTS - 4
 
234
        <double> X0
 
235
        <double> Y0
 
236
        <double> X1
 
237
        <double> Y1
 
238
        <double> X2
 
239
        <double> Y2
 
240
        <double> X3
 
241
        <double> Y3
 
242
 
 
243
        <uint32> NPOINTS - 6
 
244
        <double> X0
 
245
        <double> Y0
 
246
        <double> X1
 
247
        <double> Y1
 
248
        <double> X2
 
249
        <double> Y2
 
250
        <double> X3
 
251
        <double> Y3
 
252
        <double> X4
 
253
        <double> Y4
 
254
        <double> X5
 
255
        <double> Y5
 
256
 
 
257
=2D Collection of a point and a line, SRID and bbox present=
 
258
 
 
259
        <char>   TYPE - flags:BS__  type:7
 
260
 
 
261
        -- BBOX
 
262
        <float>  XMIN
 
263
        <float>  YMIN
 
264
        <float>  XMAX
 
265
        <float>  YMAX
 
266
 
 
267
        -- SRID
 
268
        <uint32> SRID
 
269
 
 
270
        <uint32> NGEOMS - 2
 
271
 
 
272
        <char>   TYPE - flags:____  type:1 ( the point )
 
273
        <double> X0
 
274
        <double> Y0
 
275
 
 
276
        <char>   TYPE - flags:____  type:2 ( the line )
 
277
        <uint32> NPOINTS - 3
 
278
        <double> X0
 
279
        <double> Y0
 
280
        <double> X1
 
281
        <double> Y1
 
282
        <double> X2
 
283
        <double> Y2
 
284
 
 
285
Note that in the inner geometries:
 
286
 
 
287
        - SRID value is inherited by parent geometry type.
 
288
 
 
289
        - BBOX value is not present (can be, however)
 
290
 
 
291
        - ZM flags must exactly match those in the outer geometry type byte
 
292