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