Wednesday 11 July 2012

get the raw gps data into new lines

Fisrt thing that is useful to do for my other two programs is get the data onto separate lines, then use the txt file in the converter program below that, yep, its a long process



//put the data we want on new lines save then convert with convertGPS.pde
String[] lines, array4;




void setup() {
  lines = loadStrings("test4.gpx");
  String str1 = join(lines, " "); //make into a string so we can split


  String[] array1 = split(str1, '>'); //remove '>'


  String str2 = join(array1, ""); //make into a string again
  String[] array2 = split(str2, '='); //remove = signs
  String str3 = join(array2, "\n");
  String[] array3 = split(str3, '>');
  String str4 = join(array3, '\n');
  array4= split(str4, '<');
  for (int i = 0; i < array4.length; i++) {


    println(array4[i]);
  }
}




void draw() {
}


void keyPressed() { // Press a key to save the data




  saveStrings("lines.txt", array4);
  exit(); // Stop the program
}




///Finally remove all empty new lines: found this on the Processing site, works perfectly:



String lines[];
String[] neww = new String[1];




void setup() {


  lines = loadStrings("gps.txt");
  for (int i = 0; i < lines.length; i++) 
  {
    if (!lines[i].equals("")) {
      neww = append(neww, lines[i]);
    }
  }
}




void draw() {
}


void keyPressed() {
  saveStrings("cleanfile.txt", neww); 
  exit();
}



No comments:

Post a Comment