【问题标题】:Routing in Neo4j for OSM PointOfInterest用于 OSM PointOfInterest 的 Neo4j 中的路由
【发布时间】:2020-06-25 14:54:04
【问题描述】:

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

2.Followed README,我添加了距离、交点、ROUTE 关系、PointOfInterest。

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个兴趣点的相同方式:{longitude:103.835553,latitude:1.3045739},{longitude:103.78152251,latitude:1.28357103},{longitude:103.8604644,latitude: 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 来获得从 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

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

【问题讨论】:

    标签: neo4j openstreetmap


    【解决方案1】:

    关于您的错误,很遗憾,documented examples 中的一些错误是错误的。看起来您正在尝试遵循其中一个错误的示例。

    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;
    

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

    【讨论】:

    • 非常感谢。您的代码有效。但似乎我的数据模型仍然存在问题。
    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    相关资源
    最近更新 更多