-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchcnav_isoxml.html
More file actions
408 lines (348 loc) · 13.7 KB
/
chcnav_isoxml.html
File metadata and controls
408 lines (348 loc) · 13.7 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shapefile NAVLine → ISOXML (GGP/GPN/LSG)</title>
<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
<script src="https://unpkg.com/shpjs/dist/shp.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 0;
box-sizing: border-box;
}
h1, h3 {
color: #333;
text-align: center;
}
.container {
max-width: 900px;
margin: auto;
padding: 10px;
}
textarea, input[type="file"], button {
padding: 8px;
margin-bottom: 10px;
border-radius: 5px;
border: 1px solid #ccc;
width: 100%;
box-sizing: border-box;
}
textarea {
resize: vertical;
background-color: #d4e6f1;
font-family: monospace;
font-size: 12px;
}
button {
background-color: #5499c7;
color: white;
cursor: pointer;
}
button:hover {
background-color: #7fa92a;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
font-size: 0.9rem;
}
table, th, td {
border: 1px solid #ccc;
}
th, td {
padding: 4px 6px;
text-align: left;
}
.small-textarea {
height: 220px;
}
.options-row {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin: 10px 0 15px 0;
font-size: 0.9rem;
}
.options-row label {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
user-select: none;
}
.options-row input[type="checkbox"] {
width: auto;
}
</style>
</head>
<body>
<h1>Shapefile NAVLine → ISOXML (GuidanceGroup, opcionális boundary)</h1>
<div class="container">
<p>
Exportáljuk a CHCNAV-ban Farmok-at. Ez az SD kártya CHCNAV mappában lesz benne, azokat tömörítsük be egy zip fájlba.
</p>
<p>
Válassz ki egy ZIP fájlt, amely <strong>WGS84 (lat/lon)</strong> koordinátarendszerű,
vonalas shapefile-okat (LineString / MultiLineString) tartalmaz (pl. mappánként
<code>DefaultField/NavLine.shp</code> + <code>.dbf</code>).
</p>
<p>
A program az összes shapefile-ból egy <code>TASKDATA.XML</code>-t készít:
</p>
<ul>
<li>Minden shapefile → 1 <code>PFD</code> (Partfield, D="0")</li>
<li>Minden vonal → 1 <code>GGP</code> (GuidanceGroup) a PFD alatt</li>
<li>Minden <code>GGP</code>-ben 1 <code>GPN</code> (GuidancePattern) + 1 <code>LSG</code></li>
<li><code>GPN.B</code> = vonal neve (NAMEC/Name), <code>GPN.C</code>: "1" = AB, "3" = görbe</li>
<li><code>LSG A="5"</code>, hogy az AOG kód <code>LSG[@A='5']</code>-re megtalálja</li>
<li><code>PNT C=lat</code>, <code>D=lon</code> WGS84 fokban</li>
</ul>
<div class="options-row">
<label title="6.7-es FormFieldISOXML csak akkor enged fieldet létrehozni, ha van PLN A=1 boundary.">
<input type="checkbox" id="optBoundary" checked />
Külső határ készítése (PLN A=1) egy négyszög segítségével (szükséges az AgOpenGPS 6.7-es verziójához)
</label>
</div>
<p><strong>Forrás koordináta-rendszer:</strong> WGS84 (lat/lon fokban, nincs átszámítás)</p>
<input type="file" id="shapefileInput" accept=".zip" />
<button id="processBtn">ISOXML (TASKDATA.XML) generálása</button>
<div id="output"></div>
</div>
<script>
function escapeXmlAttr(str) {
return String(str)
.replace(/&/g, "&")
.replace(/"/g, """)
.replace(/</g, "<")
.replace(/>/g, ">");
}
document.getElementById("processBtn").addEventListener("click", async () => {
const fileInput = document.getElementById("shapefileInput");
const file = fileInput.files[0];
const output = document.getElementById("output");
output.innerHTML = "";
if (!file) {
output.textContent = "Tölts fel egy shapefile ZIP-et (benne .shp + .dbf párokkal).";
return;
}
const generateBoundary = document.getElementById("optBoundary").checked;
try {
const zip = await JSZip.loadAsync(file);
// baseName (relatív útvonal kiterjesztés nélkül) → { shpPromise, dbfPromise, path }
const shpMap = new Map();
zip.forEach((relativePath, zipEntry) => {
const lower = relativePath.toLowerCase();
if (!lower.endsWith(".shp") && !lower.endsWith(".dbf")) return;
const base = lower.replace(/\.shp$|\.dbf$/i, "");
if (!shpMap.has(base)) {
shpMap.set(base, { shpPromise: null, dbfPromise: null, path: relativePath });
}
const entry = shpMap.get(base);
if (lower.endsWith(".shp")) {
entry.shpPromise = zipEntry.async("arraybuffer");
entry.path = relativePath; // eredeti case/útvonal megőrzése
} else if (lower.endsWith(".dbf")) {
entry.dbfPromise = zipEntry.async("arraybuffer");
}
});
let xml = `<?xml version="1.0" encoding="utf-8"?>\n`;
xml += `<ISO11783_TaskData VersionMajor="4" VersionMinor="3" ManagementSoftwareManufacturer="chc-navline-converter" ManagementSoftwareVersion="0.2" DataTransferOrigin="1">\n`;
let pfdCounter = 1;
let ggpCounter = 1;
let gpnCounterGlobal = 1;
let pntCounter = 1;
let totalFields = 0;
let totalLines = 0;
let totalPoints = 0;
let summaryTable =
"<h3>Beolvasott shapefile-ok</h3>" +
"<table><thead><tr>" +
"<th>#</th><th>Partfield (mappa)</th><th>Shapefile</th><th>Vonalak (GGP/GPN)</th><th>Pontok</th>" +
"</tr></thead><tbody>";
let fieldIndex = 1;
for (const [base, entry] of shpMap.entries()) {
if (!entry.shpPromise || !entry.dbfPromise) continue;
const [shpArrayBuffer, dbfArrayBuffer] = await Promise.all([
entry.shpPromise,
entry.dbfPromise
]);
const shapefileObj = { shp: shpArrayBuffer, dbf: dbfArrayBuffer };
const geojson = await shp(shapefileObj);
if (!geojson || !geojson.features || geojson.features.length === 0) {
continue;
}
// Partfield név: mappa neve (ha van), különben a shapefile neve
const pathParts = entry.path.split(/[\\/]/);
const fileName = pathParts[pathParts.length - 1];
const fileNameNoExt = fileName.replace(/\.shp$/i, "");
const partfieldName =
pathParts.length >= 3
? pathParts[pathParts.length - 3] // pl. "26-os vetés/DefaultField/NavLine.shp" → "26-os vetés"
: fileNameNoExt;
// Vonalak és bounding box kigyűjtése
const lineFeatures = [];
let latMin = +Infinity, latMax = -Infinity;
let lonMin = +Infinity, lonMax = -Infinity;
for (const feature of geojson.features) {
if (!feature.geometry) continue;
const geomType = feature.geometry.type;
const coords = feature.geometry.coordinates;
const nameProp =
feature.properties &&
(feature.properties.NAMEC || feature.properties.Name);
if (geomType === "LineString") {
if (!Array.isArray(coords) || coords.length === 0) continue;
lineFeatures.push({
name: nameProp || "",
coords: coords
});
for (const c of coords) {
if (!Array.isArray(c) || c.length < 2) continue;
const lon = Number(c[0]);
const lat = Number(c[1]);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) continue;
if (lat < latMin) latMin = lat;
if (lat > latMax) latMax = lat;
if (lon < lonMin) lonMin = lon;
if (lon > lonMax) lonMax = lon;
}
}
else if (geomType === "MultiLineString") {
if (!Array.isArray(coords)) continue;
for (const line of coords) {
if (!Array.isArray(line) || line.length === 0) continue;
lineFeatures.push({
name: nameProp || "",
coords: line
});
for (const c of line) {
if (!Array.isArray(c) || c.length < 2) continue;
const lon = Number(c[0]);
const lat = Number(c[1]);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) continue;
if (lat < latMin) latMin = lat;
if (lat > latMax) latMax = lat;
if (lon < lonMin) lonMin = lon;
if (lon > lonMax) lonMax = lon;
}
}
}
}
if (lineFeatures.length === 0) {
// Ebben a shapefile-ben nincs vonalgeometria
continue;
}
const pfdId = pfdCounter++;
totalFields++;
let fieldLineCount = 0;
let fieldPointCount = 0;
// PFD: D kötelező (6.7-ben közvetlenül kiolvassák), tegyünk bele "0"-t
xml += ` <PFD A="${pfdId}" C="${escapeXmlAttr(partfieldName)}" D="0">\n`;
// Opcionális outer boundary a 6.7-es importhoz:
// PLN A="1" -> LSG A="1" -> PNT (WGS84 lat/lon fok)
if (generateBoundary && Number.isFinite(latMin) && Number.isFinite(lonMin)) {
// kis margó a bounding boxra (5%)
const marginLat = (latMax - latMin) * 0.05 || 0.0001;
const marginLon = (lonMax - lonMin) * 0.05 || 0.0001;
latMin -= marginLat;
latMax += marginLat;
lonMin -= marginLon;
lonMax += marginLon;
const bbPoints = [
[lonMin, latMin],
[lonMax, latMin],
[lonMax, latMax],
[lonMin, latMax],
[lonMin, latMin] // zárjuk a polygont
];
xml += ` <PLN A="1">\n`;
xml += ` <LSG A="1">\n`;
for (const [lon, lat] of bbPoints) {
xml += ` <PNT A="${pntCounter}" C="${lat.toFixed(7)}" D="${lon.toFixed(7)}"/>\n`;
pntCounter++;
totalPoints++;
fieldPointCount++;
}
xml += ` </LSG>\n`;
xml += ` </PLN>\n`;
}
// Guidance vonalak → GGP/GPN/LSG (mindkét AOG verzióhoz jó)
for (const lf of lineFeatures) {
const coords = lf.coords;
if (!coords || coords.length === 0) continue;
const isAB = coords.length === 2;
const lineType = isAB ? "1" : "3"; // 1 = AB, 3 = Curve
const gpnId = gpnCounterGlobal++;
const gpnName =
lf.name && lf.name.toString().trim().length > 0
? lf.name.toString().trim()
: `Line ${gpnId}`;
const ggpId = ggpCounter++;
xml += ` <GGP A="${ggpId}" B="${escapeXmlAttr(partfieldName)}">\n`;
xml += ` <GPN A="${gpnId}" B="${escapeXmlAttr(gpnName)}" C="${lineType}">\n`;
// LSG: A="5" → ezt várja mind a 6.7-es, mind a 6.8.x-es kód (LSG[@A='5'])
xml += ` <LSG A="5">\n`;
for (const c of coords) {
if (!Array.isArray(c) || c.length < 2) continue;
const lon = Number(c[0]);
const lat = Number(c[1]);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) continue;
xml += ` <PNT A="${pntCounter}" C="${lat.toFixed(7)}" D="${lon.toFixed(7)}"/>\n`;
pntCounter++;
totalPoints++;
fieldPointCount++;
}
xml += ` </LSG>\n`;
xml += ` </GPN>\n`;
xml += ` </GGP>\n`;
totalLines++;
fieldLineCount++;
}
xml += ` </PFD>\n`;
summaryTable += `<tr>
<td>${fieldIndex++}</td>
<td>${escapeXmlAttr(partfieldName)}</td>
<td>${escapeXmlAttr(fileNameNoExt)}</td>
<td>${fieldLineCount}</td>
<td>${fieldPointCount}</td>
</tr>`;
}
xml += `</ISO11783_TaskData>\n`;
summaryTable += "</tbody></table>";
if (totalFields === 0) {
output.innerHTML = "Nem találtam érvényes (shp+dbf) shapefile párokat a ZIP-ben, vagy nem tartalmaztak vonalakat.";
return;
}
const preview = xml.length > 8000 ? xml.substring(0, 8000) + "\n...\n[vágva]" : xml;
const html = `
<p><strong>Összesen ${totalFields} partfield, ${totalLines} guidance vonal és ${totalPoints} pont került az ISOXML-be.</strong></p>
${summaryTable}
<button id="downloadXmlBtn">TASKDATA.XML letöltése</button>
<h3>ISOXML előnézet (első pár KB)</h3>
<textarea class="small-textarea" readonly>${preview}</textarea>
`;
output.innerHTML = html;
document.getElementById("downloadXmlBtn").addEventListener("click", () => {
const blob = new Blob([xml], { type: "application/xml" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "TASKDATA.XML";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
} catch (err) {
console.error(err);
output.textContent = "Hiba történt a feldolgozás során: " + err.message;
}
});
</script>
</body>
</html>