Routing in Neo4j for OSM PointOfInterest



1.我已经下载了一个城市的OSM文件,并通过 https://github.com/neo4j-contrib/osm 将数据导入Neo4j

2.按照自述文件,我添加了距离,交叉点,路线关系,兴趣点。

3.但是,ROUTE 关系是双向的,不确定这是否是导致路由算法失败的原因。

仅供参考,我的上述步骤的脚本

  1. 计算距离
'MATCH
(awn:OSMWayNode)-[r:NEXT]-(bwn:OSMWayNode)
WHERE NOT exists(r.distance)
RETURN awn,bwn,r',
'MATCH
(awn)-[:NODE]->(a:OSMNode),
(bwn)-[:NODE]->(b:OSMNode)
SET r.distance=round(distance(a.location,b.location))',
{batchSize:10000,parallel:false});

2.确定什么是交叉点

'MATCH(n:OSMNode)
WHERE size((n)<-[:NODE]-())>2
AND NOT (n:Intersection)
RETURN n',
'MATCH
(n)<-[:NODE]-(wn:OSMWayNode),(wn)<-[:NEXT*]-(wx),
(wx)<-[:FIRST_NODE]-(w:OSMWay)-[:TAGS]->(wt:OSMTags)
WHERE exists(wt.highway)
SET n:Intersection',
{batchSize:10000,parallel:false});

3.用新的距离关系连接决策点(交点(

'MATCH(x:Intersection)
CALL spatial.osm.routeIntersection(x,false,false,false)
YIELD fromNode,toNode,distance,fromRel,toRel
RETURN fromNode,toNode,distance,fromRel,toRel',
'MERGE (fromNode)-[r:ROUTE {fromRel:id(fromRel),toRel:id(toRel)}]->(toNode)
ON CREATE SET r.distance=round(distance)',
{batchSize:10000,parallel:false});

4.创建兴趣点,按照我为位置创建另一个 3 个兴趣点的方式:{经度:103.835553,纬度:1.3045739},{经度:103.78152251,纬度:1.28357103},{经度:103.8604644,纬度:1.305788741}

MATCH(n:OSMNode)
WHERE
distance(n.location,point({longitude:103.8958005,latitude:1.330945169})
)<100 AND (n)-[:ROUTE]->() and NOT n:PointOfInterest
WITH n,n.location as poi LIMIT 1
MATCH(m:OSMNode)
WHERE distance(poi,m.location)<100
WITH n,m
MATCH(m)<-[:NODE]-(wn:OSMWayNode),
(wn)<-[:NEXT*]-(wx),
(wx)<-[:FIRST_NODE]-(w:OSMWay)
WITH n,w
WITH n,COLLECT(w) AS ways
CALL spatial.osm.routePointOfInterest(n,ways) YIELD node
SET n:PointOfInterest,n.name="AAA"
RETURN count(node)

问题:

我想使用 gds.alpha.spanningTree.minimum.write 来获得从 Point AAA 到所有其他 PointOfInterest 的最小工作量,即 BBB,CCC,DDD

CALL gds.alpha.spanningTree.minimum.write({
nodeProjection: 'PointOfInterest',
relationshipProjection: {
ROUTE: {
type: 'ROUTE',
properties: 'distance',
orientation: 'UNDIRECTED'
},
startNodeId: id(n),
relationshipWeightProperty: 'distance',
writeProperty: 'MINST',
weightWriteProperty: 'writeCost'
}
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis, computeMillis, writeMillis, effectiveNodeCount;

但我总是有错误

Failed to invoke procedure `gds.alpha.spanningTree.minimum.write`: Caused by: java.lang.IllegalArgumentException: Cannot construct a relationship filter out of a java.lang.Long

使用上述方式是否可以达到我的目的?如果是,我的密码有什么问题吗?

关于你的错误,不幸的是,一些记录的例子是错误的。看起来您正在尝试遵循其中一个错误示例。

relationshipProjection应该只包含ROUTE,而不能包含其他属性。

试试这个:

CALL gds.alpha.spanningTree.minimum.write({
nodeProjection: 'PointOfInterest',
relationshipProjection: {
ROUTE: {
type: 'ROUTE',
properties: 'distance',
orientation: 'UNDIRECTED'
}
},
startNodeId: id(n),
relationshipWeightProperty: 'distance',
writeProperty: 'MINST',
weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis, computeMillis, writeMillis, effectiveNodeCount;

我为文档问题创建了一个问题。

最新更新