@@ -1328,6 +1328,189 @@ describe('#integration examples', () => {
1328
1328
}
1329
1329
} , 30000 )
1330
1330
} )
1331
+
1332
+ describe ( 'geospartial types examples' , ( ) => {
1333
+ describe ( 'Point' , ( ) => {
1334
+ it ( 'Cartesian' , async ( ) => {
1335
+ const console = jasmine . createSpyObj ( 'console' , [ 'log' ] )
1336
+ const driver = driverGlobal
1337
+ const session = driver . session ( )
1338
+
1339
+ try {
1340
+ // tag::geospatial-types-cartesian[]
1341
+ // Creating a 2D point in Cartesian space
1342
+ const point2d = new neo4j . types . Point (
1343
+ 7203 , // SRID
1344
+ 1 , // x
1345
+ 5.1 // y
1346
+ )
1347
+
1348
+ // Or in 3D
1349
+ const point3d = new neo4j . types . Point (
1350
+ 9157 , // SRID
1351
+ 1 , // x
1352
+ - 2 , // y
1353
+ 3.1 // z
1354
+ )
1355
+ // end::geospatial-types-cartesian[]
1356
+
1357
+ const recordWith2dPoint = await echo ( session , point2d )
1358
+ const recordWith3dPoint = await echo ( session , point3d )
1359
+
1360
+ // tag::geospatial-types-cartesian[]
1361
+
1362
+ // Reading a 2D point from a record
1363
+ const fieldPoint2d = recordWith2dPoint . get ( 'fieldName' )
1364
+
1365
+ // Serializing
1366
+ fieldPoint2d . toString ( ) // Point{srid=7203, x=1.0, y=5.1}
1367
+
1368
+ // Accessing fields
1369
+ console . log (
1370
+ `Point with x=${ fieldPoint2d . x } , y=${ fieldPoint2d . y } , srid=${ fieldPoint2d . srid } `
1371
+ )
1372
+
1373
+ // Verifiying if object is a Pojnt
1374
+ neo4j . isPoint ( fieldPoint2d ) // true
1375
+
1376
+ // Readning a 3D point from a record
1377
+ const fieldPoint3d = recordWith3dPoint . get ( 'fieldName' )
1378
+
1379
+ // Serializing
1380
+ fieldPoint3d . toString ( ) // Point{srid=9157, x=1.0, y=-2.0, z=3.1}
1381
+
1382
+ // Accessing fields
1383
+ console . log (
1384
+ `Point with x=${ fieldPoint3d . x } , y=${ fieldPoint3d . y } , z=${ fieldPoint3d . z } , srid=${ fieldPoint3d . srid } `
1385
+ )
1386
+
1387
+ // Verifiying if object is a Pojnt
1388
+ neo4j . isPoint ( fieldPoint3d ) // true
1389
+ // end::geospatial-types-cartesian[]
1390
+
1391
+ expect ( neo4j . isPoint ( fieldPoint2d ) ) . toBe ( true )
1392
+ expect ( fieldPoint2d . x ) . toBe ( point2d . x )
1393
+ expect ( fieldPoint2d . y ) . toBe ( point2d . y )
1394
+ expect ( fieldPoint2d . z ) . toBe ( point2d . z )
1395
+ expect ( fieldPoint2d . toString ( ) ) . toEqual (
1396
+ 'Point{srid=7203, x=1.0, y=5.1}'
1397
+ )
1398
+ expect ( console . log ) . toHaveBeenCalledWith (
1399
+ 'Point with x=1, y=5.1, srid=7203'
1400
+ )
1401
+ expect ( fieldPoint2d . srid . toInt ( ) ) . toBe ( Number ( point2d . srid ) )
1402
+
1403
+ expect ( neo4j . isPoint ( fieldPoint3d ) ) . toBe ( true )
1404
+ expect ( fieldPoint3d . x ) . toBe ( point3d . x )
1405
+ expect ( fieldPoint3d . y ) . toBe ( point3d . y )
1406
+ expect ( fieldPoint3d . z ) . toBe ( point3d . z )
1407
+ expect ( fieldPoint3d . toString ( ) ) . toEqual (
1408
+ 'Point{srid=9157, x=1.0, y=-2.0, z=3.1}'
1409
+ )
1410
+ expect ( console . log ) . toHaveBeenCalledWith (
1411
+ 'Point with x=1, y=-2, z=3.1, srid=9157'
1412
+ )
1413
+ expect ( fieldPoint3d . srid . toInt ( ) ) . toBe ( Number ( point3d . srid ) )
1414
+ } finally {
1415
+ await session . close ( )
1416
+ }
1417
+ } )
1418
+
1419
+ it ( 'WGS84' , async ( ) => {
1420
+ const console = jasmine . createSpyObj ( 'console' , [ 'log' ] )
1421
+ const driver = driverGlobal
1422
+ const session = driver . session ( )
1423
+
1424
+ try {
1425
+ // tag::geospatial-types-wgs84[]
1426
+ // Creating a 2D point in WGS84 space
1427
+ const point2d = new neo4j . types . Point (
1428
+ 4326 , // SRID
1429
+ 1 , // x
1430
+ 5.1 // y
1431
+ )
1432
+
1433
+ // Or in 3D
1434
+ const point3d = new neo4j . types . Point (
1435
+ 4979 , // SRID
1436
+ 1 , // x
1437
+ - 2 , // y
1438
+ 3.1 // z
1439
+ )
1440
+ // end::geospatial-types-wgs84[]
1441
+
1442
+ const recordWith2dPoint = await echo ( session , point2d )
1443
+ const recordWith3dPoint = await echo ( session , point3d )
1444
+
1445
+ // tag::geospatial-types-wgs84[]
1446
+
1447
+ // Reading a 2D point from a record
1448
+ const fieldPoint2d = recordWith2dPoint . get ( 'fieldName' )
1449
+
1450
+ // Serializing
1451
+ fieldPoint2d . toString ( ) // Point{srid=4326, x=1.0, y=5.1}
1452
+
1453
+ // Accessing fields
1454
+ console . log (
1455
+ `Point with x=${ fieldPoint2d . x } , y=${ fieldPoint2d . y } , srid=${ fieldPoint2d . srid } `
1456
+ )
1457
+
1458
+ // Verifiying if object is a Pojnt
1459
+ neo4j . isPoint ( fieldPoint2d ) // true
1460
+
1461
+ // Readning a 3D point from a record
1462
+ const fieldPoint3d = recordWith3dPoint . get ( 'fieldName' )
1463
+
1464
+ // Serializing
1465
+ fieldPoint3d . toString ( ) // Point{srid=4979, x=1.0, y=-2.0, z=3.1}
1466
+
1467
+ // Accessing fields
1468
+ console . log (
1469
+ `Point with x=${ fieldPoint3d . x } , y=${ fieldPoint3d . y } , z=${ fieldPoint3d . z } , srid=${ fieldPoint3d . srid } `
1470
+ )
1471
+
1472
+ // Verifiying if object is a Pojnt
1473
+ neo4j . isPoint ( fieldPoint3d ) // true
1474
+ // end::geospatial-types-wgs84[]
1475
+
1476
+ expect ( neo4j . isPoint ( fieldPoint2d ) ) . toBe ( true )
1477
+ expect ( fieldPoint2d . x ) . toBe ( point2d . x )
1478
+ expect ( fieldPoint2d . y ) . toBe ( point2d . y )
1479
+ expect ( fieldPoint2d . z ) . toBe ( point2d . z )
1480
+ expect ( fieldPoint2d . toString ( ) ) . toEqual (
1481
+ 'Point{srid=4326, x=1.0, y=5.1}'
1482
+ )
1483
+ expect ( console . log ) . toHaveBeenCalledWith (
1484
+ 'Point with x=1, y=5.1, srid=4326'
1485
+ )
1486
+ expect ( fieldPoint2d . srid . toInt ( ) ) . toBe ( Number ( point2d . srid ) )
1487
+
1488
+ expect ( neo4j . isPoint ( fieldPoint3d ) ) . toBe ( true )
1489
+ expect ( fieldPoint3d . x ) . toBe ( point3d . x )
1490
+ expect ( fieldPoint3d . y ) . toBe ( point3d . y )
1491
+ expect ( fieldPoint3d . z ) . toBe ( point3d . z )
1492
+ expect ( fieldPoint3d . toString ( ) ) . toEqual (
1493
+ 'Point{srid=4979, x=1.0, y=-2.0, z=3.1}'
1494
+ )
1495
+ expect ( console . log ) . toHaveBeenCalledWith (
1496
+ 'Point with x=1, y=-2, z=3.1, srid=4979'
1497
+ )
1498
+ expect ( fieldPoint3d . srid . toInt ( ) ) . toBe ( Number ( point3d . srid ) )
1499
+ } finally {
1500
+ await session . close ( )
1501
+ }
1502
+ } )
1503
+ } )
1504
+
1505
+ async function echo ( session , value ) {
1506
+ return await session . readTransaction ( async tx => {
1507
+ const result = await tx . run ( 'RETURN $value as fieldName' , {
1508
+ value
1509
+ } )
1510
+ return result . records [ 0 ]
1511
+ } )
1512
+ }
1513
+ } )
1331
1514
} )
1332
1515
1333
1516
function removeLineBreaks ( string ) {
0 commit comments