1
- using System . Linq ;
1
+ using System ;
2
+ using System . Linq ;
2
3
3
4
using LinqToDB ;
4
5
using NUnit . Framework ;
@@ -304,34 +305,40 @@ public void TestSTPolygon()
304
305
. Value ( g => g . Geometry , ( ) => GeometryConstructors . STPolygon ( GeometryInput . STGeomFromText ( Wkt1 ) , SRID4326 ) )
305
306
. Insert ( ) ;
306
307
307
- db . TestGeometries
308
- . Value ( g => g . Id , 2 )
309
- . Value ( g => g . Geometry , ( ) => GeometryConstructors . STPolygon ( GeometryInput . STGeomFromText ( Wkt2 ) , SRID4326 ) )
310
- . Insert ( ) ;
311
-
312
- db . TestGeometries
313
- . Value ( g => g . Id , 3 )
314
- . Value ( g => g . Geometry , ( ) => GeometryConstructors . STPolygon ( Wkt1 , SRID4326 ) )
315
- . Insert ( ) ;
316
-
317
308
Assert . AreEqual (
318
309
"POLYGON((75 29,77 29,77 29,75 29))" ,
319
310
db . TestGeometries . Where ( g => g . Id == 1 )
320
311
. Select ( g => g . Geometry . STAsText ( ) )
321
312
. Single ( ) ) ;
322
313
314
+ db . TestGeometries
315
+ . Value ( g => g . Id , 2 )
316
+ . Value ( g => g . Geometry , ( ) => GeometryConstructors . STPolygon ( GeometryInput . STGeomFromText ( Wkt2 ) , SRID4326 ) )
317
+ . Insert ( ) ;
318
+
319
+
323
320
Assert . AreEqual (
324
321
"SRID=4326;POLYGON((75 29 1,77 29 2,77 29 3,75 29 1))" ,
325
322
db . TestGeometries
326
323
. Where ( g => g . Id == 2 )
327
324
. Select ( g => g . Geometry . STAsEWKT ( ) )
328
325
. Single ( ) ) ;
329
326
330
- Assert . AreEqual (
331
- "POLYGON((75 29,77 29,77 29,75 29))" ,
332
- db . TestGeometries . Where ( g => g . Id == 3 )
333
- . Select ( g => g . Geometry . STAsText ( ) )
334
- . Single ( ) ) ;
327
+ // TODO: ? reason of error? ST_Polygon(text) not works in 2.5 ?
328
+ var version = new Version ( db . Select ( ( ) => VersionFunctions . PostGISLibVersion ( ) ) ) ;
329
+ if ( version >= new Version ( "3.0.0" ) )
330
+ {
331
+ db . TestGeometries
332
+ . Value ( g => g . Id , 3 )
333
+ . Value ( g => g . Geometry , ( ) => GeometryConstructors . STPolygon ( Wkt1 , SRID4326 ) )
334
+ . Insert ( ) ;
335
+
336
+ Assert . AreEqual (
337
+ "POLYGON((75 29,77 29,77 29,75 29))" ,
338
+ db . TestGeometries . Where ( g => g . Id == 3 )
339
+ . Select ( g => g . Geometry . STAsText ( ) )
340
+ . Single ( ) ) ;
341
+ }
335
342
}
336
343
}
337
344
@@ -340,54 +347,100 @@ public void TestSTTileEnvelope()
340
347
{
341
348
using ( var db = new PostGisTestDataConnection ( TestDatabaseConnectionString ) )
342
349
{
343
- db . TestGeometries
344
- . Value ( g => g . Id , 1 )
345
- . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 2 , 1 , 1 ) )
346
- . Insert ( ) ;
350
+ var version = new Version ( db . Select ( ( ) => VersionFunctions . PostGISLibVersion ( ) ) ) ;
351
+ if ( version >= new Version ( "3.0.0" ) )
352
+ {
353
+ db . TestGeometries
354
+ . Value ( g => g . Id , 1 )
355
+ . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 2 , 1 , 1 ) )
356
+ . Insert ( ) ;
347
357
348
- db . TestGeometries
349
- . Value ( g => g . Id , 2 )
350
- . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 3 , 1 , 1 , GeometryConstructors . STMakeEnvelope ( - 180 , - 90 , 180 , 90 , SRID4326 ) ) )
351
- . Insert ( ) ;
358
+ db . TestGeometries
359
+ . Value ( g => g . Id , 2 )
360
+ . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 3 , 1 , 1 , GeometryConstructors . STMakeEnvelope ( - 180 , - 90 , 180 , 90 , SRID4326 ) ) )
361
+ . Insert ( ) ;
352
362
353
- db . TestGeometries
354
- . Value ( g => g . Id , 3 )
355
- . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 2 , 1 , 1 , "SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)" ) )
356
- . Insert ( ) ;
363
+ db . TestGeometries
364
+ . Value ( g => g . Id , 3 )
365
+ . Value ( g => g . Geometry , ( ) => GeometryConstructors . STTileEnvelope ( 2 , 1 , 1 , "SRID=3857;LINESTRING(-20037508.342789 -20037508.342789,20037508.342789 20037508.342789)" ) )
366
+ . Insert ( ) ;
367
+
368
+ var result1 = db . TestGeometries . Where ( g => g . Id == 1 ) ;
369
+ var poly1 = result1 . Select ( g => g . Geometry ) . Single ( ) as NTSGS . Polygon ;
370
+ Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 0 ] . X , 1.0E-6 ) ;
371
+ Assert . AreEqual ( 0 , poly1 . Coordinates [ 0 ] . Y , 1.0E-6 ) ;
372
+ Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 1 ] . X , 1.0E-6 ) ;
373
+ Assert . AreEqual ( 10018754.1713945 , poly1 . Coordinates [ 1 ] . Y , 1.0E-6 ) ;
374
+ Assert . AreEqual ( 0 , poly1 . Coordinates [ 2 ] . X , 1.0E-6 ) ;
375
+ Assert . AreEqual ( 10018754.1713945 , poly1 . Coordinates [ 2 ] . Y , 1.0E-6 ) ;
376
+ Assert . AreEqual ( 0 , poly1 . Coordinates [ 3 ] . X , 1.0E-6 ) ;
377
+ Assert . AreEqual ( 0 , poly1 . Coordinates [ 3 ] . Y , 1.0E-6 ) ;
378
+ Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 4 ] . X , 1.0E-6 ) ;
379
+ Assert . AreEqual ( 0 , poly1 . Coordinates [ 4 ] . Y , 1.0E-6 ) ;
380
+ Assert . AreEqual ( SRID3857 , poly1 . SRID ) ;
381
+
382
+ var result2 = db . TestGeometries . Where ( g => g . Id == 2 ) ;
383
+ Assert . AreEqual ( "POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45))" ,
384
+ result2 . Select ( g => g . Geometry . STAsText ( ) ) . Single ( ) ) ;
385
+ Assert . AreEqual ( SRID4326 ,
386
+ result2 . Select ( g => g . Geometry . STSrId ( ) ) . Single ( ) ) ;
387
+
388
+ var result3 = db . TestGeometries . Where ( g => g . Id == 3 ) ;
389
+ var poly3 = result3 . Select ( g => g . Geometry ) . Single ( ) as NTSGS . Polygon ;
390
+ Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 0 ] . X , 1.0E-6 ) ;
391
+ Assert . AreEqual ( 0 , poly3 . Coordinates [ 0 ] . Y , 1.0E-6 ) ;
392
+ Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 1 ] . X , 1.0E-6 ) ;
393
+ Assert . AreEqual ( 10018754.1713945 , poly3 . Coordinates [ 1 ] . Y , 1.0E-6 ) ;
394
+ Assert . AreEqual ( 0 , poly3 . Coordinates [ 2 ] . X , 1.0E-6 ) ;
395
+ Assert . AreEqual ( 10018754.1713945 , poly3 . Coordinates [ 2 ] . Y , 1.0E-6 ) ;
396
+ Assert . AreEqual ( 0 , poly3 . Coordinates [ 3 ] . X , 1.0E-6 ) ;
397
+ Assert . AreEqual ( 0 , poly3 . Coordinates [ 3 ] . Y , 1.0E-6 ) ;
398
+ Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 4 ] . X , 1.0E-6 ) ;
399
+ Assert . AreEqual ( 0 , poly3 . Coordinates [ 4 ] . Y , 1.0E-6 ) ;
400
+ Assert . AreEqual ( SRID3857 , poly3 . SRID ) ;
401
+ }
402
+ }
403
+ }
357
404
358
- var result1 = db . TestGeometries . Where ( g => g . Id == 1 ) ;
359
- var poly1 = result1 . Select ( g => g . Geometry ) . Single ( ) as NTSGS . Polygon ;
360
- Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 0 ] . X , 1.0E-6 ) ;
361
- Assert . AreEqual ( 0 , poly1 . Coordinates [ 0 ] . Y , 1.0E-6 ) ;
362
- Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 1 ] . X , 1.0E-6 ) ;
363
- Assert . AreEqual ( 10018754.1713945 , poly1 . Coordinates [ 1 ] . Y , 1.0E-6 ) ;
364
- Assert . AreEqual ( 0 , poly1 . Coordinates [ 2 ] . X , 1.0E-6 ) ;
365
- Assert . AreEqual ( 10018754.1713945 , poly1 . Coordinates [ 2 ] . Y , 1.0E-6 ) ;
366
- Assert . AreEqual ( 0 , poly1 . Coordinates [ 3 ] . X , 1.0E-6 ) ;
367
- Assert . AreEqual ( 0 , poly1 . Coordinates [ 3 ] . Y , 1.0E-6 ) ;
368
- Assert . AreEqual ( - 10018754.1713945 , poly1 . Coordinates [ 4 ] . X , 1.0E-6 ) ;
369
- Assert . AreEqual ( 0 , poly1 . Coordinates [ 4 ] . Y , 1.0E-6 ) ;
370
- Assert . AreEqual ( SRID3857 , poly1 . SRID ) ;
371
-
372
- var result2 = db . TestGeometries . Where ( g => g . Id == 2 ) ;
373
- Assert . AreEqual ( "POLYGON((-135 45,-135 67.5,-90 67.5,-90 45,-135 45))" ,
374
- result2 . Select ( g => g . Geometry . STAsText ( ) ) . Single ( ) ) ;
375
- Assert . AreEqual ( SRID4326 ,
376
- result2 . Select ( g => g . Geometry . STSrId ( ) ) . Single ( ) ) ;
377
-
378
- var result3 = db . TestGeometries . Where ( g => g . Id == 3 ) ;
379
- var poly3 = result3 . Select ( g => g . Geometry ) . Single ( ) as NTSGS . Polygon ;
380
- Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 0 ] . X , 1.0E-6 ) ;
381
- Assert . AreEqual ( 0 , poly3 . Coordinates [ 0 ] . Y , 1.0E-6 ) ;
382
- Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 1 ] . X , 1.0E-6 ) ;
383
- Assert . AreEqual ( 10018754.1713945 , poly3 . Coordinates [ 1 ] . Y , 1.0E-6 ) ;
384
- Assert . AreEqual ( 0 , poly3 . Coordinates [ 2 ] . X , 1.0E-6 ) ;
385
- Assert . AreEqual ( 10018754.1713945 , poly3 . Coordinates [ 2 ] . Y , 1.0E-6 ) ;
386
- Assert . AreEqual ( 0 , poly3 . Coordinates [ 3 ] . X , 1.0E-6 ) ;
387
- Assert . AreEqual ( 0 , poly3 . Coordinates [ 3 ] . Y , 1.0E-6 ) ;
388
- Assert . AreEqual ( - 10018754.1713945 , poly3 . Coordinates [ 4 ] . X , 1.0E-6 ) ;
389
- Assert . AreEqual ( 0 , poly3 . Coordinates [ 4 ] . Y , 1.0E-6 ) ;
390
- Assert . AreEqual ( SRID3857 , poly3 . SRID ) ;
405
+ [ Test ]
406
+ public void TestSTHexagon ( )
407
+ {
408
+ using ( var db = new PostGisTestDataConnection ( TestDatabaseConnectionString ) )
409
+ {
410
+ var version = new Version ( db . Select ( ( ) => VersionFunctions . PostGISLibVersion ( ) ) ) ;
411
+ if ( version >= new Version ( "3.1.0" ) )
412
+ {
413
+ var origin = db . Select ( ( ) => GeometryConstructors . STMakePoint ( 0 , 0 ) ) ;
414
+
415
+ var hexagon1 = db . Select ( ( ) => GeometryConstructors . STHexagon ( 1.0 , 0 , 0 , origin ) ) as NTSGS . Polygon ;
416
+ Assert . IsNotNull ( hexagon1 ) ;
417
+ Assert . AreEqual ( 7 , hexagon1 . Coordinates . Length ) ;
418
+
419
+ var hexagon2 = db . Select ( ( ) => GeometryConstructors . STHexagon ( 1.0 , 0 , 0 ) ) as NTSGS . Polygon ;
420
+ Assert . IsNotNull ( hexagon2 ) ;
421
+ Assert . AreEqual ( 7 , hexagon2 . Coordinates . Length ) ;
422
+ }
423
+ }
424
+ }
425
+
426
+ [ Test ]
427
+ public void TestSTSquare ( )
428
+ {
429
+ using ( var db = new PostGisTestDataConnection ( TestDatabaseConnectionString ) )
430
+ {
431
+ var version = new Version ( db . Select ( ( ) => VersionFunctions . PostGISLibVersion ( ) ) ) ;
432
+ if ( version >= new Version ( "3.1.0" ) )
433
+ {
434
+ var origin = db . Select ( ( ) => GeometryConstructors . STMakePoint ( 0 , 0 ) ) ;
435
+
436
+ var square1 = db . Select ( ( ) => GeometryConstructors . STSquare ( 1.0 , 0 , 0 , origin ) ) as NTSGS . Polygon ;
437
+ Assert . IsNotNull ( square1 ) ;
438
+ Assert . AreEqual ( 5 , square1 . Coordinates . Length ) ;
439
+
440
+ var square2 = db . Select ( ( ) => GeometryConstructors . STSquare ( 1.0 , 0 , 0 ) ) as NTSGS . Polygon ;
441
+ Assert . IsNotNull ( square2 ) ;
442
+ Assert . AreEqual ( 5 , square2 . Coordinates . Length ) ;
443
+ }
391
444
}
392
445
}
393
446
}
0 commit comments