Repository navigation
Expand file tree
/
Copy pathgenerateKml.php
More file actions
105 lines (65 loc) · 1.92 KB
/
Copy pathgenerateKml.php
File metadata and controls
105 lines (65 loc) · 1.92 KB
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
<?php
require_once 'include.php';
use Symfony\Component\Yaml\Yaml;
list ($lines, $stationsUnique) = Yaml::Parse(stream_get_contents(STDIN));
foreach ($lines as $keyLine => $line)
{
foreach ($line['stations'] as $keyStation => $station)
{
foreach ($stationsUnique as $k => $v)
{
if ($v['origName'] == $station)
{
$lines[$keyLine]['stations'][$keyStation] = $v;
break;
}
}
}
}
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndentString("\t");
$xml->setIndent(true);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('kml');
$xml->writeAttribute('xmlns', 'http://www.opengis.net/kml/2.2');
$xml->startElement('Document');
$xml->writeElement('name', 'Railway stations');
$xml->startElement('Style');
$xml->writeAttribute('id', 'RS');
$xml->startElement('LineStyle');
$xml->writeElement('color', '000000');
$xml->writeElement('width', '15');
$xml->endElement(); // LineStyle
$xml->endElement(); // Style
foreach ($lines as $line)
{
$xml->startElement('Folder');
$xml->writeElement('name', $line['name']);
$xml->writeElement('description', $line['name']);
foreach ($line['stations'] as $station)
{
$xml->startElement('Placemark');
$xml->writeElement('name', $station['name']);
$xml->writeElement('description', $station['name']);
$xml->startElement('Point');
$xml->writeElement('coordinates', sprintf('%f,%f', $station['lng'], $station['lat']));
$xml->endElement(); // Point
$xml->endElement(); // Placemark
}
$xml->startElement('Placemark');
$xml->startElement('LineString');
$xml->startElement('coordinates');
foreach ($line['stations'] as $station)
{
$xml->text(sprintf('%f,%f ', $station['lng'], $station['lat']));
}
$xml->endElement(); // coordinates
$xml->endElement(); // LineString
$xml->endElement(); // Placemark
$xml->endElement(); // Folder
}
$xml->endElement(); // Document
$xml->endElement(); // kml
$xml->endDocument();
echo $xml->flush();