Increasing scale of plotted GPS points

edited October 2014 in Questions about Code

Hello,

I have plotted the GPS coordinates of the 21 stages of the Tour De France, this is the first time i've done anything like this and I am struggling to understand how I can 'enlarge' the cluster of lines plotted. The current output looks like this:

Image and video hosting by TinyPic

and the code is:

import processing.pdf.*;
import tomc.gpx.*;
GPX gpx;

String numbers[] = {
  "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"
};

float x;
float y;

String stageName;

void setup() {
  size(3508, 2480, PDF, "tdfMountains.pdf");
  background(30, 39, 40);
  noLoop();
}

void draw() {
  translate(width/2, height/2);
  rotate(radians(270));
  plotPoints();
  exit();
}


void plotPoints() {

  for (int q = 0; q<= 20; q++) {



    gpx = new GPX(this);
    gpx.parse("stage"+ numbers[q] +".gpx");


    for (int i = 0; i < gpx.getTrackCount(); i++) {

      GPXTrack trk = gpx.getTrack(i);



      for (int j = 0; j < trk.size(); j++) {

        GPXTrackSeg trkseg = trk.getTrackSeg(j);

        for (int k = 0; k < trkseg.size(); k++) {


          GPXPoint pt = trkseg.getPoint(k);

          double correctedLat = pt.lat;
          double correctedLon = pt.lon; 


          x = new Float(correctedLat * (width/180));
          y = new Float(correctedLon * (height/180) );

          println("y= "+y);
          stroke(255);
          strokeWeight(0.7);
          point(x, y);
        }
      }
      fill(255, 50, 2, 140);
      text("Stage " + stageName, x, y);
    }
  }
}

Thanks!

Tagged:

Answers

  • Answer ✓

    I suggest that you use the map function

    e.g.

    x = map(x, minX, maxX, 0, width);
    y = map(y, minY, maxY, 0, height);
    

    Where minX, maxX, minY and maxY are the limits for your GPS data. You will need to tweak these values to get exactly what you need.

Sign In or Register to comment.