Files
secondo/bin/Scripts/ORGfromOSM.sec
2026-01-23 17:03:45 +08:00

140 lines
4.6 KiB
Plaintext

###########################################################################
#
# Construction of a Road Network from OpenStreetMap Data in OrderedRelation
# Graph Representation (here only as a relation)
#
# Sequential version for comparison with distributed version.
#
# Uses NestedRelationAlgebra and OsmAlgebra
#
# -> adapt the filename of the osm-file to be imported (first line)
#
#
###########################################################################
query fullosmimport('arnsberg-regbez-latest.osm', "City")
let CityNodesNew = CityNodes feed
extend[Easting: .Lon * 1000000, Northing: .Lat * 1000000]
extend[Box: rectangle2(.Easting, .Easting, .Northing, .Northing)]
sortby[Box]
projectextend[NodeId; Pos: makepoint(.Lon, .Lat)]
addcounter[NodeIdNew, 1]
consume
let Ways =
CityNodesNew feed
CityWays feed itHashJoin[NodeId, NodeRef] sortby[WayId, NodeCounter] nest[WayId; NodeList]
extend[Curve : .NodeList afeed projecttransformstream[Pos] collect_line[TRUE]]
CityWayTags feed nest[WayIdInTag; WayInfo] itHashJoin[WayId, WayIdInTag]
extend[Box: bbox(.Curve) scale[1000000.0]]
sortby[Box]
remove[Box]
consume
let Roads = Ways feed filter[.WayInfo afeed filter[.WayTagKey = "highway"] count > 0] consume
let Nodes =
CityWays feed
CityWays feed {h2}
itHashJoin[NodeRef, NodeRef_h2]
filter[.WayId # .WayId_h2]
CityNodesNew feed
itHashJoin[NodeRef, NodeId]
Roads feed project[WayId] {r1} itHashJoin[WayId, WayId_r1]
Roads feed project[WayId] {r2} itHashJoin[WayId_h2, WayId_r2]
project[WayId, NodeCounter, NodeIdNew, Pos]
Roads feed
projectextend[WayId; Node: .NodeList afeed filter[.NodeCounter = 0] aconsume]
unnest[Node]
project[WayId, NodeCounter, NodeIdNew, Pos]
concat
Roads feed
extend[HighNodeNo: (.NodeList afeed count) - 1]
projectextend[WayId; Node: fun(t: TUPLE)
attr(t, NodeList) afeed filter[.NodeCounter = attr(t, HighNodeNo)] aconsume]
unnest[Node]
project[WayId, NodeCounter, NodeIdNew, Pos]
concat
sortby[WayId, NodeCounter]
rdup
consume
let EdgesUp =
Nodes feed nest[WayId; SectionNodes]
projectextend[WayId; Sections: .SectionNodes afeed
extend_last[Source: ..NodeIdNew::0, Target: .NodeIdNew::0,
SourcePos: ..Pos::[const point value undef],
TargetPos: .Pos::[const point value undef],
SourceNodeCounter: ..NodeCounter::0,
TargetNodeCounter: .NodeCounter::0]
filter[.Source # 0]
project[Source, Target, SourcePos, TargetPos,
SourceNodeCounter, TargetNodeCounter]
aconsume]
Roads feed {r}
itHashJoin[WayId, WayId_r]
projectextend[WayId; Sections: fun(t:TUPLE)
attr(t, Sections) afeed
extend[
Curve: fun(u: TUPLE)
attr(t, NodeList_r) afeed
filter[.NodeCounter_r between[attr(u, SourceNodeCounter),
attr(u, TargetNodeCounter)] ]
projecttransformstream[Pos_r]
collect_sline[TRUE],
RoadName: attr(t, WayInfo_r) afeed filter[.WayTagKey_r = "name"] extract
[WayTagValue_r],
RoadType: attr(t, WayInfo_r) afeed filter[.WayTagKey_r = "highway"] extract
[WayTagValue_r]
]
aconsume ]
unnest[Sections]
consume
let EdgesDown =
Nodes feed nest[WayId; SectionNodes]
projectextend[WayId; Sections: .SectionNodes afeed sortby[NodeCounter desc]
extend_last[Source: ..NodeIdNew::0, Target: .NodeIdNew::0,
SourcePos: ..Pos::[const point value undef],
TargetPos: .Pos::[const point value undef],
SourceNodeCounter: ..NodeCounter::0,
TargetNodeCounter: .NodeCounter::0]
filter[.Source # 0]
project[Source, Target, SourcePos, TargetPos,
SourceNodeCounter, TargetNodeCounter]
aconsume]
Roads feed
filter[.WayInfo afeed filter[.WayTagKey = "oneway"]
filter[(.WayTagValue = "yes")] count = 0] {r}
itHashJoin[WayId, WayId_r]
projectextend[WayId; Sections: fun(t:TUPLE)
attr(t, Sections) afeed extend[Curve: fun(u: TUPLE)
attr(t, NodeList_r) afeed sortby[NodeCounter_r desc]
filter[.NodeCounter_r between[attr(u, TargetNodeCounter),
attr(u, SourceNodeCounter)] ]
projecttransformstream[Pos_r]
collect_sline[TRUE],
RoadName: attr(t, WayInfo_r) afeed filter[.WayTagKey_r = "name"] extract
[WayTagValue_r],
RoadType: attr(t, WayInfo_r) afeed filter[.WayTagKey_r = "highway"] extract
[WayTagValue_r]
]
aconsume ]
unnest[Sections]
consume
let Edges = EdgesUp feed EdgesDown feed concat
projectextend[Source, Target, SourcePos, TargetPos, SourceNodeCounter, TargetNodeCounter, Curve, RoadName,
RoadType; WayId: .WayId]
consume