@@ -52,20 +52,30 @@ public Ordinates HandleOrdinates
52
52
/// </summary>
53
53
public bool UseCompressed { get ; set ; }
54
54
55
+ /// <summary>
56
+ /// Writes the provided <paramref name="geometry"/> to the given <paramref name="stream"/>.
57
+ /// </summary>
58
+ /// <param name="geometry">A geometry</param>
59
+ /// <param name="stream">The stream to write to</param>
55
60
public void Write ( Geometry geometry , Stream stream )
56
61
{
57
- var g = Write ( geometry ) ;
62
+ byte [ ] g = Write ( geometry ) ;
58
63
stream . Write ( g , 0 , g . Length ) ;
59
64
}
60
65
61
- public byte [ ] Write ( Geometry geom )
66
+ /// <summary>
67
+ /// Writes the provided <paramref name="geometry"/> to an array of bytes
68
+ /// </summary>
69
+ /// <param name="geometry">A geometry</param>
70
+ /// <returns>An array of bytes</returns>
71
+ public byte [ ] Write ( Geometry geometry )
62
72
{
63
73
//if (geom.IsEmpty)
64
74
// return GaiaGeoEmptyHelper.EmptyGeometryCollectionWithSrid(geom.SRID);
65
75
66
- var ordinates = CheckOrdinates ( geom ) ;
67
- var hasZ = ( ordinates & Ordinates . Z ) == Ordinates . Z ;
68
- var hasM = ( ordinates & Ordinates . M ) == Ordinates . M ;
76
+ var ordinates = CheckOrdinates ( geometry ) ;
77
+ bool hasZ = ( ordinates & Ordinates . Z ) == Ordinates . Z ;
78
+ bool hasM = ( ordinates & Ordinates . M ) == Ordinates . M ;
69
79
70
80
var gaiaExport = SetGaiaGeoExportFunctions ( GaiaGeoEndianMarker . GAIA_LITTLE_ENDIAN , hasZ , hasM , UseCompressed ) ;
71
81
@@ -77,10 +87,10 @@ public byte[] Write(Geometry geom)
77
87
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_START ) ;
78
88
bw . Write ( ( byte ) GaiaGeoEndianMarker . GAIA_LITTLE_ENDIAN ) ;
79
89
//SRID
80
- gaiaExport . WriteInt32 ( bw , geom . SRID ) ;
90
+ gaiaExport . WriteInt32 ( bw , geometry . SRID ) ;
81
91
//MBR
82
- var env = geom . EnvelopeInternal ; //.Coordinates;
83
- if ( geom . IsEmpty )
92
+ var env = geometry . EnvelopeInternal ; //.Coordinates;
93
+ if ( geometry . IsEmpty )
84
94
{
85
95
gaiaExport . WriteDouble ( bw , 0d , 0d , 0d , 0d ) ;
86
96
}
@@ -92,7 +102,7 @@ public byte[] Write(Geometry geom)
92
102
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_MBR ) ;
93
103
94
104
//Write geometry
95
- WriteGeometry ( geom , gaiaExport , bw ) ;
105
+ WriteGeometry ( geometry , gaiaExport , bw ) ;
96
106
97
107
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_END ) ;
98
108
}
@@ -126,7 +136,7 @@ private static WriteCoordinates SetWriteCoordinatesFunction(GaiaExport gaiaExpor
126
136
127
137
private static void WriteGeometry ( Geometry geom , GaiaExport gaiaExport , BinaryWriter bw )
128
138
{
129
- WriteCoordinates writeCoordinates = SetWriteCoordinatesFunction ( gaiaExport ) ;
139
+ var writeCoordinates = SetWriteCoordinatesFunction ( gaiaExport ) ;
130
140
131
141
//Geometry type
132
142
int coordinateFlag = gaiaExport . CoordinateFlag ;
@@ -173,7 +183,7 @@ private static void WriteGeometry(Geometry geom, GaiaExport gaiaExport, BinaryWr
173
183
private static void WriteGeometryCollection ( GeometryCollection geom , GaiaExport gaiaExport , BinaryWriter bw )
174
184
{
175
185
gaiaExport . WriteInt32 ( bw , geom . NumGeometries ) ;
176
- for ( var i = 0 ; i < geom . NumGeometries ; i ++ )
186
+ for ( int i = 0 ; i < geom . NumGeometries ; i ++ )
177
187
{
178
188
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_ENTITY ) ;
179
189
WriteGeometry ( geom [ i ] , gaiaExport , bw ) ;
@@ -183,7 +193,7 @@ private static void WriteGeometryCollection(GeometryCollection geom, GaiaExport
183
193
private static void WriteMultiPolygon ( GeometryCollection geom , WriteCoordinates writeCoordinates , GaiaExport gaiaExport , BinaryWriter bw )
184
194
{
185
195
gaiaExport . WriteInt32 ( bw , geom . NumGeometries ) ;
186
- for ( var i = 0 ; i < geom . NumGeometries ; i ++ )
196
+ for ( int i = 0 ; i < geom . NumGeometries ; i ++ )
187
197
{
188
198
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_ENTITY ) ;
189
199
gaiaExport . WriteInt32 ( bw , gaiaExport . CoordinateFlag | ( int ) GaiaGeoGeometry . GAIA_POLYGON ) ;
@@ -194,7 +204,7 @@ private static void WriteMultiPolygon(GeometryCollection geom, WriteCoordinates
194
204
private static void WriteMultiLineString ( MultiLineString geom , WriteCoordinates writeCoordinates , GaiaExport gaiaExport , BinaryWriter bw )
195
205
{
196
206
gaiaExport . WriteInt32 ( bw , geom . NumGeometries ) ;
197
- for ( var i = 0 ; i < geom . NumGeometries ; i ++ )
207
+ for ( int i = 0 ; i < geom . NumGeometries ; i ++ )
198
208
{
199
209
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_ENTITY ) ;
200
210
gaiaExport . WriteInt32 ( bw , gaiaExport . CoordinateFlag | ( int ) GaiaGeoGeometry . GAIA_LINESTRING ) ;
@@ -210,9 +220,9 @@ private static void WriteMultiPoint(MultiPoint geom, WriteCoordinates writeCoord
210
220
wi ( bw , geom . NumGeometries ) ;
211
221
212
222
// get the coordinate flag
213
- var coordinateFlag = gaiaExport . CoordinateFlagUncompressed ;
223
+ int coordinateFlag = gaiaExport . CoordinateFlagUncompressed ;
214
224
215
- for ( var i = 0 ; i < geom . NumGeometries ; i ++ )
225
+ for ( int i = 0 ; i < geom . NumGeometries ; i ++ )
216
226
{
217
227
//write entity begin marker
218
228
bw . Write ( ( byte ) GaiaGeoBlobMark . GAIA_MARK_ENTITY ) ;
@@ -229,7 +239,7 @@ private static void WritePolygon(Polygon geom, WriteCoordinates writeCoordinates
229
239
{
230
240
gaiaExport . WriteInt32 ( bw , geom . NumInteriorRings + 1 ) ;
231
241
WriteLineString ( geom . Shell , writeCoordinates , gaiaExport , bw ) ;
232
- for ( var i = 0 ; i < geom . NumInteriorRings ; i ++ )
242
+ for ( int i = 0 ; i < geom . NumInteriorRings ; i ++ )
233
243
WriteLineString ( geom . GetInteriorRingN ( i ) , writeCoordinates , gaiaExport , bw ) ;
234
244
}
235
245
@@ -247,7 +257,7 @@ private static void WritePoint(Point geom, WriteCoordinates writeCoordinates, Ga
247
257
248
258
private static GaiaExport SetGaiaGeoExportFunctions ( GaiaGeoEndianMarker gaiaGeoEndianMarker , bool hasZ , bool hasM , bool useCompression )
249
259
{
250
- var conversionNeeded = false ;
260
+ bool conversionNeeded = false ;
251
261
switch ( gaiaGeoEndianMarker )
252
262
{
253
263
case GaiaGeoEndianMarker . GAIA_LITTLE_ENDIAN :
@@ -274,7 +284,7 @@ private static void WriteXY(CoordinateSequence coordinateSequence, GaiaExport ex
274
284
{
275
285
var wd = export . WriteDouble ;
276
286
277
- for ( var i = 0 ; i < coordinateSequence . Count ; i ++ )
287
+ for ( int i = 0 ; i < coordinateSequence . Count ; i ++ )
278
288
{
279
289
var c = coordinateSequence . GetCoordinate ( i ) ;
280
290
wd ( bw , c . X , c . Y ) ;
@@ -284,7 +294,7 @@ private static void WriteXY(CoordinateSequence coordinateSequence, GaiaExport ex
284
294
private static void WriteXYZ ( CoordinateSequence coordinateSequence , GaiaExport export , BinaryWriter bw )
285
295
{
286
296
var wd = export . WriteDouble ;
287
- for ( var i = 0 ; i < coordinateSequence . Count ; i ++ )
297
+ for ( int i = 0 ; i < coordinateSequence . Count ; i ++ )
288
298
{
289
299
var c = coordinateSequence . GetCoordinate ( i ) ;
290
300
wd ( bw , c . X , c . Y , c . Z ) ;
@@ -294,7 +304,7 @@ private static void WriteXYZ(CoordinateSequence coordinateSequence, GaiaExport e
294
304
private static void WriteXYM ( CoordinateSequence coordinateSequence , GaiaExport export , BinaryWriter bw )
295
305
{
296
306
var wd = export . WriteDouble ;
297
- for ( var i = 0 ; i < coordinateSequence . Count ; i ++ )
307
+ for ( int i = 0 ; i < coordinateSequence . Count ; i ++ )
298
308
{
299
309
var c = coordinateSequence . GetCoordinate ( i ) ;
300
310
wd ( bw , c . X , c . Y , coordinateSequence . GetOrdinate ( i , Ordinate . M ) ) ;
@@ -304,7 +314,7 @@ private static void WriteXYM(CoordinateSequence coordinateSequence, GaiaExport e
304
314
private static void WriteXYZM ( CoordinateSequence coordinateSequence , GaiaExport export , BinaryWriter bw )
305
315
{
306
316
var wd = export . WriteDouble ;
307
- for ( var i = 0 ; i < coordinateSequence . Count ; i ++ )
317
+ for ( int i = 0 ; i < coordinateSequence . Count ; i ++ )
308
318
{
309
319
var c = coordinateSequence . GetCoordinate ( i ) ;
310
320
wd ( bw , c . X , c . Y , c . Z , coordinateSequence . GetOrdinate ( i , Ordinate . M ) ) ;
@@ -320,14 +330,14 @@ private static void WriteCompressedXY(CoordinateSequence coordinateSequence, Gai
320
330
wd ( bw , cprev . X , cprev . Y ) ;
321
331
322
332
var ws = export . WriteSingle ;
323
- var maxIndex = coordinateSequence . Count - 1 ;
333
+ int maxIndex = coordinateSequence . Count - 1 ;
324
334
if ( maxIndex <= 0 ) return ;
325
335
326
- for ( var i = 1 ; i < maxIndex ; i ++ )
336
+ for ( int i = 1 ; i < maxIndex ; i ++ )
327
337
{
328
338
var c = coordinateSequence . GetCoordinate ( i ) ;
329
- var fx = ( float ) ( c . X - cprev . X ) ;
330
- var fy = ( float ) ( c . Y - cprev . Y ) ;
339
+ float fx = ( float ) ( c . X - cprev . X ) ;
340
+ float fy = ( float ) ( c . Y - cprev . Y ) ;
331
341
ws ( bw , fx , fy ) ;
332
342
cprev = c ;
333
343
}
@@ -345,16 +355,16 @@ private static void WriteCompressedXYZ(CoordinateSequence coordinateSequence, Ga
345
355
var cprev = coordinateSequence . GetCoordinate ( 0 ) ;
346
356
wd ( bw , cprev . X , cprev . Y , cprev . Z ) ;
347
357
348
- var maxIndex = coordinateSequence . Count - 1 ;
358
+ int maxIndex = coordinateSequence . Count - 1 ;
349
359
if ( maxIndex <= 0 ) return ;
350
360
351
361
var ws = export . WriteSingle ;
352
- for ( var i = 1 ; i < maxIndex ; i ++ )
362
+ for ( int i = 1 ; i < maxIndex ; i ++ )
353
363
{
354
364
var c = coordinateSequence . GetCoordinate ( i ) ;
355
- var fx = ( float ) ( c . X - cprev . X ) ;
356
- var fy = ( float ) ( c . Y - cprev . Y ) ;
357
- var fz = ( float ) ( c . Z - cprev . Z ) ;
365
+ float fx = ( float ) ( c . X - cprev . X ) ;
366
+ float fy = ( float ) ( c . Y - cprev . Y ) ;
367
+ float fz = ( float ) ( c . Z - cprev . Z ) ;
358
368
ws ( bw , fx , fy , fz ) ;
359
369
cprev = c ;
360
370
}
@@ -368,19 +378,19 @@ private static void WriteCompressedXYM(CoordinateSequence coordinateSequence, Ga
368
378
369
379
// Write initial coordinate
370
380
var cprev = coordinateSequence . GetCoordinate ( 0 ) ;
371
- var mprev = coordinateSequence . GetOrdinate ( 0 , Ordinate . M ) ;
381
+ double mprev = coordinateSequence . GetOrdinate ( 0 , Ordinate . M ) ;
372
382
wd ( bw , cprev . X , cprev . Y , mprev ) ;
373
383
374
- var maxIndex = coordinateSequence . Count - 1 ;
384
+ int maxIndex = coordinateSequence . Count - 1 ;
375
385
if ( maxIndex <= 0 ) return ;
376
386
377
387
var ws = export . WriteSingle ;
378
- for ( var i = 1 ; i < maxIndex ; i ++ )
388
+ for ( int i = 1 ; i < maxIndex ; i ++ )
379
389
{
380
390
var c = coordinateSequence . GetCoordinate ( i ) ;
381
- var fx = ( float ) ( c . X - cprev . X ) ;
382
- var fy = ( float ) ( c . Y - cprev . Y ) ;
383
- var fm = ( float ) ( coordinateSequence . GetOrdinate ( i , Ordinate . M ) - mprev ) ;
391
+ float fx = ( float ) ( c . X - cprev . X ) ;
392
+ float fy = ( float ) ( c . Y - cprev . Y ) ;
393
+ float fm = ( float ) ( coordinateSequence . GetOrdinate ( i , Ordinate . M ) - mprev ) ;
384
394
ws ( bw , fx , fy , fm ) ;
385
395
cprev = c ;
386
396
}
@@ -395,20 +405,20 @@ private static void WriteCompressedXYZM(CoordinateSequence coordinateSequence, G
395
405
396
406
// Write initial coordinate
397
407
var cprev = coordinateSequence . GetCoordinate ( 0 ) ;
398
- var mprev = coordinateSequence . GetOrdinate ( 0 , Ordinate . M ) ;
408
+ double mprev = coordinateSequence . GetOrdinate ( 0 , Ordinate . M ) ;
399
409
wd ( bw , cprev . X , cprev . Y , cprev . Z , mprev ) ;
400
410
401
- var maxIndex = coordinateSequence . Count - 1 ;
411
+ int maxIndex = coordinateSequence . Count - 1 ;
402
412
if ( maxIndex <= 0 ) return ;
403
413
404
414
var ws = export . WriteSingle ;
405
- for ( var i = 1 ; i < maxIndex ; i ++ )
415
+ for ( int i = 1 ; i < maxIndex ; i ++ )
406
416
{
407
417
var c = coordinateSequence . GetCoordinate ( i ) ;
408
- var fx = ( float ) ( c . X - cprev . X ) ;
409
- var fy = ( float ) ( c . Y - cprev . Y ) ;
410
- var fz = ( float ) ( c . Z - cprev . Z ) ;
411
- var fm = ( float ) ( coordinateSequence . GetOrdinate ( i , Ordinate . M ) - mprev ) ;
418
+ float fx = ( float ) ( c . X - cprev . X ) ;
419
+ float fy = ( float ) ( c . Y - cprev . Y ) ;
420
+ float fz = ( float ) ( c . Z - cprev . Z ) ;
421
+ float fm = ( float ) ( coordinateSequence . GetOrdinate ( i , Ordinate . M ) - mprev ) ;
412
422
ws ( bw , fx , fy , fz , fm ) ;
413
423
cprev = c ;
414
424
}
0 commit comments