Hi everyone,
I’m trying to visualize some journeys wich are encoded in XML files. These files give me the position (lattitude and longitude), the date/time, and some others informations that I don’t need.
I write a program to display the journey ; with points for all points marked, and a line between the points (its wheight depends on the time past between the two points). My purpose is to display a map of the journey in wich the attendance modify the saturation of the color of the line, and the time past during a portion of the course modify weight of the outline.
It’s not completely finished, but I have no idea on how to load all the XML in the same time for preload the max and min of the latitude, longitude, and time. I can find it easily for one XML, but only one…
I tried to put all my XML in an array ; but it’s not working due to methods used after. I thought i can load one after the other all my XML in order to find the bigger max/min of my variables, and then run the draw for display the drawing.
XML xml;
XML[] trackpoints;
double lat;
double lon;
float latitude1;
float longitude1;
float latitude;
float longitude;
float taille;
float Time;
float time2;
float[] time_spent;
String[] tstamp;
float minTime_spent;
float maxTime_spent;
double longMax;
double longMin;
double latMin;
double latMax;
//XML Persona1
/*Longmin= -1.5762523603616678
Longmax=-1.51827744
Latmin= 47.17566217418081
Latmax= 47.28254926 */
void setup() {
size(1350, 850);
xml = loadXML("2823481.xml");//loadXML("2823482.xml"),loadXML("2823483.xml",loadXML("2823484.xml"),loadXML("2823485.xml"),loadXML("2823486.xml");
//loadXML("2823479.xml");//loadXML("2823480.xml");//
trackpoints = xml.getChildren("trk")[0].getChildren("trkseg")[0].getChildren("trkpt");
longMax =-1.51827744 ;// trackpoints[0].getDouble("lon");
longMin= -1.5762523603616678;//trackpoints[0].getDouble("lon");
latMax =47.28254926;//trackpoints[0].getDouble("lat");
latMin = 47.17566217418081 ;// trackpoints[0].getDouble("lat");
String t1 = trackpoints[0].getChildren("time")[0].getContent();
tstamp = t1.split("T")[1].split("\\.")[0].split(":");
Time = float(tstamp[0])*3600 + float(tstamp[1])*60 + float(tstamp[2]);
time2 = float(tstamp[0])*3600 + float(tstamp[1])*60 + float(tstamp[2]);
time_spent = new float[trackpoints.length];
for (int i = 0; i < trackpoints.length; i++) {
lat = trackpoints[i].getDouble("lat");
lon = trackpoints[i].getDouble("lon");
String t = trackpoints[i].getChildren("time")[0].getContent();
// println(trackpoints[i]);
tstamp = t.split("T")[1].split("\\.")[0].split(":"); //get only the time
if (lon>longMax) { //parcourt les valeurs max et min de longitude et latitude, for the max/min of longitude...
longMax = lon;
//print("longmax=", longMax);
}
if (lon<longMin) {
// println("longmin=", longMin);
longMin = lon;
}
if (lat>latMax) { //parcourt les valeurs max et min de longitude et latitude, and the max/min of latitude
latMax = lat;
// print("LATMAX=", latMax);
}
if (lat<latMin) {
// println("LATMIN=", latMin);
latMin = lat;
}
Time = float(tstamp[0])*3600 + float(tstamp[1])*60 + float(tstamp[2]); // valeur de time unique, unique value of time in sec
time_spent[i] = Time-time2; //temps passé entre deux points, time spent between 2 points
time2 = Time; //récupère l'ancienne valeur de time, value n-1 of Time
// println("time_spent=",time_spent[i]);
longitude = (float)trackpoints[0].getDouble("lon");
latitude = (float)trackpoints[0].getDouble("lat");
// printArray(tstamp);
} //for trackpoints.length
println(lat, lon, "longMin et Max =", longMin, longMax, "latMin et Max =", latMin, latMax);
for (int i =0; i<time_spent.length; i++) {
if (time_spent[i]>maxTime_spent) {
maxTime_spent =time_spent[i];
}
if (time_spent[i]<minTime_spent) {
minTime_spent = time_spent[i];
}
}
println("min et maxtime =", minTime_spent, maxTime_spent);
latitude = map((float)lat, (float)latMin, (float)latMax, 50, width-50); //convert into the scale of the window
longitude = map((float)lon, (float)longMin, (float)longMax, 30, height-30); //for first line, to not connect it to the origin
latitude1 = latitude ;
longitude1 = longitude;
}
void draw() {
pushMatrix();
for (int i = 0; i < trackpoints.length; i++) {
lat = trackpoints[i].getDouble("lat");
lon = trackpoints[i].getDouble("lon");
String t = trackpoints[i].getChildren("time")[0].getContent();
tstamp = t.split("T")[1].split("\\.")[0].split(":");
taille = map(time_spent[i], minTime_spent, maxTime_spent, 1, 13);
latitude = map((float)lat, (float)latMin, (float)latMax, 50, width-50); //convert into the scale of the window
longitude = map((float)lon, (float)longMin, (float)longMax, 30, height-30);
println("latitude", i, "=", latitude, "//longitude", i, " =", longitude);
/* println("latitude1-latitude=",abs(latitude1-latitude));
println("longitude1-longitude",abs(longitude1-longitude));
*/
if ((abs(latitude1-latitude)<15) && (abs(longitude1-longitude)<15)) { //get together points that they're near
latitude = latitude1;
longitude =longitude1;
taille = map(time_spent[i-1], minTime_spent, maxTime_spent, 0.5, 10) + map(time_spent[i], minTime_spent, maxTime_spent, 0.5, 10);
println("point à ressembler");
}
stroke(120, 20, 0);
strokeWeight(taille); //weight depends on time past
line(latitude1, longitude1, latitude, longitude);
ellipse(latitude, longitude, taille, taille);
latitude1 = latitude ;
longitude1 = longitude;
}
popMatrix();
saveFrame("TESTxml.png");
}
Thanks !