回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,257 +1,129 @@
|
|
1
1
|
> 複数のPlacemarkのラグを保持したKMLファイルを作りたいです。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
タグですかね?
|
6
|
-
|
7
4
|
KMLについてまったくわかっていませんが、こうなればいいんでしょうか?(固定値で関係ない部分は省略)
|
8
|
-
|
9
5
|
```xml
|
10
|
-
|
11
6
|
<?xml version="1.0" encoding="utf-8"?>
|
12
|
-
|
13
7
|
<kml xmlns="http://www.opengis.net/kml/2.2">
|
14
|
-
|
15
8
|
<Document>
|
16
|
-
|
17
9
|
<Folder>
|
18
|
-
|
19
10
|
<Placemark>
|
20
|
-
|
21
11
|
<LookAt>
|
22
|
-
|
23
12
|
<longitude>135</longitude>
|
24
|
-
|
25
13
|
<latitude>35</latitude>
|
26
|
-
|
27
14
|
<altitude>17</altitude>
|
28
|
-
|
29
15
|
</LookAt>
|
30
|
-
|
31
16
|
<Point>
|
32
|
-
|
33
17
|
<coordinates>135,35,17</coordinates>
|
34
|
-
|
35
18
|
</Point>
|
36
|
-
|
37
19
|
</Placemark>
|
38
|
-
|
39
20
|
<Placemark>
|
40
|
-
|
41
21
|
<LookAt>
|
42
|
-
|
43
22
|
<longitude>132</longitude>
|
44
|
-
|
45
23
|
<latitude>35</latitude>
|
46
|
-
|
47
24
|
<altitude>17</altitude>
|
48
|
-
|
49
25
|
</LookAt>
|
50
|
-
|
51
26
|
<Point>
|
52
|
-
|
53
27
|
<coordinates>132,35,17</coordinates>
|
54
|
-
|
55
28
|
</Point>
|
56
|
-
|
57
29
|
</Placemark>
|
58
|
-
|
59
30
|
<Placemark>
|
60
|
-
|
61
31
|
<LookAt>
|
62
|
-
|
63
32
|
<longitude>131</longitude>
|
64
|
-
|
65
33
|
<latitude>35</latitude>
|
66
|
-
|
67
34
|
<altitude>17</altitude>
|
68
|
-
|
69
35
|
</LookAt>
|
70
|
-
|
71
36
|
<Point>
|
72
|
-
|
73
37
|
<coordinates>131,35,17</coordinates>
|
74
|
-
|
75
38
|
</Point>
|
76
|
-
|
77
39
|
</Placemark>
|
78
|
-
|
79
40
|
</Folder>
|
80
|
-
|
81
41
|
</Document>
|
82
|
-
|
83
42
|
</kml>
|
84
|
-
|
85
43
|
```
|
86
44
|
|
87
|
-
|
88
|
-
|
89
45
|
だとして、
|
90
|
-
|
91
46
|
方針としては`Placemark`以外の部分をまず作ってしまいます。
|
92
|
-
|
93
47
|
その後`Folder`を取得し、必要分`Placemark`を追加します。
|
94
48
|
|
95
|
-
|
96
|
-
|
97
|
-
```
|
49
|
+
```cs
|
98
|
-
|
99
50
|
using System.Linq;
|
100
|
-
|
101
51
|
using System.Xml.Linq;
|
102
52
|
|
103
|
-
|
104
|
-
|
105
53
|
namespace Questions337759
|
106
|
-
|
107
54
|
{
|
108
|
-
|
109
55
|
class Place
|
110
|
-
|
111
56
|
{
|
112
|
-
|
113
57
|
public string Lon;
|
114
|
-
|
115
58
|
public string Lat;
|
116
|
-
|
117
59
|
public string Alt;
|
118
60
|
|
119
|
-
|
120
|
-
|
121
61
|
public Place(string lon, string lat, string alt)
|
122
|
-
|
123
62
|
=> (Lon, Lat, Alt) = (lon, lat, alt);
|
124
63
|
|
125
|
-
|
126
|
-
|
127
64
|
public override string ToString() => $"{Lon},{Lat},{Alt}";
|
128
|
-
|
129
65
|
}
|
130
66
|
|
131
|
-
|
132
|
-
|
133
67
|
class Program
|
134
|
-
|
135
68
|
{
|
136
|
-
|
137
69
|
static void Main()
|
138
|
-
|
139
70
|
{
|
140
|
-
|
141
71
|
var placelist = new Place[] {
|
142
|
-
|
143
72
|
new Place("135", "35", "17"),
|
144
|
-
|
145
73
|
new Place("132", "35", "17"),
|
146
|
-
|
147
74
|
new Place("131", "35", "17")
|
148
|
-
|
149
75
|
};
|
150
76
|
|
151
|
-
|
152
|
-
|
153
77
|
var xml = CreateKml(placelist);
|
154
|
-
|
155
78
|
xml.Save(@"KMLSample01.kml");
|
156
|
-
|
157
79
|
}
|
158
80
|
|
159
|
-
|
160
|
-
|
161
81
|
private static XDocument CreateKml(Place[] placelist)
|
162
|
-
|
163
82
|
{
|
164
|
-
|
165
83
|
XNamespace ns = "http://www.opengis.net/kml/2.2";
|
166
84
|
|
167
|
-
|
168
|
-
|
169
85
|
var xml = new XDocument(
|
170
|
-
|
171
86
|
new XDeclaration("1.0", "utf-8", "true"),
|
172
|
-
|
173
87
|
new XElement(ns + "kml",
|
174
|
-
|
175
88
|
new XAttribute("xmlns", ns),
|
176
|
-
|
177
89
|
new XElement(ns + "Document",
|
178
|
-
|
179
90
|
new XElement(ns + "name", "KMLSample.kml"),
|
180
|
-
|
181
91
|
new XElement(ns + "open", "1"),
|
182
|
-
|
183
92
|
new XElement(ns + "Style",
|
184
|
-
|
185
93
|
new XElement(ns + "IconStyle",
|
186
|
-
|
187
94
|
new XElement(ns + "scale", "3")),
|
188
|
-
|
189
95
|
new XElement(ns + "LabelStyle",
|
190
|
-
|
191
96
|
new XElement(ns + "scale", "5"))),
|
192
|
-
|
193
97
|
new XElement(ns + "Folder",
|
194
|
-
|
195
98
|
new XElement(ns + "name", "Kyoto sample"),
|
196
|
-
|
197
99
|
new XElement(ns + "open", "1")))));
|
198
|
-
|
199
|
-
|
200
100
|
|
201
101
|
var folder = xml.Descendants(ns + "Folder").First();
|
202
102
|
|
203
|
-
|
204
|
-
|
205
103
|
foreach (var place in placelist)
|
206
|
-
|
207
104
|
{
|
208
|
-
|
209
105
|
var placemark = new XElement(ns + "Placemark",
|
210
|
-
|
211
106
|
new XElement(ns + "name", "Somewhere of Kyoto"),
|
212
|
-
|
213
107
|
new XElement(ns + "description", "Here is Kyoto"),
|
214
|
-
|
215
108
|
new XElement(ns + "LookAt",
|
216
|
-
|
217
109
|
new XElement(ns + "longitude", place.Lon),
|
218
|
-
|
219
110
|
new XElement(ns + "latitude", place.Lat),
|
220
|
-
|
221
111
|
new XElement(ns + "altitude", place.Alt),
|
222
|
-
|
223
112
|
new XElement(ns + "heading", "0"),
|
224
|
-
|
225
113
|
new XElement(ns + "tilt", "0"),
|
226
|
-
|
227
114
|
new XElement(ns + "range", "1304.699887442112"),
|
228
|
-
|
229
115
|
new XElement(ns + "altitudeMode", "absolute")),
|
230
|
-
|
231
116
|
new XElement(ns + "Point",
|
232
|
-
|
233
117
|
new XElement(ns + "coordinates", place)));
|
234
118
|
|
235
|
-
|
236
|
-
|
237
119
|
folder.Add(placemark);
|
238
|
-
|
239
120
|
}
|
240
121
|
|
241
|
-
|
242
|
-
|
243
122
|
return xml;
|
244
|
-
|
245
123
|
}
|
246
|
-
|
247
124
|
}
|
248
|
-
|
249
125
|
}
|
250
|
-
|
251
126
|
```
|
252
127
|
|
253
|
-
|
254
|
-
|
255
128
|
説明が足りないとは思うのですが、hangil700さんがどこまでわかっているかがわからないので不明点があればコメントしてください。
|
256
|
-
|
257
129
|
説明を追加します。
|