Wednesday, 18 July 2012

Improved visualisation of GPS elevation data

Improved visualisation of GPS elevation data from bike-rides around South London:



Uses curveVertex instead of lines, nicer I think....the above is Streatham to New Cross...


code below:



/*visualises the elevation data from a .gpx file
 the data is 'cleaned' in my other programs.
 Dare 2012
 */


float[] as, lon, lat;
float x, y;
int index;
ArrayList thatXPos = new ArrayList(); //array for X
ArrayList thatYPos = new ArrayList(); //array for Y
//y in this case is elevation data
float lonMax, lonMin, latMax, latMin; //to be our min and max values


void setup() {
  size(258, 320);
  as = float(loadStrings("cleanfile.txt"));
  /*create this file in 'convertGPS.pde */
  background(0);


}




void draw() {
  background(0);

  ///you might have to adjust start and ends but this seems to work
  for (int i =0;i<as.length-2;i+=2) { //all the longitude every 3rd
    thatXPos.add(as[i]); //not used in thisversion


  ///you might have to adjust start and ends but this seems to work
  for (int i =1;i<as.length-1;i+=2) { //all the  Y latitude
    thatYPos.add(as[i]); //in this case elevation data
  }




  int len = thatXPos.size();
  int len2 = thatYPos.size();
  Float[] fa = new Float[len];
  Float[] fa2 = new Float[len2];
  float[] xPosCount = new float[len];
  float[] yPosCount = new float[len2];
  thatXPos.toArray(fa);
  thatYPos.toArray(fa2);




  for (int i =0;i< len; i++) {


    xPosCount[i] = fa[i];
  } 


  for (int i =0;i< len2; i++) {


    yPosCount[i] = fa2[i];
  } 






  lonMax =max(xPosCount);
  lonMin =min(xPosCount);


  latMax =max(yPosCount);
  latMin =min(yPosCount);




  beginShape();
  for (int index =0;index<len;index++) {
    x =xPosCount[index];
    y =yPosCount[index];




    //use the minimums and maximums to calculate map()
    float x1= map(x, lonMin, lonMax, 50, width-50);
    float y2= map(y, latMin, latMax, 20, height);






    stroke(#EDFF03);
    strokeWeight(3);
    fill(#55C127);
    curveVertex(index*5, y2); //smoother than vertex
    //  vertex(index*5, y2); //less smooth
  }
  endShape();
  fill(255);
  smooth();
  // text("Elevations of cycle ride: 18/07/12", 20,30);
}




void mousePressed() {


  save("elevation.gif");
}
//end

No comments:

Post a Comment