395 lines
16 KiB
Plaintext
395 lines
16 KiB
Plaintext
|
|
################################################################################
|
||
|
|
# JNet Import from Openstreetmap data in osm data file format. #
|
||
|
|
################################################################################
|
||
|
|
# Create and open database #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
create database ruegen;
|
||
|
|
|
||
|
|
open database ruegen;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Set path to osm source files. #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let SRC_DIR_PATH = '/home/jandt/Downloads/OSM-Dateien/';
|
||
|
|
let SOURCEFILE = 'mecklenburg-vorpommern.osm';
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Define rectangle selecting part of map which we are interested in. #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let GK_VALUE_FOR_REGION = 4;
|
||
|
|
|
||
|
|
#let PARTREGION = gk((rectangle2(13.094, 13.596, 53.846, 54.102))rect2region, GK_VALUE_FOR_REGION);
|
||
|
|
|
||
|
|
let PARTREGION = gk((rectangle2(13.244, 13.446, 53.946, 54.002))rect2region,
|
||
|
|
GK_VALUE_FOR_REGION4);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Import the raw data from osm-file #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let osmNodesRel =
|
||
|
|
osmimport(SRC_DIR_PATH + SOURCEFILE ,'node')
|
||
|
|
extend [geoData: gk(makepoint(.lon,.lat),GK_VALUE_FOR_REGION)]
|
||
|
|
remove [lon,lat]
|
||
|
|
renameattr[pointType: "type"]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let osmWaysTmp =
|
||
|
|
osmimport(SRC_DIR_PATH + SOURCEFILE,'way')
|
||
|
|
renameattr[roadType: "type"]
|
||
|
|
filter [isdefined(.roadType)]
|
||
|
|
project[ref, name, roadType, osm_id, oneway, layer, maxspeed, nodeRefs]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let osmRestrictionsRel =
|
||
|
|
osmimport(SRC_DIR_PATH + SOURCEFILE,'restriction')
|
||
|
|
renameattr[fromWay: "from", viaNode: "via", toWay: "to"]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Set vmax by maxspeed or roadType. Build sline from nodeRefs. Sortby ref and #
|
||
|
|
# name for later use. #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let secWaysTmp =
|
||
|
|
osmWaysTmp feed
|
||
|
|
projectextend[ref, name, roadType, osm_id, oneway, layer,
|
||
|
|
nodeRefs; vmax: ifthenelse(.maxspeed > 0, int2real(.maxspeed),
|
||
|
|
ifthenelse(.roadType contains "motorway", 130.0,
|
||
|
|
ifthenelse(.roadType contains "trunk", 130.0,
|
||
|
|
ifthenelse(.roadType contains "primary",100.0,
|
||
|
|
ifthenelse(.roadType contains "secondary",70.0,
|
||
|
|
ifthenelse(.roadType contains "tertiary",50.0,
|
||
|
|
ifthenelse(.roadType contains "residential",30.0,
|
||
|
|
ifthenelse(.roadType contains "living_street",15.0,
|
||
|
|
ifthenelse(.roadType contains "road",50.0,
|
||
|
|
ifthenelse(.roadType contains "unclassified",50.0,
|
||
|
|
ifthenelse(.roadType contains "service",50.0,
|
||
|
|
ifthenelse(.roadType contains "track", 5.0, 4.0))))))))))))]
|
||
|
|
projectextendstream[ref, name, roadType, osm_id, oneway, layer,
|
||
|
|
vmax; nodeIdString: tokenize(.nodeRefs,",")]
|
||
|
|
extend[nodeId: toObject(.nodeIdString,0)]
|
||
|
|
remove[nodeIdString]
|
||
|
|
addcounter[orderId,1]
|
||
|
|
osmNodesRel feed {n}
|
||
|
|
hashjoin[nodeId, osm_id_n, 9997]
|
||
|
|
projectextend[ref, name, roadType, osm_id, oneway, layer, vmax, orderId,
|
||
|
|
nodeId; nodePoint: .geoData_n]
|
||
|
|
sortby[osm_id, orderId]
|
||
|
|
groupby[osm_id, ref, name, roadType, oneway, layer,
|
||
|
|
vmax; geometry: group feed projecttransformstream [nodePoint] collect_sline[TRUE],
|
||
|
|
startNodeOSMId: group feed sortby [orderId] head[1] extract[nodeId],
|
||
|
|
endNodeOSMId: group feed sortby [orderId] tail[1] extract[nodeId]]
|
||
|
|
osmNodesRel feed {s}
|
||
|
|
hashjoin[startNodeOSMId, osm_id_s,9997]
|
||
|
|
projectextend[osm_id, ref, name, roadType, oneway, layer, vmax, geometry,
|
||
|
|
endNodeOSMId; sPoint: .geoData_s]
|
||
|
|
osmNodesRel feed {e}
|
||
|
|
hashjoin[endNodeOSMId, osm_id_e,9997]
|
||
|
|
projectextend[osm_id, ref, name, roadType, oneway, layer, vmax, geometry,
|
||
|
|
sPoint; ePoint: .geoData_e]
|
||
|
|
filter[toline(.geometry) intersects PARTREGION]
|
||
|
|
projectextend[osm_id, ref, name, roadType, oneway, layer,
|
||
|
|
vmax; geoData: set_startsmaller(.geometry, ifthenelse(.ePoint < .sPoint, FALSE, TRUE))]
|
||
|
|
sortby[ref, name, osm_id]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Build roads relation #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let longRoadsTmp =
|
||
|
|
secWaysTmp feed
|
||
|
|
projectextend[ref, name, roadType, osm_id; sectCurve: toline(.geoData)]
|
||
|
|
filter [isdefined(.ref)]
|
||
|
|
filter[not(.roadType contains "link")]
|
||
|
|
projectextendstream[name, roadType, osm_id, sectCurve; refToken: tokenize(' '+.ref,";")]
|
||
|
|
projectextend[name, roadType, osm_id, sectCurve; ref: trim(toObject('"'+.refToken +'"',"a"))]
|
||
|
|
sortby[ref,osm_id]
|
||
|
|
groupby[ref; roadCurve: group feed projecttransformstream[sectCurve] collect_line[TRUE],
|
||
|
|
osmIdSet: group feed projecttransformstream[osm_id] createlistj]
|
||
|
|
sortby[ref, roadCurve, osmIdSet]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadsTmp =
|
||
|
|
secWaysTmp feed
|
||
|
|
projectextend[ref, name, roadType, osm_id; sectCurve: toline(.geoData)]
|
||
|
|
filter[not(isdefined(.ref))]
|
||
|
|
filter[isdefined(.name)]
|
||
|
|
filter[not(.roadType contains "link")]
|
||
|
|
sortby[name,osm_id]
|
||
|
|
groupby[name; roadCurve: group feed projecttransformstream[sectCurve] collect_line[TRUE],
|
||
|
|
osmIdSet: group feed projecttransformstream[osm_id] createlistj]
|
||
|
|
sortby[name, roadCurve, osmIdSet]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadsPartsTmp1 =
|
||
|
|
secWaysTmp feed
|
||
|
|
projectextend[ref, name, roadType, osm_id; sectCurve: toline(.geoData)]
|
||
|
|
filter[(.roadType contains "link")]
|
||
|
|
filter[isdefined(.ref) or isdefined(.name)]
|
||
|
|
sortby[osm_id]
|
||
|
|
groupby[osm_id; roadCurve: group feed projecttransformstream[sectCurve] collect_line[TRUE],
|
||
|
|
osmIdSet: group feed projecttransformstream[osm_id] createlistj]
|
||
|
|
sortby[osm_id, roadCurve, osmIdSet]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
|
||
|
|
let roadsPartsTmp =
|
||
|
|
secWaysTmp feed
|
||
|
|
projectextend[ref, name, roadType, osm_id; sectCurve: toline(.geoData)]
|
||
|
|
filter[not(isdefined(.ref))]
|
||
|
|
filter[(not(isdefined(.name)))]
|
||
|
|
sortby[osm_id]
|
||
|
|
groupby[osm_id; roadCurve: group feed projecttransformstream[sectCurve] collect_line[TRUE],
|
||
|
|
osmIdSet: group feed projecttransformstream[osm_id] createlistj]
|
||
|
|
sortby[osm_id, roadCurve, osmIdSet]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadsRelTmp =
|
||
|
|
((longRoadsTmp feed project[roadCurve, osmIdSet])
|
||
|
|
(roadsTmp feed project[roadCurve, osmIdSet])
|
||
|
|
concat)
|
||
|
|
((roadsPartsTmp feed project[roadCurve, osmIdSet])
|
||
|
|
(roadsPartsTmp1 feed project[roadCurve, osmIdSet])
|
||
|
|
concat)
|
||
|
|
concat
|
||
|
|
projectextendstream[osmIdSet; geometry: .roadCurve polylines[TRUE]]
|
||
|
|
projectextend[osmIdSet; geoData: fromline(.geometry), lenth: size(.geometry)]
|
||
|
|
sortby[geoData]
|
||
|
|
addcounter[roadId,1]
|
||
|
|
sortby[roadId]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Compute all junctions and terminating points by finding the existing #
|
||
|
|
# crossings between ways and add terminating points #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let crossingPtsTmp =
|
||
|
|
secWaysTmp feed project [osm_id,geoData,layer] {s1}
|
||
|
|
secWaysTmp feed project [osm_id,geoData,layer] {s2}
|
||
|
|
itSpatialJoin [geoData_s1, geoData_s2, 4 ,8]
|
||
|
|
filter[(.osm_id_s1 < .osm_id_s2) and (.layer_s1 = .layer_s2)]
|
||
|
|
filter[.geoData_s1 intersects .geoData_s2]
|
||
|
|
projectextendstream[; Road1: .osm_id_s1,
|
||
|
|
Road2: .osm_id_s2,
|
||
|
|
Pt: components(crossings(.geoData_s1, .geoData_s2))]
|
||
|
|
filter[isdefined(.Pt)]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadEndPoints =
|
||
|
|
roadsRelTmp feed
|
||
|
|
projectextendstream[geoData; osm_id: createstreamj(.osmIdSet)]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let junctionsTmp =
|
||
|
|
(((crossingPtsTmp feed projectextend[Pt; WayId: .Road1])
|
||
|
|
(crossingPtsTmp feed projectextend[Pt; WayId: .Road2])
|
||
|
|
concat)
|
||
|
|
((secWaysTmp feed projectextend [; Pt: getstartpoint(.geoData), WayId: .osm_id])
|
||
|
|
(secWaysTmp feed projectextend [; Pt: getendpoint(.geoData), WayId: .osm_id])
|
||
|
|
concat)
|
||
|
|
concat)
|
||
|
|
((roadEndPoints feed projectextend[;Pt: getstartpoint(.geoData), WayId: .osm_id])
|
||
|
|
(roadEndPoints feed projectextend[;Pt: getendpoint(.geoData), WayId: .osm_id])
|
||
|
|
concat)
|
||
|
|
concat
|
||
|
|
filter[isdefined(.Pt)]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let junctionNumbers =
|
||
|
|
junctionsTmp feed
|
||
|
|
project[Pt]
|
||
|
|
filter[isdefined(.Pt)]
|
||
|
|
sortby[Pt]
|
||
|
|
rdup
|
||
|
|
addcounter[JuncId,1]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let junctionsRelHelp=
|
||
|
|
junctionsTmp feed {j}
|
||
|
|
junctionNumbers feed {n}
|
||
|
|
itSpatialJoin[Pt_j, Pt_n,4,8]
|
||
|
|
projectextend[;wayId: .WayId_j, Pt: .Pt_j, juncId: .JuncId_n]
|
||
|
|
sortby[juncId, wayId]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let junctionsRel =
|
||
|
|
osmNodesRel feed {o}
|
||
|
|
junctionsRelHelp feed
|
||
|
|
itSpatialJoin[geoData_o,Pt,4,8]
|
||
|
|
projectextend[juncId, wayId;osm_id: .osm_id_o,
|
||
|
|
geoData: .geoData_o]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let terminatingPts =
|
||
|
|
junctionsRel feed
|
||
|
|
sortby [wayId]
|
||
|
|
groupby [wayId; WayPts: group feed projecttransformstream [geoData] collect_points [TRUE],
|
||
|
|
juncs: group feed projecttransformstream[juncId] createlistj]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Split ways into sections #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let sectionsHelp1 =
|
||
|
|
secWaysTmp feed
|
||
|
|
terminatingPts feed {a}
|
||
|
|
hashjoin[osm_id, wayId_a,9997]
|
||
|
|
project[osm_id, ref, name, roadType, oneway, vmax, geoData, WayPts_a]
|
||
|
|
sortby [osm_id]
|
||
|
|
projectextendstream [osm_id, ref, name, roadType, oneway, geoData,
|
||
|
|
vmax; sectionCurve: toline(.geoData) polylines [FALSE,.WayPts_a]]
|
||
|
|
addcounter[SecId,1]
|
||
|
|
projectextend[osm_id, ref, name, SecId, roadType, oneway, vmax,
|
||
|
|
geoData; sectGeoData: fromline(.sectionCurve)]
|
||
|
|
extend[sectStartSmaller: get_startsmaller(.sectGeoData),
|
||
|
|
startNodePoint: getstartpoint(.sectGeoData),
|
||
|
|
endNodePoint: getendpoint(.sectGeoData),
|
||
|
|
lenth: size(.sectGeoData)]
|
||
|
|
extend[startOnCurve: atpoint(.geoData, .startNodePoint),
|
||
|
|
endOnCurve: atpoint(.geoData, .endNodePoint)]
|
||
|
|
projectextend[osm_id, ref, name, SecId, roadType, oneway, vmax,
|
||
|
|
lenth, startOnCurve, endOnCurve; geoDataSection: set_startsmaller(.sectGeoData,
|
||
|
|
ifthenelse(.startOnCurve < .endOnCurve,
|
||
|
|
.sectStartSmaller,
|
||
|
|
not(.sectStartSmaller)))]
|
||
|
|
extend[direc: ifthenelse((.oneway = 0) and (not(.roadType contains "motorway")),
|
||
|
|
[const jdirection value(Both)],
|
||
|
|
ifthenelse((.oneway = 0) and (.roadType contains "link"),
|
||
|
|
[const jdirection value(Both)],
|
||
|
|
ifthenelse(get_startsmaller(.geoDataSection) = (.startOnCurve < .endOnCurve),
|
||
|
|
[const jdirection value(Up)],
|
||
|
|
[const jdirection value(Down)]))),
|
||
|
|
startNodePoint: getstartpoint(.geoDataSection),
|
||
|
|
endNodePoint: getendpoint(.geoDataSection)]
|
||
|
|
junctionsRel feed {j}
|
||
|
|
itSpatialJoin[startNodePoint,geoData_j,4,8]
|
||
|
|
filter[.startNodePoint = .geoData_j]
|
||
|
|
projectextend[osm_id, ref, name, SecId, roadType, oneway, vmax, lenth,
|
||
|
|
direc, endNodePoint; startNodeOSMId: .osm_id_j,
|
||
|
|
startNodeJuncId: .juncId_j,
|
||
|
|
geoData: .geoDataSection]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let sectionsTmp=
|
||
|
|
sectionsHelp1 feed
|
||
|
|
junctionsRel feed {n}
|
||
|
|
itSpatialJoin[endNodePoint,geoData_n,4,8]
|
||
|
|
projectextend[osm_id, ref, name, SecId, roadType, oneway, vmax, geoData,
|
||
|
|
lenth, direc, startNodeOSMId, startNodeJuncId; endNodeOSMId: .osm_id_n,
|
||
|
|
endNodeJuncId: .juncId_n]
|
||
|
|
sortby[SecId]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Connect roads with junctions and sections to compute roadintervals for each #
|
||
|
|
# section and junctions for each road #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let roadSectionsHelp =
|
||
|
|
roadsRelTmp feed
|
||
|
|
projectextendstream[roadId, geoData, lenth; sectOSMId: createstreamj(.osmIdSet)]
|
||
|
|
sectionsTmp feed sortby[osm_id] {s}
|
||
|
|
hashjoin[sectOSMId,osm_id_s,9997]
|
||
|
|
projectextend[roadId, geoData, sectOSMId, lenth, SecId_s, startNodeJuncId_s,
|
||
|
|
endNodeJuncId_s, direc_s, geoData_s,
|
||
|
|
lenth_s, vmax_s; startPoint: getstartpoint(.geoData_s),
|
||
|
|
endPoint: getendpoint(.geoData_s),
|
||
|
|
startPos: atpoint(.geoData, getstartpoint(.geoData_s)),
|
||
|
|
endPos: atpoint(.geoData, getendpoint(.geoData_s))]
|
||
|
|
filter[isdefined(.startPos)]
|
||
|
|
filter[isdefined(.endPos)]
|
||
|
|
sortby[roadId, secId_s]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadSections =
|
||
|
|
roadSectionsHelp feed
|
||
|
|
projectextend [roadId, startNodeJuncId_s, endNodeJuncId_s,
|
||
|
|
SecId_s, vmax_s, direc_s, lenth_s; geoData: .geoData_s,
|
||
|
|
routeInt: createrouteinterval(.roadId, .startPos, .endPos, .direc_s)]
|
||
|
|
sortby[roadId, routeInt]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let roadJunctions =
|
||
|
|
(roadSectionsHelp feed
|
||
|
|
projectextend[roadId; Pos: .startPoint,
|
||
|
|
juncId: .startNodeJuncId_s,
|
||
|
|
juncPosOnRoad: createroutelocation(.roadId, .startPos, .direc_s)])
|
||
|
|
(roadSectionsHelp feed
|
||
|
|
projectextend[roadId; Pos: .endPoint,
|
||
|
|
juncId: .endNodeJuncId_s,
|
||
|
|
juncPosOnRoad: createroutelocation(.roadId, .endPos, .direc_s)])
|
||
|
|
concat
|
||
|
|
sortby[roadId, juncId]
|
||
|
|
rdup
|
||
|
|
consume;
|
||
|
|
|
||
|
|
################################################################################
|
||
|
|
# Connect restrictions with junctions and positions #
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
let secRestrictionsNodes =
|
||
|
|
junctionsRel feed {j}
|
||
|
|
osmRestrictionsRel feed
|
||
|
|
hashjoin[osm_id_j,viaNode,9997]
|
||
|
|
projectextend [osm_id, fromWay, viaNode, toWay,
|
||
|
|
restriction; viaPoint: .geoData_j, viaJuncId: .juncId_j]
|
||
|
|
sectionsTmp feed {s1}
|
||
|
|
hashjoin[osm_id_s1,fromWay,9997]
|
||
|
|
projectextend[osm_id, fromWay, viaNode, toWay, restriction, viaPoint,
|
||
|
|
viaJuncId; fromWaySecId: .SecId_s1,
|
||
|
|
fromWayJuncId1: .startNodeJuncId_s1,
|
||
|
|
fromWayJuncId2: .endNodeJuncId_s1]
|
||
|
|
sectionsTmp feed {s2}
|
||
|
|
hashjoin[osm_id, toWay, 9997]
|
||
|
|
projectextend[osm_id, fromWay, viaNode, toWay, restriction, viaPoint,
|
||
|
|
viaJuncId, fromWaySecId, fromWayJuncId1,
|
||
|
|
fromWayJuncId2; toWaySecId: .SecId_s2,
|
||
|
|
toWayJuncId1: .startNodeJuncId_s1,
|
||
|
|
toWayJuncId2: .endNodeJuncId_s2]
|
||
|
|
sortby[viaJuncId]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
let secRestrictionsSects =
|
||
|
|
sectionsTmp feed {s}
|
||
|
|
osmRestrictionsRel feed
|
||
|
|
hashjoin[osm_id_s, viaNode,9997]
|
||
|
|
projectextend[osm_id, fromWay, viaNode, toWay, restriction; viaSectionId: .SecId_s,
|
||
|
|
viaSectionJuncId1: .startNodeJuncId_s,
|
||
|
|
viaSectionJuncId2: .endNodeJuncId_s]
|
||
|
|
sectionsTmp feed {s1}
|
||
|
|
hashjoin[osm_id_s1,fromWay,9997]
|
||
|
|
projectextend[osm_id, fromWay, viaNode, toWay, restriction, viaSectionId,
|
||
|
|
viaSectionJuncId1, viaSectionJundId2; fromWaySecId: .SecId_s1,
|
||
|
|
fromWayJuncId1: .startNodeJuncId_s1,
|
||
|
|
fromWayJuncId2: .endNodeJuncId_s1]
|
||
|
|
sectionsTmp feed {s2}
|
||
|
|
hashjoin[osm_id_s1,toWay,9997]
|
||
|
|
projectextend[osm_id, fromWay, viaNode, toWay, restriction, viaSectionId,
|
||
|
|
viaSectionJuncId1, viaSectionJundId2, fromWaySecId, fromWayJuncId1,
|
||
|
|
fromWayJuncId2; toWaySecId: .SecId_s2,
|
||
|
|
toWayJuncId1: .startNodeJuncId_s2,
|
||
|
|
toWayJuncId2: .endNodeJuncId_s2]
|
||
|
|
sortby [viaSectionId]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
close database;
|
||
|
|
quit;
|
||
|
|
|