@@ -94,19 +94,31 @@ abstract class SQLServerSpatialDatatype {
94
94
/**
95
95
* Serializes the Geogemetry/Geography instance to WKB.
96
96
*
97
- * @param noZM
98
- * flag to indicate if Z and M coordinates should be included
97
+ * @param excludeZMFromWKB
98
+ * flag to indicate if Z and M coordinates should be excluded from the WKB representation
99
99
* @param type
100
100
* Type of Spatial Datatype (Geometry/Geography)
101
101
*/
102
- protected void serializeToWkb (boolean noZM , SQLServerSpatialDatatype type ) {
103
- ByteBuffer buf = ByteBuffer .allocate (determineWkbCapacity ());
102
+ protected void serializeToWkb (boolean excludeZMFromWKB , SQLServerSpatialDatatype type ) {
103
+ ByteBuffer buf = ByteBuffer .allocate (determineWkbCapacity (excludeZMFromWKB ));
104
104
createSerializationProperties ();
105
105
106
106
buf .order (ByteOrder .LITTLE_ENDIAN );
107
107
buf .putInt (srid );
108
108
buf .put (version );
109
- buf .put (serializationProperties );
109
+ if (excludeZMFromWKB ) {
110
+ byte serializationPropertiesNoZM = serializationProperties ;
111
+ if (hasZvalues ) {
112
+ serializationPropertiesNoZM -= hasZvaluesMask ;
113
+ }
114
+
115
+ if (hasMvalues ) {
116
+ serializationPropertiesNoZM -= hasMvaluesMask ;
117
+ }
118
+ buf .put (serializationPropertiesNoZM );
119
+ } else {
120
+ buf .put (serializationProperties );
121
+ }
110
122
111
123
if (!isSinglePoint && !isSingleLineSegment ) {
112
124
buf .putInt (numberOfPoints );
@@ -124,7 +136,7 @@ protected void serializeToWkb(boolean noZM, SQLServerSpatialDatatype type) {
124
136
}
125
137
}
126
138
127
- if (!noZM ) {
139
+ if (!excludeZMFromWKB ) {
128
140
if (hasZvalues ) {
129
141
for (int i = 0 ; i < numberOfPoints ; i ++) {
130
142
buf .putDouble (zValues [i ]);
@@ -139,7 +151,11 @@ protected void serializeToWkb(boolean noZM, SQLServerSpatialDatatype type) {
139
151
}
140
152
141
153
if (isSinglePoint || isSingleLineSegment ) {
142
- wkb = buf .array ();
154
+ if (excludeZMFromWKB ) {
155
+ wkbNoZM = buf .array ();
156
+ } else {
157
+ wkb = buf .array ();
158
+ }
143
159
return ;
144
160
}
145
161
@@ -163,7 +179,7 @@ protected void serializeToWkb(boolean noZM, SQLServerSpatialDatatype type) {
163
179
}
164
180
}
165
181
166
- if (noZM ) {
182
+ if (excludeZMFromWKB ) {
167
183
wkbNoZM = buf .array ();
168
184
} else {
169
185
wkb = buf .array ();
@@ -1282,32 +1298,36 @@ protected void createSerializationProperties() {
1282
1298
}
1283
1299
}
1284
1300
1285
- protected int determineWkbCapacity () {
1301
+ protected int determineWkbCapacity (boolean excludeZMFromWKB ) {
1286
1302
int totalSize = 0 ;
1287
1303
1288
1304
totalSize += 6 ; // SRID + version + SerializationPropertiesByte
1289
1305
1290
1306
if (isSinglePoint || isSingleLineSegment ) {
1291
1307
totalSize += 16 * numberOfPoints ;
1292
1308
1293
- if (hasZvalues ) {
1294
- totalSize += 8 * numberOfPoints ;
1295
- }
1309
+ if (!excludeZMFromWKB ) {
1310
+ if (hasZvalues ) {
1311
+ totalSize += 8 * numberOfPoints ;
1312
+ }
1296
1313
1297
- if (hasMvalues ) {
1298
- totalSize += 8 * numberOfPoints ;
1314
+ if (hasMvalues ) {
1315
+ totalSize += 8 * numberOfPoints ;
1316
+ }
1299
1317
}
1300
1318
1301
1319
return totalSize ;
1302
1320
}
1303
1321
1304
1322
int pointSize = 16 ;
1305
- if (hasZvalues ) {
1306
- pointSize += 8 ;
1307
- }
1323
+ if (!excludeZMFromWKB ) {
1324
+ if (hasZvalues ) {
1325
+ pointSize += 8 ;
1326
+ }
1308
1327
1309
- if (hasMvalues ) {
1310
- pointSize += 8 ;
1328
+ if (hasMvalues ) {
1329
+ pointSize += 8 ;
1330
+ }
1311
1331
}
1312
1332
1313
1333
totalSize += 12 ; // 4 bytes for 3 ints, each representing the number of points, shapes and figures
0 commit comments