-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmcosm.php
129 lines (110 loc) · 3.46 KB
/
tmcosm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
include_once('tmcpdo.php');
function osm_tags($data)
{
$tags = array();
$country = find_country($data['cid']);
$tags['table'] = $data['cid'] . ":" . $data['tabcd'];
$tags['lcd'] = $data['lcd'];
$tags['class'] = $data['class'] . $data['tcd'] . "." . $data['stcd'];
if($country)
$tags['version'] = $country['version'];
if($data['class'] == 'P')
{
$tags['type'] = "tmc:point";
if($data['n1id'])
{
$tags['name'] = $data['n1id'];
if($data['cid'] == 58)
$tags['name'] = preg_replace('/([[:alpha:]]+)([[:digit:]])/', '$1 $2', $tags['name']);
}
if($data['n2id'])
{
$tags['intersects'] = $data['n2id'];
if($data['cid'] == 58)
$tags['intersects'] = preg_replace('/([[:alpha:]]+)([[:digit:]])/', '$1 $2', $tags['intersects']);
}
if($data['rnid'] != "")
$tags['road_name'] = $data['rnid'];
if($data['junctionnumber'])
$tags['junction_ref'] = $data['junctionnumber'];
if($data['pol_lcd'])
$tags['area_lcd'] = $data['pol_lcd'];
if($data['oth_lcd'])
$tags['area_lcd'] = $data['oth_lcd'];
if($data['seg_lcd'])
$tags['seg_lcd'] = $data['seg_lcd'];
if(array_key_exists('pos_off_lcd', $data) && $data['pos_off_lcd'])
$tags['pos_offset'] = $data['pos_off_lcd'];
if(array_key_exists('neg_off_lcd', $data) && $data['neg_off_lcd'])
$tags['neg_offset'] = $data['neg_off_lcd'];
if($data['presentpos'] && !$data['presentneg'])
$tags['present'] = 'positive';
else if($data['presentneg'] && !$data['presentpos'])
$tags['present'] = 'negative';
if(($data['seg_lcd'] && ($rs = find_location('segments', $data['cid'], $data['tabcd'], $data['seg_lcd']))) || ($data['roa_lcd'] && ($rs = find_location('roads', $data['cid'], $data['tabcd'], $data['roa_lcd']))))
{
if($rs['roadnumber'])
{
$tags['road_ref'] = $rs['roadnumber'];
if($data['cid'] == 58)
$tags['road_ref'] = preg_replace('/([[:alpha:]]+)([[:digit:]])/', '$1 $2', $tags['road_ref']);
}
}
if($road = find_road($data))
$tags['road_lcd'] = $road['lcd'];
}
else if($data['class'] == 'A')
{
$tags['type'] = "tmc:area";
if($data['nid'] != "")
$tags['name'] = $data['nid'];
if($data['pol_lcd'])
$tags['area_lcd'] = $data['pol_lcd'];
}
return $tags;
}
function link_tags($data, $dir)
{
$tags = array();
$country = find_country($data['cid']);
if($data['class'] == 'P')
{
$tags['type'] = "tmc:link";
$tags['table'] = $data['cid'] . ":" . $data['tabcd'];
$tags['pos_lcd'] = $data[($dir ? 'pos_off_lcd' : 'lcd')];
$tags['neg_lcd'] = $data[($dir ? 'lcd' : 'neg_off_lcd')];
if($country)
$tags['version'] = $country['version'];
if($road = find_road($data))
$tags['road_lcd'] = $road['lcd'];
}
return $tags;
}
function create_relation($tags)
{
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$osm = $xml->createElement('osm');
$osm->setAttribute('version', "0.6");
$osm->setAttribute('upload', "true");
$osm->setAttribute('generator', "TMC import helper");
$xml->appendChild($osm);
$rel = $xml->createElement('relation');
$rel->setAttribute('id', -1);
$rel->setAttribute('action', "create");
$rel->setAttribute('visible', "true");
$osm->appendChild($rel);
foreach($tags as $key => $value)
{
if($value)
{
$tag = $xml->createElement('tag');
$tag->setAttribute('k', $key);
$tag->setAttribute('v', $value);
$rel->appendChild($tag);
}
}
return $xml->saveXML();
}
?>