String[] pieces;
String[] nums;
String[] hf = {// for hedder & footer
"", "", "", "", "", "", "", ""};
String[] fileName;
String x, y, z;
float maxLat, maxLng, maxH, minLat, minLng, minH;
float factorW, factorH;
float addZ;
void setup() {
String loadPath = selectInput();//select kml file
XMLElement kml = new XMLElement(this, loadPath);
//for the file name
String allPath[] = split(loadPath, "/");
fileName = split(allPath[allPath.length-1], ".");
//extract the "coordinates" content
XMLElement coordinates;
coordinates = kml.getChild("Document/Placemark/MultiGeometry/LineString/coordinates");
if(coordinates == null) coordinates = kml.getChild("Document/Placemark/LineString/coordinates");
//calculate maxmum & minimum
pieces = splitTokens(trim(coordinates.getContent()), " ");
nums = split(pieces[1], ',');
minLat = float(nums[0]);
minLng = float(nums[1]);
minH = float(nums[2]);
for (int i=1; i float(nums[0])) minLat = float(nums[0]);
if (maxLng < float(nums[1])) maxLng = float(nums[1]);
if (minLng > float(nums[1])) minLng = float(nums[1]);
if (maxH < float(nums[2])) maxH = float(nums[2]);
if (minH > float(nums[2])) minH = float(nums[2]);
}
//calculate factor
float w = maxLat - minLat;
float h = maxLng - minLng;
if(w > h) {
factorW = 1.0;
factorH = h / w;
}
else{
factorW = w / h;
factorH = 1.0;
}
}
void draw(){
String[] data = new String[pieces.length-1];
for(int i = 0; i < pieces.length-1; i++){
//mapping nums + generate gml data
nums = split(pieces[i], ',');
x = str(map(float(nums[0]), minLat, maxLat, 0.0, factorW));
y = str(1 - map(float(nums[1]), minLng, maxLng, 0.0, factorH));
addZ += float(nums[2])/100;
z = str(addZ);
data[i] = ""+x+""+y+""+z+"";
}
//add tags which is nessesary for .gml
for(int i = 0; i