空间函数
空间函数用于在坐标参考系统(CRS)中指定二维或三维 POINT
值,并计算两个 POINT
值之间的测地距离。
示例图
以下图用于下面的部分示例。
要重新创建图,请针对空的 Neo4j 数据库运行以下查询
CREATE
(copenhagen:TrainStation {latitude: 55.672874, longitude: 12.564590, city: 'Copenhagen'}),
(malmo:Office {latitude: 55.611784, longitude: 12.994341, city: 'Malmö'}),
(copenhagen)-[:TRAVEL_ROUTE]->(malmo)
point()
语法 |
|
||
描述 |
给定笛卡尔坐标系或 WGS 84 地理坐标系中的两到三个坐标值,返回一个二维或三维点对象。 |
||
参数 |
名称 |
类型 |
描述 |
|
|
笛卡尔二维: 笛卡尔三维: WGS 84 二维: WGS 84 三维: |
|
返回 |
|
如果提供给 |
如果使用 |
如果使用 |
如果未提供 |
|
RETURN point({longitude: 56.7, latitude: 12.78}) AS point
返回一个在 WGS 84 CRS 中,longitude
为 56.7
,latitude
为 12.78
的二维 POINT
。
point |
---|
|
行数: 1 |
RETURN point({x: 2.3, y: 4.5, crs: 'WGS-84'}) AS point
在 WGS 84 CRS 中,可以使用 x
和 y
坐标分别代替 longitude
和 latitude
,前提是 crs
设置为 'WGS-84'
,或 srid
设置为 4326
。
point |
---|
|
行数: 1 |
MATCH (p:Office)
RETURN point({longitude: p.longitude, latitude: p.latitude}) AS officePoint
返回一个表示马尔默市坐标的二维 POINT
,位于 WGS 84 CRS 中。
officePoint |
---|
|
行数: 1 |
RETURN point({longitude: 56.7, latitude: 12.78, height: 8}) AS point
返回一个在 WGS 84 CRS 中,longitude
为 56.7
,latitude
为 12.78
,高度为 8
米的三维 POINT
。
point |
---|
|
行数: 1 |
RETURN point({x: 2.3, y: 4.5}) AS point
返回一个在 笛卡尔 CRS 中,x
坐标为 2.3
,y
坐标为 4.5
的二维 POINT
。
point |
---|
|
行数: 1 |
RETURN point({x: 2.3, y: 4.5, z: 2}) AS point
返回一个在 笛卡尔 CRS 中,x
坐标为 2.3
,y
坐标为 4.5
,z
坐标为 2
的三维 POINT
。
point |
---|
|
行数: 1 |
RETURN point(null) AS p
如果将 null
作为参数提供,则返回 null
。
p |
---|
|
行数: 1 |
point.distance()
语法 |
|
||
描述 |
返回一个 |
||
参数 |
名称 |
类型 |
描述 |
|
|
起始点。 |
|
|
|
与起始点位于同一 CRS 中的终点。 |
|
返回 |
|
-
如果
POINT
值位于 笛卡尔 CRS(二维或三维)中,则返回距离的单位将与点的单位相同,使用毕达哥拉斯定理计算。 -
如果
POINT
值位于 WGS-84 CRS(二维)中,则返回距离的单位将是米,基于球面地球近似的半正矢公式。 -
如果
POINT
值位于 WGS-84 CRS(三维)中,则返回距离的单位将是米。-
距离分两步计算。
-
首先,使用球面地球上的半正矢公式,以两点的平均高度为基准。
-
为了考虑高度差异,使用毕达哥拉斯定理,将先前计算的球面距离与高度差结合起来。
-
-
此公式适用于靠近地球表面的点;例如,它非常适合计算飞机飞行的距离。然而,对于更高的海拔,例如计算两颗卫星之间的距离时,则不太适用。
-
|
|
|
尝试使用不同坐标参考系统(例如 WGS 84 二维和 WGS 84 三维)的点将返回 |
WITH
point({x: 2.3, y: 4.5, crs: 'cartesian'}) AS p1,
point({x: 1.1, y: 5.4, crs: 'cartesian'}) AS p2
RETURN point.distance(p1,p2) AS dist
返回 笛卡尔 CRS 中两个二维点之间的距离。
dist |
---|
|
行数: 1 |
WITH
point({longitude: 12.78, latitude: 56.7, height: 100}) AS p1,
point({latitude: 56.71, longitude: 12.79, height: 100}) AS p2
RETURN point.distance(p1, p2) AS dist
示例 9. point.distance()
dist |
---|
|
行数: 1 |
MATCH (t:TrainStation)-[:TRAVEL_ROUTE]->(o:Office)
WITH
point({longitude: t.longitude, latitude: t.latitude}) AS trainPoint,
point({longitude: o.longitude, latitude: o.latitude}) AS officePoint
RETURN round(point.distance(trainPoint, officePoint)) AS travelDistance
示例 10. point.distance()
返回哥本哈根火车站和马尔默 Neo4j 办公室之间的距离。 |
---|
|
行数: 1 |
RETURN point.distance(null, point({longitude: 56.7, latitude: 12.78})) AS d
示例 11. point.distance()
如果其中一个或两个参数为 null ,则返回 null 。 |
---|
|
行数: 1 |
null
语法 |
|||
描述 |
point.withinBBox(point, lowerLeft, upperRight) |
||
参数 |
名称 |
类型 |
描述 |
|
|
如果提供的点位于由另外两个点定义的边界框内,则返回 true。 |
|
|
|
lowerLeft |
|
|
|
upperRight |
|
返回 |
|
BOOLEAN |
如果任何参数评估为 |
尝试使用不同坐标参考系统(例如 WGS 84 二维和 WGS 84 三维)的 |
|
在地理坐标中交换 |
lowerLeft
和 upperRight
的纬度,使得前者在后者的北方,将导致一个空范围。WITH
point({x: 0, y: 0, crs: 'cartesian'}) AS lowerLeft,
point({x: 10, y: 10, crs: 'cartesian'}) AS upperRight
RETURN point.withinBBox(point({x: 5, y: 5, crs: 'cartesian'}), lowerLeft, upperRight) AS result
示例 12. point.withinBBox()
检查 笛卡尔 CRS 中的点是否包含在边界框中。 |
---|
|
行数: 1 |
WITH
point({longitude: 12.53, latitude: 55.66}) AS lowerLeft,
point({longitude: 12.614, latitude: 55.70}) AS upperRight
MATCH (t:TrainStation)
WHERE point.withinBBox(point({longitude: t.longitude, latitude: t.latitude}), lowerLeft, upperRight)
RETURN count(t)
示例 13. point.withinBBox()
查找哥本哈根周围边界框中包含的所有火车站。 |
---|
|
行数: 1 |
WITH
point({longitude: 179, latitude: 55.66}) AS lowerLeft,
point({longitude: -179, latitude: 55.70}) AS upperRight
RETURN point.withinBBox(point({longitude: 180, latitude: 55.66}), lowerLeft, upperRight) AS result
示例 14. point.withinBBox()
检查 笛卡尔 CRS 中的点是否包含在边界框中。 |
---|
|
行数: 1 |
RETURN
point.withinBBox(
null,
point({longitude: 56.7, latitude: 12.78}),
point({longitude: 57.0, latitude: 13.0})
) AS in
示例 15. point.withinBBox()
如果任何参数为 null ,则返回 null 。 |
---|
|
行数: 1 |