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
| public static void EngrGPX(PTS[] ptsRep, String[] lstTrk) {
StringBuilder sB = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
+"<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"ChP\" version=\"1.1\""
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
+"<metadata><time>"+sdf.format(new Date())+"</time>"
+"<bounds minlat=\"";
int lLgn = str.length(); // Point pour connaître l'endroit où insérer les min et max
sB.append(str);
sB.append("\"/></metadata>");
for (int i = 0; i < ptsRep.length; i++) { //les Waypoints
minmax(ptsRep[i].lat, ptsRep[i].lon);
sB.append("<wpt lat=\"").append(ptsRep[i].lat).append("\" lon=\"").append(ptsRep[i].lon)
.append("\"><ele>").append(ptsRep[i].alti).append("</ele><name>").append(ptsRep[i].nom)
.append("</name><cmt></cmt><desc></desc><sym>").append(ptsRep[i].noIcon).append("</sym></wpt>");
}
sB.append("<trk>");
for (int i = 0; i < lstTrk.length; i++) { //Les traces qui sont dans un tableau de fichiers
sB.append("<name>").append(lstTrk[i].substring(0, lstTrk[i].length()-4)).append("</name><trkseg>"); // Suppression de l'extension du fichier
PTS[] ptsTrk = TRK.tblPtTrek(FCH.dirVal, lstTrk[i]);
for (int j = 0; j < ptsTrk.length; j++) { // Les points d'une trace
minmax(ptsTrk[j].lat, ptsTrk[j].lon);
sB.append("<trkpt lat=\"").append(ptsTrk[j].lat).append("\" lon=\"").append(ptsTrk[j].lon)
.append("\"><ele>").append(ptsTrk[j].alti).append("</ele>").append("</trkpt>");
}
sB.append("</trkseg>");
}
sB.append("</trk></gpx>");
sB.insert(lLgn, String.format(Locale.US, "%.6f", minLat)+"\" minlon=\""+String.format(Locale.US, "%.6f", minLon) // insertion des min et max
+"\" maxlat=\""+String.format(Locale.US, "%.6f", maxLat)+"\" maxlon=\""+String.format(Locale.US, "%.6f", maxLon));
BufferedWriter fchGPX = FCH.ouvreEnrg("Xport", ".gpx");
try {
fchGPX.write(sB.toString()); // Enregistrement de la chaîne
}
catch (IOException e) {
e.printStackTrace();
}
FCH.clotEnrg(fchGPX);
} |
Partager