Skip to content

Instantly share code, notes, and snippets.

@michael-simons
Last active December 9, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-simons/c48f6eb0a5fcd1de5b1e9e0c331d3ec2 to your computer and use it in GitHub Desktop.
Save michael-simons/c48f6eb0a5fcd1de5b1e9e0c331d3ec2 to your computer and use it in GitHub Desktop.
Fietsen
WITH 2407988 as parentRel
MATCH (p:Network {externalId: parentRel})
WITH p
CALL apoc.load.xml("https://api.openstreetmap.org/api/0.6/relation/" + p.externalId + "/full") YIELD value AS v
WITH p, [c IN v._children WHERE c._type = 'relation' AND ANY (t IN c._children WHERE t._type = 'tag' and t.k = 'network' and t.v = 'rcn')] as relations
SET p.name = [r IN relations WHERE r.id = toString(p.externalId) | [t IN r._children WHERE t._type = 'tag' and t.k = 'name' | t.v][0] ][0]
WITH p, relations
UNWIND relations AS relation
WITH p, [t IN relation._children WHERE t._type = 'tag' and t.k ='note' and t.v =~ "\\d+-\\d+"] as connection
WHERE size(connection) = 1
WITH p, apoc.text.regexGroups(connection[0].v, "(\\d+)-(\\d+)") as names
MATCH (s:Node {name: names[0][1]}) - [:BELONGS_TO] -> (p)
MATCH (e:Node {name: names[0][2]}) - [:BELONGS_TO] -> (p)
MERGE (s) -[r:NEXT {distance: distance(s.location, e.location)}] ->(e)
return s, r, e
WITH 2407988 as relationId
CREATE (p:Network {externalId: relationId})
WITH p
CALL apoc.load.xml("https://api.openstreetmap.org/api/0.6/relation/" + p.externalId + "/full") YIELD value AS v
WITH p, v, [c IN v._children WHERE c._type = 'node' AND SINGLE (t IN c._children WHERE t._type = 'tag' and t.k = 'rcn_ref')] as nodes
UNWIND nodes AS node
WITH p, node, [t IN node._children WHERE t.k = 'rcn_ref' | t.v][0] as name
MERGE (n:Node {name: name}) - [b:BELONGS_TO] -> (p)
SET n.externalId = toString(node.id),
n.location = point({longitude: toFloat(node.lon), latitude: toFloat(node.lat)})
RETURN n, b, p
MATCH (start:Node{name:'75'}), (end:Node{name:'83'})
CALL algo.shortestPath.stream(start, end, 'distance', {nodeQuery:'Node'})
YIELD nodeId, cost
RETURN algo.getNodeById(nodeId).name AS name, cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment