Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
-------------------------------------------------------------------------
 
TITLE:  ZM values and SRID for Simple Features 
 
AUTHOR: Name: Sandro Santilli
    Email: strk@refractions.net
 
DATE:   27 December 2005
 
CATEGORY: Simple Features Revision Proposal
 
-------------------------------------------------------------------------
 
1. Background
 
OpenGIS document 99-402r2 introduces semantic and well-known
representations for Z-geometries. This proposal extend the well-known
representations to optionally also hold a measure (M) and a SRID.
Measures, as Z values, are attributes of 2D vertices, but their
semantic is unspecified in this document, as they could be used
for any kind 'misurement'. SRID is an attribute of the whole feature.
 
This document defines how geometry can have Z,M or both values and SRID
in a way which is compatible to the existing 2D OpenGIS Simple Features
specification AND to the Z-Geometry documented in OpenGIS 99-402r2.
 
 
2. Proposal
 
2.1. Definition of ZM-Geometry
 
a) A geometry can have either 2, 3 or 4 dimensions.
b) 3rd dimension of a 3d geometry can either represent Z or M (3DZ or 3DM).
c) 4d geometries contain both Z and M (in this order).
d) M and Z values are associated with every vertex.
e) M and Z values are undefined within surface interiors.
 
Any ZM-Geometry can be converted into a 2D geometry by discarding all its
Z and M values. The resulting 2D geometry is the "shadow" of the ZM-Geometry.
2D geometries cannot be safely converted into ZM-Geometries, since their Z
and M values are undefined, and not necessarily zero.
 
 
2.2. Extensions to Well-Known-Binary format
 
The 2d OpenGIS Simple Features specification has the following geometry types:
 
enum wkbGeometryType {
    wkbPoint = 1,
    wkbLineString = 2,
    wkbPolygon = 3,
    wkbMultiPoint = 4,
    wkbMultiLineString = 5,
    wkbMultiPolygon = 6,
    wkbGeometryCollection = 7
}
 
Document 99-402r2 introduces a Z-presence flag (wkbZ) which OR'ed
to the type specifies the presence of Z coordinate:
 
    wkbZ = 0x80000000
 
This proposal suggest the use of an M-presence flag (wkbM) to
allow for XY, XYM, XYZ and XYZM geometries, and SRID-presence
flag to allow for embedded SRID:
 
    wkbM = 0x40000000
    wkbSRID = 0x20000000
 
Possible resulting geometry types are:
 
enum wkbGeometryTypeZ {
 
    wkbPoint = 1,
    wkbLineString = 2,
    wkbPolygon = 3,
    wkbMultiPoint = 4,
    wkbMultiLineString = 5,
    wkbMultiPolygon = 6,
    wkbGeometryCollection = 7,
 
    // | 0x80000000
    wkbPointZ = 0x80000001,
    wkbLineStringZ = 0x80000002,
    wkbPolygonZ = 0x80000003,
    wkbMultiPointZ = 0x80000004,
    wkbMultiLineStringZ = 0x80000005,
    wkbMultiPolygonZ = 0x80000006,
    wkbGeometryCollectionZ = 0x80000007,
 
    // | 0x40000000
    wkbPointM = 0x40000001,
    wkbLineStringM = 0x40000002,
    wkbPolygonM = 0x40000003,
    wkbMultiPointM = 0x40000004,
    wkbMultiLineStringM = 0x40000005,
    wkbMultiPolygonM = 0x40000006,
    wkbGeometryCollectionM = 0x40000007,
 
    // | 0x40000000 | 0x80000000
    wkbPointZM = 0xC0000001,
    wkbLineStringZM = 0xC0000002,
    wkbPolygonZM = 0xC0000003,
    wkbMultiPointZM = 0xC0000004,
    wkbMultiLineStringZM = 0xC0000005,
    wkbMultiPolygonZM = 0xC0000006,
    wkbGeometryCollectionZM = 0xC0000007,
 
    // | 0x20000000 
    wkbPointS = 0x20000001,
    wkbLineStringS = 0x20000002,
    wkbPolygonS = 0x20000003,
    wkbMultiPointS = 0x20000004,
    wkbMultiLineStringS = 0x20000005,
    wkbMultiPolygonS = 0x20000006,
    wkbGeometryCollectionS = 0x20000007,
 
    // | 0x20000000 | 0x80000000
    wkbPointZS = 0xA0000001,
    wkbLineStringZS = 0xA0000002,
    wkbPolygonZS = 0xA0000003,
    wkbMultiPointZS = 0xA0000004,
    wkbMultiLineStringZS = 0xA0000005,
    wkbMultiPolygonZS = 0xA0000006,
    wkbGeometryCollectionZS = 0xA0000007,
 
    // | 0x20000000 | 0x40000000
    wkbPointMS = 0x60000001,
    wkbLineStringMS = 0x60000002,
    wkbPolygonMS = 0x60000003,
    wkbMultiPointMS = 0x60000004,
    wkbMultiLineStringMS = 0x60000005,
    wkbMultiPolygonMS = 0x60000006,
    wkbGeometryCollectionMS = 0x60000007,
 
    // | 0x20000000 | 0x40000000 | 0x80000000
    wkbPointZMS = 0xE0000001,
    wkbLineStringZMS = 0xE0000002,
    wkbPolygonZMS = 0xE0000003,
    wkbMultiPointZMS = 0xE0000004,
    wkbMultiLineStringZMS = 0xE0000005,
    wkbMultiPolygonZMS = 0xE0000006,
    wkbGeometryCollectionZMS = 0xE0000007,
}
 
 
If the SRID flag is set it's value is encoded as a 4byte integer
right after the type integer.
 
If only wkbZ or wkbM flags are set Point coordinates will
be XYZ or XYM, if both wkbZ and wkbM flags are set Point
coordinates will be XYZM (Z first).
 
For example, a ZM-Point geometry at the location (10,20) with Z==30,
M==40 and SRID=4326 would be:
 
WKBPoint {
 
    byte    byteOrder;      // wkbXDR or wkbNDR
 
    uint32  wkbType;        // (wkbPoint+wkbZ+wkbM+wkbSRID) =
                    // 0xE0000001
 
    uint32  SRID;           // 4326
 
    Point {
        Double    x;    // 10.0
        Double    y;    // 20.0
        Double    z;    // 30.0
        Double    m;    // 40.0
    }
}
 
 
2.3. Empty Geometry Handling
 
For geometries with a counter (nPoints for LineString, nRings for Polygon, nPoints for MultiPoint, nLines for MultiLineString, nPolygons for MultiPolygon, nGeometries for GeometryCollection), an Empty geometry can be represented by setting the counter to zero.
 
For an empty Point, which does not have a counter, an empty geometry is signalled by setting all coordinates to an IEEE-754 quiet NaN value (big endian 0x7ff8000000000000 or little endian 0x000000000000f87f depending on the endian value of the WKB).
 
 
2.4. Extensions to Well-Known-Text format
 
Geometry SRID presence and value would be represented using a
"SRID=#;" prefix to the WKT text:
 
    "SRID=4326;POINT(1 2)"
 
3DZ geometry will be represented as:
 
    "POINT(1 2 3)"
 
4D geometry will be represented as:
 
    "POINT(1 2 3 4)"
 
3DM geometry will be represented as:
 
    "POINTM(1 2 3)"
    or
    "GEOMETRYCOLLECTIONM(POINTM(1 2 3), LINESTRINGM(1 2 3, 4 5 6))"
 
Note that the coordinates structure of a geometry must be consistent,
you can't mix dimensions in a single geometry.