parseLocation: parse fare zone, transit authority & more foreign stop IDs

closes #131
see also #5, #90
This commit is contained in:
Jannis R 2020-03-07 00:31:25 +01:00 committed by Jannis Redmann
parent 2a241375db
commit 3ea9380218
4 changed files with 44 additions and 3 deletions

View file

@ -1,5 +1,6 @@
'use strict' 'use strict'
const omit = require('lodash/omit')
const findInTree = require('../lib/find-in-tree') const findInTree = require('../lib/find-in-tree')
const parseCommonData = (_ctx) => { const parseCommonData = (_ctx) => {
@ -9,6 +10,7 @@ const parseCommonData = (_ctx) => {
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX', '**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX', '**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
'**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL', '**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
'**.msgL',
]); ]);
const common = {} const common = {}
@ -89,13 +91,29 @@ const parseCommonData = (_ctx) => {
}) })
} }
common.warnings = [] common.warnings = []
if (opt.remarks && Array.isArray(c.himL)) { if (Array.isArray(c.himL)) {
common.warnings = c.himL.map(w => profile.parseWarning(ctx, w)) common.warnings = c.himL.map(w => profile.parseWarning(ctx, w))
matches['**.himX'].forEach(([idx, parents]) => { matches['**.himX'].forEach(([idx, parents]) => {
if ('number' === typeof idx) parents[0].warning = common.warnings[idx] if ('number' === typeof idx) parents[0].warning = common.warnings[idx]
}) })
} }
// resolve .msgL[] references
const parseRemarkRef = (ref) => {
if (ref.type === 'REM' && ref.hint) {
return omit(ref, ['type', 'remX'])
}
if (ref.type === 'HIM' && ref.warning) {
return omit(ref, ['type', 'himX'])
}
return null
}
matches['**.msgL'].forEach(([refs, parents]) => {
parents[0].remarkRefs = refs
.map(parseRemarkRef)
.filter(ref => ref !== null)
})
common.polylines = [] common.polylines = []
if (opt.polylines && Array.isArray(c.polyL)) { if (opt.polylines && Array.isArray(c.polyL)) {
common.polylines = c.polyL.map(p => profile.parsePolyline(ctx, p)) common.polylines = c.polyL.map(p => profile.parsePolyline(ctx, p))

View file

@ -5,10 +5,12 @@ const codesByIcon = Object.assign(Object.create(null), {
}) })
const linkTypesByCode = Object.assign(Object.create(null), { const linkTypesByCode = Object.assign(Object.create(null), {
BB: 'stop-website',
// IFOPT-based DHID // IFOPT-based DHID
// https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT // https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT
// https://trid.trb.org/view/1435440 // https://trid.trb.org/view/1435440
IF: 'stop-dhid', IF: 'stop-dhid',
OZ: 'transit-authority',
// todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}` // todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}`
// todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}` // todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}`
}) })
@ -28,6 +30,9 @@ const parseHint = (ctx, h) => {
if (h.code in linkTypesByCode) { if (h.code in linkTypesByCode) {
return {type: linkTypesByCode[h.code], text: h.txtN} return {type: linkTypesByCode[h.code], text: h.txtN}
} }
if (h.code === 'TW' && h.txtN[0] === '$') {
return {type: 'local-fare-zone', text: h.txtN.slice(1)}
}
if (h.code === 'TW' && h.txtN[0] === '#') { if (h.code === 'TW' && h.txtN[0] === '#') {
return {type: 'foreign-id', text: h.txtN.slice(1)} return {type: 'foreign-id', text: h.txtN.slice(1)}
} }

View file

@ -38,9 +38,22 @@ const parseLocation = (ctx, l) => {
stop.lines = l.lines stop.lines = l.lines
} }
const hints = l.hints || [] const locHints = (l.remarkRefs || [])
.filter(ref => !!ref.hint && Array.isArray(ref.tagL))
.filter(({tagL}) => (
tagL.includes('RES_LOC') ||
tagL.find(t => t.slice(0, 8) === 'RES_LOC_') // e.g. `RES_LOC_H3`
))
.map(ref => ref.hint)
const hints = [
...(l.hints || []),
...locHints,
]
const byType = type => hints.find(h => h.type === type) const byType = type => hints.find(h => h.type === type)
const transitAuthority = (byType('transit-authority') || {}).text
if (transitAuthority) stop.transitAuthority = transitAuthority
const dhid = (byType('stop-dhid') || {}).text const dhid = (byType('stop-dhid') || {}).text
if (dhid) { if (dhid) {
if (!stop.ids) stop.ids = {} if (!stop.ids) stop.ids = {}

View file

@ -3,6 +3,10 @@
module.exports = { module.exports = {
type: 'stop', type: 'stop',
id: '8011155', id: '8011155',
ids: {
dhid: 'de:11000:900100003',
VBB: '900100003'
},
name: 'Berlin Alexanderplatz', name: 'Berlin Alexanderplatz',
location: { location: {
type: 'location', type: 'location',
@ -21,5 +25,6 @@ module.exports = {
subway: true, subway: true,
tram: true, tram: true,
taxi: false taxi: false
} },
transitAuthority: 'VBB',
} }