233 lines
8.3 KiB
Plaintext
233 lines
8.3 KiB
Plaintext
|
|
################################################################################
|
||
|
|
### Postprocessing imported OSM data (4 / 11)
|
||
|
|
################################################################################
|
||
|
|
### This script postprocesses OSM data imported From various files. Some values
|
||
|
|
### are modified, indexes are introduced and new relations collecting data on
|
||
|
|
### equally Named Streets are created.
|
||
|
|
### Please, see tu_Osm_import.sh for further details.
|
||
|
|
###
|
||
|
|
### Preconditions:
|
||
|
|
### - activated necessary algebras
|
||
|
|
### - existing open database with successfully imported Osm data
|
||
|
|
### - StreetsTmp-relation
|
||
|
|
### StreetsTmp: rel{GeoData: sline, Osm_id: int, Name: string, Ref: string,
|
||
|
|
### Type: string, oneway: int, Bridge: int, Maxspeed: int,
|
||
|
|
### Tunnel: bool, Layer: int}
|
||
|
|
### - PointsTmp-relation
|
||
|
|
### PointsTmp: rel{Osm_id: int, Timestamp: int, Name: string, GeoData: point,
|
||
|
|
### Type: string}
|
||
|
|
### - restrictionsTmp-relation
|
||
|
|
### restrictionsTmp: rel{Osm_id: int, From: int, Via: int, To: int,
|
||
|
|
### restriction: text}
|
||
|
|
###
|
||
|
|
### Postconditions:
|
||
|
|
### - StreetsRel-relation
|
||
|
|
### StreetsRel: rel{GeoData: sline, StreetId: int, Name: string, Ref: string,
|
||
|
|
### RoadClassRef: int, OneWay: int, Bridge: int, MaxSpeed: int,
|
||
|
|
### Tunnel: bool, Layer: int}
|
||
|
|
### - PointsRel-relation
|
||
|
|
### PointsRel: rel{PointId: int, Timestamp: int, Name: string, GeoData: point,
|
||
|
|
### PointType: string}
|
||
|
|
### - GroupedStreetsRel-relation
|
||
|
|
### GroupedStreetsRel: rel{Name: string, numParts: int, Geo: line,
|
||
|
|
### GroupedStreetsId: int}
|
||
|
|
### - extStreetsRel-relation
|
||
|
|
### extStreetsRel: rel{GeoData: sline, StreetId: int, Name: string, Ref: string,
|
||
|
|
### RoadClassRef: int, OneWay: int, Bridge: int,
|
||
|
|
### MaxSpeed: int, Tunnel: bool, Layer: int, groupId: int}
|
||
|
|
### - RoadClassesRel-relation
|
||
|
|
### RoadClassesRel: rel{RoadClassId: int, RoadClass: string,
|
||
|
|
### Description: string}
|
||
|
|
### - restrictionsRel-relation
|
||
|
|
### restrictionsRel: rel{FromStreet: int, ToStreet: int, ViaPoint: point,
|
||
|
|
### restriction: text}
|
||
|
|
###
|
||
|
|
### Author:
|
||
|
|
### - Thomas Uchdorf, thomas.uchdorf(at)fernuni-hagen.de
|
||
|
|
################################################################################
|
||
|
|
|
||
|
|
# Creating a relation that maps Road classes To numbers
|
||
|
|
let RoadClassesRel =
|
||
|
|
[const rel(tuple([RoadClassId: int, RoadClass: string,
|
||
|
|
Description: string])) value (
|
||
|
|
(0 "other" "alle sonstigen Strassenarten (insb. Fusswege)")
|
||
|
|
(1 "motorway" "Autobahn")
|
||
|
|
(2 "motorway_link" "Autobahnauf-/abfahrt")
|
||
|
|
(3 "trunk" "auTobahnaehnliche Strasse")
|
||
|
|
(4 "trunk_link" "Auf-/Abfahrt einer auTobahnaehnlichen Strasse")
|
||
|
|
(5 "primary" "Bundesstrasse")
|
||
|
|
(6 "primary_link" "Bundesstrassenauf-/abfahrt")
|
||
|
|
(7 "secondary" "Landstrasse")
|
||
|
|
(8 "secondary_link" "Landstrassenauf-/abfahrt")
|
||
|
|
(9 "tertiary" "Kreisstrasse")
|
||
|
|
(10 "tertiary_link" "Kreisstrassenabfahrt")
|
||
|
|
(11 "residential" "Wohngebietsstrasse")
|
||
|
|
(12 "unclassified" "verbindende Gemeindestrasse")
|
||
|
|
(13 "Road" "unzugeordnete Strasse")
|
||
|
|
(14 "living_Street" "Strasse in verkehrsberuhigtem Bereich")
|
||
|
|
(15 "service" "Erschliessungsweg")
|
||
|
|
(16 "track" "Feld-/Waldweg")
|
||
|
|
)];
|
||
|
|
|
||
|
|
# Renaming the attribute 'Type' which is a secondo keyword. Also
|
||
|
|
# trimming the Street Names as well as the abbreViations and altering
|
||
|
|
# undefined Names (since motorway Names are often undefined generic Names are
|
||
|
|
# introduced for them)
|
||
|
|
let StreetsModified =
|
||
|
|
StreetsTmp feed
|
||
|
|
reNameattr [RoadClass: "Type",OsmId: "Osm_id",
|
||
|
|
OneWay: "oneway",MaxSpeed: "Maxspeed",
|
||
|
|
originalName: "Name", originalRef: "Ref"]
|
||
|
|
extend [Name: ifthenelse(isdefined(.originalName),
|
||
|
|
Tostring(trim(Totext(.originalName))),
|
||
|
|
ifthenelse((isdefined(.originalRef)) and
|
||
|
|
(.RoadClass = 'motorway'),
|
||
|
|
"Autobahn " + .originalRef,
|
||
|
|
"UNKNOWN")),
|
||
|
|
Ref: ifthenelse(isdefined(.originalRef),
|
||
|
|
Tostring(trim(Totext(.originalRef))),
|
||
|
|
"UNKNOWN"),
|
||
|
|
RoadClassTrimmed: trim(.RoadClass)]
|
||
|
|
remove [originalName,originalRef,RoadClass]
|
||
|
|
extend [RoadClass: .RoadClassTrimmed]
|
||
|
|
remove [RoadClassTrimmed]
|
||
|
|
sortby [Name]
|
||
|
|
addcounter[StreetId,1]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Removing the help relation
|
||
|
|
delete StreetsTmp;
|
||
|
|
|
||
|
|
# Changing the representation of the Road class From string To a
|
||
|
|
# corresponding number and removing all unwanted Roads
|
||
|
|
let StreetsRel =
|
||
|
|
StreetsModified feed
|
||
|
|
RoadClassesRel feed
|
||
|
|
smouterjoin [RoadClass,RoadClass]
|
||
|
|
filter [isdefined(.StreetId)]
|
||
|
|
extend [RoadClassRef: ifthenelse(isdefined(.RoadClassId),.RoadClassId,0)]
|
||
|
|
remove [RoadClass,RoadClassId,RoadClass,Description]
|
||
|
|
filter [.RoadClassRef > 0]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Removing the help relation
|
||
|
|
delete StreetsModified;
|
||
|
|
|
||
|
|
# Adding indexes for faster access
|
||
|
|
derive StreetsRel_StreetId_btree =
|
||
|
|
StreetsRel createbtree[StreetId];
|
||
|
|
derive StreetsRel_GeoData_rtree =
|
||
|
|
StreetsRel creatertree[GeoData];
|
||
|
|
derive StreetsRel_Name_btree =
|
||
|
|
StreetsRel createbtree[Name];
|
||
|
|
|
||
|
|
# Again renaming the attribute 'Type' which is a secondo keyword and
|
||
|
|
# removing superfluous blanks From PointType
|
||
|
|
let PointsRel =
|
||
|
|
PointsTmp feed
|
||
|
|
reNameattr [PointType: "Type",OsmId: "Osm_id"]
|
||
|
|
projectextend [OsmId,Timestamp,Name,GeoData;
|
||
|
|
PointType: Tostring(replace(.PointType, " ", ""))]
|
||
|
|
filter [isdefined(.PointType)]
|
||
|
|
addcounter[PointId,1]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Adding indexes for faster access
|
||
|
|
derive PointsRel_PointId_btree =
|
||
|
|
PointsRel createbtree[PointId];
|
||
|
|
derive PointsRel_GeoData_rtree =
|
||
|
|
PointsRel creatertree[GeoData];
|
||
|
|
|
||
|
|
# Grouping Streets by Name
|
||
|
|
# GroupedStreetsTmp: rel{Name: string, numParts: int, Geo: line}
|
||
|
|
let GroupedStreetsTmp =
|
||
|
|
StreetsRel feed
|
||
|
|
project [StreetId,Name,GeoData]
|
||
|
|
filter [isdefined(.Name)]
|
||
|
|
extend [LineData: toline(.GeoData)]
|
||
|
|
sortby [Name]
|
||
|
|
groupby [Name;
|
||
|
|
numParts: group count,
|
||
|
|
Geo: group feed
|
||
|
|
aggregateB [LineData;
|
||
|
|
fun(L1:line,L2:line)
|
||
|
|
L1 union L2;
|
||
|
|
[const line value ()]]]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Adding an ID To the Grouped Streets
|
||
|
|
let GroupedStreetsRel =
|
||
|
|
GroupedStreetsTmp feed
|
||
|
|
sortby [Name]
|
||
|
|
addcounter [GroupedStreetsId,1]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Adding an index for faster access
|
||
|
|
derive GroupedStreetsRel_GroupedStreetsId_btree =
|
||
|
|
GroupedStreetsRel createbtree[GroupedStreetsId];
|
||
|
|
|
||
|
|
# Deleting help relation
|
||
|
|
delete GroupedStreetsTmp;
|
||
|
|
|
||
|
|
# Extending the Streets-relation with a foreign key attribute To the
|
||
|
|
# grouping-relation
|
||
|
|
let ExtStreetsRel =
|
||
|
|
(GroupedStreetsRel feed {a}
|
||
|
|
StreetsRel feed
|
||
|
|
hashjoin [Name_a,Name,99997]
|
||
|
|
projectextend [;
|
||
|
|
GroupedStreetsId : .GroupedStreetsId_a,
|
||
|
|
TmpStreetId: .StreetId])
|
||
|
|
StreetsRel feed
|
||
|
|
hashjoin [tmpStreetId,StreetId,99997]
|
||
|
|
extend [groupId: .GroupedStreetsId]
|
||
|
|
remove [TmpStreetId, GroupedStreetsId]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Adding indexes for faster access
|
||
|
|
derive ExtStreetsRel_StreetId_btree =
|
||
|
|
ExtStreetsRel createbtree[StreetId];
|
||
|
|
derive ExtStreetsRel_groupId_btree =
|
||
|
|
ExtStreetsRel createbtree[groupId];
|
||
|
|
derive ExtStreetsRel_Name_btree =
|
||
|
|
ExtStreetsRel createbtree[Name];
|
||
|
|
derive ExtStreetsRel_GeoData_rtree =
|
||
|
|
ExtStreetsRel creatertree[GeoData];
|
||
|
|
|
||
|
|
let RestrictionsHelp =
|
||
|
|
RestrictionsTmp feed
|
||
|
|
reNameattr [OsmFrom: "From", OsmTo: "To", OsmVia: "Via", OsmId: "Osm_id"]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Updating the References in the restrictions-relation so that the new
|
||
|
|
# artificial IDs are used instead of the original ones From Osm
|
||
|
|
# (for the crossing the geo data of the corresponding point is used
|
||
|
|
# instead of an ID as all none POI-related data was removed From
|
||
|
|
# the persistent Points-relation)
|
||
|
|
let RestrictionsRel =
|
||
|
|
((RestrictionsHelp feed
|
||
|
|
StreetsRel feed
|
||
|
|
project [OsmId,StreetId] {f}
|
||
|
|
hashjoin [OsmFrom,OsmId_f,99997]
|
||
|
|
extend [FromStreet: .StreetId_f]
|
||
|
|
remove [OsmId_f,StreetId_f])
|
||
|
|
StreetsRel feed
|
||
|
|
project [OsmId,StreetId] {t}
|
||
|
|
hashjoin [OsmTo,OsmId_t,99997]
|
||
|
|
extend [ToStreet: .StreetId_t]
|
||
|
|
remove [OsmId_t,StreetId_t])
|
||
|
|
PointsTmp feed
|
||
|
|
project [Osm_id,GeoData] {v}
|
||
|
|
hashjoin [OsmVia,Osm_id_v,99997]
|
||
|
|
extend [ViaPoint: .GeoData_v]
|
||
|
|
remove [Osm_id_v,GeoData_v,OsmFrom,OsmTo,OsmVia]
|
||
|
|
sortby [FromStreet,ToStreet]
|
||
|
|
addcounter[RestrictionId,1]
|
||
|
|
consume;
|
||
|
|
|
||
|
|
# Removing the help relations
|
||
|
|
delete PointsTmp;
|
||
|
|
delete RestrictionsHelp;
|
||
|
|
delete RestrictionsTmp;
|
||
|
|
|