Load several XML to analyse them

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 !

1 Like

Can you share a simple example of one of your XML files? You can leave out some of the information you don’t need if there is a lot – just provide a valid XML file with the information you do need in it.

Of course. I can’t upload an XML so you’ll have to make it with this :slight_smile:

<gpx version="1.0" creator="GPSLogger 97 - http://gpslogger.mendhak.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"><time>2018-10-12T22:01:28.000Z</time><trk><trkseg><trkpt lat="47.20349425744051" lon="-1.5695211822085458"><ele>33.999796711839736</ele><time>2018-10-12T22:01:28.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>11</sat><hdop>0.861</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20371054298847" lon="-1.5694389628583754"><ele>57.21704855095595</ele><time>2018-10-12T22:02:15.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>14</sat><hdop>0.735</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20369311292399" lon="-1.5695292282368303"><ele>66.10760809760541</ele><time>2018-10-12T22:02:43.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>0.985</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.203935751806995" lon="-1.5694116571391599"><ele>70.85451869852841</ele><time>2018-10-12T22:03:10.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.814</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.203935751806995" lon="-1.5694116571391599"><ele>70.85451869852841</ele><time>2018-10-12T22:03:31.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>0.790</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.203861288580704" lon="-1.5694306841843788"><ele>69.329120606184</ele><time>2018-10-12T22:03:53.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>14</sat><hdop>0.735</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20387304454464" lon="-1.5695063800267262"><ele>74.26585341989994</ele><time>2018-10-12T22:05:04.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>11</sat><hdop>0.953</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20373585466371" lon="-1.5694305205958627"><ele>72.83865458704531</ele><time>2018-10-12T22:05:31.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>0.777</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20371101219211" lon="-1.5694651007220544"><ele>91.7788194520399</ele><time>2018-10-12T22:06:23.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>13</sat><hdop>0.776</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20375478030817" lon="-1.569513783721165"><ele>60.33738913293928</ele><time>2018-10-12T22:07:04.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>0.911</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20363023371362" lon="-1.5693978148721213"><ele>68.00777916237712</ele><time>2018-10-12T22:07:31.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>1.025</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.203753312394724" lon="-1.5694790437195074"><ele>73.5576301086694</ele><time>2018-10-12T22:08:09.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>0.872</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20380123644595" lon="-1.569499838261445"><ele>70.38934893067926</ele><time>2018-10-12T22:08:39.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20417194005279" lon="-1.5647295398780667"><ele>54.09139933809638</ele><time>2018-10-12T22:12:43.000Z</time><course>87.229355</course><speed>1.4427516</speed><src>gps</src><sat>19</sat><hdop>0.661</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20423308902389" lon="-1.5641281700012981"><ele>48.909449672326446</ele><time>2018-10-12T22:13:04.000Z</time><course>85.43315</course><speed>1.8634235</speed><src>gps</src><sat>18</sat><hdop>0.661</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20428129680647" lon="-1.5635735895118132"><ele>48.83859606273472</ele><time>2018-10-12T22:13:25.000Z</time><course>72.587585</course><speed>1.6670016</speed><src>gps</src><sat>20</sat><hdop>0.603</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20435423573269" lon="-1.5630550569587767"><ele>50.94407127890736</ele><time>2018-10-12T22:13:46.000Z</time><course>95.8904</course><speed>1.6306335</speed><src>gps</src><sat>19</sat><hdop>0.622</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.204321911282584" lon="-1.562484269935951"><ele>56.30207472573966</ele><time>2018-10-12T22:14:07.000Z</time><course>118.47932</course><speed>1.7754682</speed><src>gps</src><sat>20</sat><hdop>0.604</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20430927480848" lon="-1.5620230176793892"><ele>62.39413719251752</ele><time>2018-10-12T22:14:29.000Z</time><course>143.93993</course><speed>2.029855</speed><src>gps</src><sat>19</sat><hdop>0.616</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.20418340912657" lon="-1.5614913783283932"><ele>60.769500490278006</ele><time>2018-10-12T22:14:51.000Z</time><course>113.16143</course><speed>1.5904458</speed><src>gps</src><sat>19</sat><hdop>0.634</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.2040260176557" lon="-1.5609252708740888"><ele>55.63570551387966</ele><time>2018-10-12T22:15:14.000Z</time><course>91.62614</course><speed>2.1448538</speed><src>gps</src><sat>16</sat><hdop>0.715</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.205199349031055" lon="-1.5520433643283884"><ele>53.02610728237778</ele><time>2018-10-12T22:20:26.000Z</time><course>54.518406</course><speed>2.083961</speed><src>gps</src><sat>20</sat><hdop>0.609</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.2146453499986" lon="-1.5561459335476981"><ele>61.75346542429179</ele><time>2018-10-12T22:30:19.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.432</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.214752089428686" lon="-1.5559505374909395"><ele>55.98913097754121</ele><time>2018-10-12T22:30:50.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>5</sat><hdop>1.828</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21697418457949" lon="-1.5586074166907542"><ele>219.44619236513972</ele><time>2018-10-12T22:35:45.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>0.980</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.2180542943504" lon="-1.5573716684665466"><ele>250.6198966074735</ele><time>2018-10-12T22:36:13.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.052</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21711030656585" lon="-1.5569471893946347"><ele>55.56338410079479</ele><time>2018-10-12T22:36:40.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>11</sat><hdop>0.892</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21699755108639" lon="-1.5567996060110567"><ele>41.776507526636124</ele><time>2018-10-12T22:37:07.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>0.976</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21818594312145" lon="-1.5571219060853059"><ele>51.63474513310939</ele><time>2018-10-12T22:37:35.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.417</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21716851800992" lon="-1.5566079297158075"><ele>86.04924862552434</ele><time>2018-10-12T22:38:05.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>0.813</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21702047446489" lon="-1.5569418405441893"><ele>47.32080702576786</ele><time>2018-10-12T22:38:34.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>1.176</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.216814377204415" lon="-1.5568751293920997"><ele>50.24347150698304</ele><time>2018-10-12T22:39:02.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>0.974</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21714528397261" lon="-1.5572645622792702"><ele>-23.295903977937996</ele><time>2018-10-12T22:39:37.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>1.329</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21699558042582" lon="-1.5568657744905592"><ele>53.54862023238093</ele><time>2018-10-12T22:40:10.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>12</sat><hdop>1.170</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21740080911752" lon="-1.5573737344760057"><ele>33.82174093555659</ele><time>2018-10-12T22:41:11.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>8</sat><hdop>1.144</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21707256149581" lon="-1.5570581967939203"><ele>38.57736684754491</ele><time>2018-10-12T22:41:43.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>1.007</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.216835771005954" lon="-1.5572108524300152"><ele>46.88062702212483</ele><time>2018-10-12T22:42:45.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>1.131</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21685875276186" lon="-1.556659323451939"><ele>33.95603013969958</ele><time>2018-10-12T22:43:15.000Z</time><course>80.40472</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.417</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21692032324517" lon="-1.5567274269391531"><ele>33.83820783812553</ele><time>2018-10-12T22:44:00.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>1.728</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21712837364016" lon="-1.557122784534594"><ele>98.43395509012043</ele><time>2018-10-12T22:44:30.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>10</sat><hdop>1.163</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.2171290956127" lon="-1.5568148326290927"><ele>81.43958742264658</ele><time>2018-10-12T22:44:59.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>8</sat><hdop>1.305</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21696114484847" lon="-1.5568913480828828"><ele>85.95698602218181</ele><time>2018-10-12T22:45:59.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.605</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.21783450355703" lon="-1.5540710813533547"><ele>94.63379538897425</ele><time>2018-10-12T22:47:37.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>8</sat><hdop>1.603</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.218800264906626" lon="-1.5506279503387341"><ele>78.09365604817867</ele><time>2018-10-12T22:49:26.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>7</sat><hdop>1.999</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
<trkpt lat="47.247527254356015" lon="-1.5389095204687568"><ele>88.90477059688419</ele><time>2018-10-12T23:04:25.000Z</time><course>0.0</course><speed>0.0</speed><src>gps</src><sat>9</sat><hdop>1.521</hdop><ageofdgpsdata>0</ageofdgpsdata></trkpt>
</trkseg></trk></gpx>

It should give you this result.

Just highlight the code in your post and press the </> button to format it.

It’s done in the previous done. There is all the data I use in my sketch with some banners useless inside, but it’s not important.
I use only lat , lon and time for now

I thought that I can make an array instead of using my variable xml to put in all my xml and then call them one after to draw the journeys ; but an xml can’t be put in an aray…

to find working range can use like

XML xml; //,xml1, xml2;
XML[] trackpoints; //,trackpoints1, trackpoints2;
String file1="trip1.xml";
String file2="trip2.xml";

double lat, lon;
double longMax=-300, longMin=+300, latMax=-300, latMin=+300;  // some over range 

void setup() {

  load_file(file1);
  println("min max accumulated");
  load_file(file2);
// now you know your overall working range
// more of your code
}

void load_file(String file){
  xml = loadXML(file);
  trackpoints  = xml.getChildren("trk")[0].getChildren("trkseg")[0].getChildren("trkpt");
  // check data
  for (int i = 0; i < trackpoints.length; i++) {
    lat = trackpoints[i].getDouble("lat");
    lon = trackpoints[i].getDouble("lon");
    minmax(lon, lat);
  }
  println("load "+file+" longMax "+longMax+" longMin "+longMin+" latMax "+latMax+" latMin "+latMin);
}

void minmax(double lon, double lat){
    if (lon>longMax) longMax = lon;
    if (lon<longMin) longMin = lon;
    if (lat>latMax)  latMax = lat;
    if (lat<latMin)  latMin = lat;
}

but that is working also if you use the
,xml1, xml2;
,trackpoints1, trackpoints2;
and you have all data stored

Thanks for your help @kll

So I did two distincts programs finaly (only for visibility) ; the first for find working range for polar coordinates, and then I manually put them in the second which draws.

For the first, using @kll code :

XML xml;
XML[] trackpoints; //,trackpoints1, trackpoints2;
String xml1 = "2823479.xml";
String xml2 = "2823480.xml";
String xml3 = "2823481.xml";
String xml4 = "2823482.xml";
String xml5 = "2823483.xml";
String xml6 = "2823484.xml";
String xml7 = "2823485.xml";
String xml8 = "2823486.xml";
String xml9 = "2817909.xml";
String xml10= "2816774.xml";
double lat, lon;
double longMax=-3, longMin=0, latMax=-3, latMin=50;
int Time;
int time2;
int[] time_spent;
String[] tstamp;
int minTime_spent; 
int maxTime_spent;


void setup() {

  // to know overall working range
  load_file(xml1);
  load_file(xml2);
  load_file(xml3);
  load_file(xml4);
  load_file(xml5);
  load_file(xml6);
  load_file(xml7);
  load_file(xml8);
  load_file(xml9);
  load_file(xml10);

  println("LongMax =", longMax, "  Longmin=", longMin, "  Latmax=", latMax, "  latMin=", latMin);
  println("time_spentMin= ", minTime_spent, " maxtimespent = ", maxTime_spent);
}

void load_file(String file) {
  xml = loadXML(file);
  trackpoints  = xml.getChildren("trk")[0].getChildren("trkseg")[0].getChildren("trkpt");
  time_spent = new int[trackpoints.length];
  // check data
  for (int i = 0; i < trackpoints.length; i++) {
    //gps data
    lat = trackpoints[i].getDouble("lat");
    lon = trackpoints[i].getDouble("lon");

    //time data
     String t = trackpoints[i].getChildren("time")[0].getContent();
    tstamp = t.split("T")[1].split("\\.")[0].split(":"); //get only the time
    Time = int(tstamp[0])*3600 +  int(tstamp[1])*60 + int(tstamp[2]); // valeur de time unique, unique value of time in sec
    time_spent[i] = Time-time2; // time spent between 2 points
    time2 = Time; // value n-1 of Time
  }
  minmax(lon, lat);
  println("load "+file+" longMax "+longMax+" longMin "+longMin+" latMax "+latMax+" latMin "+latMin);
}


//to find min/max
void minmax(double lon, double lat) {
  //gps data
  if (lon>longMax) longMax = lon;
  if (lon<longMin) longMin = lon;
  if (lat>latMax)  latMax = lat;
  if (lat<latMin)  latMin = lat;

  //time data
  for (int i =0; i < trackpoints.length; i++ ) {
    if (time_spent[i] > maxTime_spent) {
      maxTime_spent = time_spent[i];
    }
    if (time_spent[i] < minTime_spent) {
      minTime_spent = time_spent[i];
    }
  }
}

void draw() {
}

And then I draw in the second. I had to use arrays of double for store gps data, and because I had an error of OutOfBounds, I finally use a class (and receive some exterior help at this time) :

//  un classe qui stocke juste des valeurs
class Data {
  double lat;
  double lon;
  int time_spent;

  Data(double lat, double lon, int time_spent) {
    this.lat = lat;
    this.lon = lon;
    this.time_spent = time_spent;

wich is used in my function load_file to store my data.

    Data d = new Data(lat, lon, Time-time2);
    datas.add(d); // je l'ajoute à mon arrayList

It permits to display all my journeys I load in my sketch. It only remains to the final graphic aspect of my drawings. But the code is functional. I quickly cleaned up all the code I put in comment but there still are probably some useless lines…

XML xml;
XML[] trackpoints;
double[] everyLat ={};
double[] everyLon = new double[0] ;
int indexTrackpoints;
double lat; 
double lon;
float latitude1; 
float longitude1;
float latitude; 
float longitude;
float taille;
int Time;
int time2;
int[] time_spent ={};
String[] tstamp;
int minTime_spent; 
int maxTime_spent;
double longMax; 
double longMin;
double latMin;
double latMax;
String xml1 = "2823479.xml";
String xml2 = "2823480.xml";
String xml3 = "2823481.xml";
String xml4 = "2823482.xml";
String xml5 = "2823483.xml";
String xml6 = "2823484.xml";
String xml7 = "2823485.xml";
String xml8 = "2823486.xml";
String xml9 = "2817909.xml";
String xml10= "2816774.xml";

// un arrayList qui stocke toutes nos données
ArrayList <Data> datas = new ArrayList();

void setup() {
  size(1350, 850);
  // xml = loadXML("2823479.xml");//loadXML("2823482.xml");//,loadXML("2823483.xml");,loadXML("2823484.xml"),loadXML("2823485.xml"),loadXML("2823486.xml");
  //loadXML("2823480.xml");//
  // trackpoints  = xml.getChildren("trk")[0].getChildren("trkseg")[0].getChildren("trkpt");
  longMax =-1.5182774066925049  ;  // trackpoints[0].getDouble("lon");
  longMin= -1.5762523603616678;  //trackpoints[0].getDouble("lon");
  latMax = 47.28255081176758 ;  //trackpoints[0].getDouble("lat");
  latMin = 47.17566217418081 ;  // trackpoints[0].getDouble("lat");
  minTime_spent = -48248;
  maxTime_spent = 79288;
  indexTrackpoints = 0;

  //  time_spent = new float[trackpoints.length];
  /* Time = float(tstamp[0])*3600 +  float(tstamp[1])*60 + float(tstamp[2]);
   time2 = float(tstamp[0])*3600 +  float(tstamp[1])*60 + float(tstamp[2]);*/


  // to know gps data & time_spent 
  load_file(xml1);
  load_file(xml2);
  load_file(xml3);
  load_file(xml4);
  load_file(xml5);
  load_file(xml6);
  load_file(xml7);
  load_file(xml8);
  load_file(xml9);
  load_file(xml10);

  // verify data size
  println(datas.size());
}//setup


//store all gps from xml(s) in an array & time_spent in another
void load_file(String file) {
  xml = loadXML(file);
  trackpoints  = xml.getChildren("trk")[0].getChildren("trkseg")[0].getChildren("trkpt");

  for (int i = 0; i < trackpoints.length; i++) {
    //gps storage
    lat = trackpoints[i].getDouble("lat");
    lon = trackpoints[i].getDouble("lon");

    
    //time storage
    String t = trackpoints[0].getChildren("time")[0].getContent();
    tstamp = t.split("T")[1].split("\\.")[0].split(":");
    Time = int(tstamp[0])*3600 +  int(tstamp[1])*60 + int(tstamp[2]); // valeur de time unique, unique value of time in sec
    //append(time_spent, Time-time2); // time spent between 2 points
    
    //create data object w/ data collected in xml files
    // Je créée un objet data avec les données récoltées dans les fichiers xml
    Data d = new Data(lat, lon, Time-time2);
    datas.add(d); // add to my arrayList
   
    time2 = Time; // value n-1 of Time
  }
}


void draw() {
  pushMatrix();

  for (int i = 0; i < datas.size(); i++) { // on itère sur l'arraylist
  
    Data d = datas.get(i); // on récupère l'objet stocké à l'index i de l'arraylist
    
    // on récupère les données stockées dans l'objet "d"
    lat = d.lat;
    lon = d.lon;
    taille = map(d.time_spent, 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);

    //get together points that they're near 
    if ((abs(latitude1-latitude)<15) && (abs(longitude1-longitude)<15)) {
      latitude = latitude1;
      longitude =longitude1;
    }

    //draw
    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");
}


// class wich store data 
class Data {
  double lat;
  double lon;
  int time_spent;

  Data(double lat, double lon, int time_spent) {
    this.lat = lat;
    this.lon = lon;
    this.time_spent = time_spent;
  }
}
1 Like