Hi All,
I’m attempting to adapt some of the provided examples above to draw lines between the points in my XML data.
Here’s a sample of my XML data
<dataPoint>
<id>474781744</id>
<timestamp>7/12/2012 3:01</timestamp>
<longitude>147.388981</longitude>
<latitude>-36.356586</latitude>
</dataPoint>
<dataPoint>
<id>474781745</id>
<timestamp>7/12/2012 3:31</timestamp>
<longitude>147.390586</longitude>
<latitude>-36.3578</latitude>
</dataPoint>
And here’s what I’ve come up with for my sketch:
gpsPoint[] gpsPoints1;
XML xml;
PImage background;
float mapScreenWidth, mapScreenHeight;
void setup() {
size(3840, 2160);
background(255);
xml = loadXML("sheepData_001.xml");
background = loadImage("img/paddock.png");
mapScreenWidth = width;
mapScreenHeight = height;
image(background, 0, 0, mapScreenWidth, mapScreenHeight);
smooth();
XML[] point = xml.getChildren("dataPoint");
for (int i = 0; i < point.length; i++) {
XML idElement = point[i].getChild("id");
int event = idElement.getIntContent();
XML timeElement = point[i].getChild("timestamp");
String time = timeElement.getContent();
XML longElement = point[i].getChild("longitude");
float longitude = longElement.getFloatContent();
XML latElement = point[i].getChild("latitude");
float latitude = latElement.getFloatContent();
println(event + "," + time + "," + longitude + "," + latitude);
gpsPoints1 = new gpsPoint[point.length];
for (int a = 0; a < point.length-1; a++){
XML longData1 = point[a].getChild("longitude");
float pointLong1 = longData1.getFloatContent();
XML longData2 = point[a+1].getChild("longitude");
float pointLong2 = longData2.getFloatContent();
XML latData1 = point[a].getChild("latitude");
float pointLat1 = latData1.getFloatContent();
XML latData2 = point[a+1].getChild("latitude");
float pointLat2 = latData2.getFloatContent();
float mainx = map(pointLong1, 147.3538, 147.3922, 0, width);
float mainy = map(pointLat1, -36.3228, -36.3179, 0, height);
float mainx2 = map(pointLong2, 147.3538, 147.3922, 0, width);
float mainy2 = map(pointLat2, -36.3228, -36.3179, 0, height);
gpsPoints1[a] = new gpsPoint(mainx, mainy, mainx2, mainy2);
gpsPoints1[a].display();
}
}
println("num of points " + point.length);
}
void draw() {
}
class gpsPoint {
float prevX;
float prevY;
float newX;
float newY;
gpsPoint(float previousX, float previousY, float nextX, float nextY){
prevX = previousX;
prevY = previousY;
newX = nextX;
newY = nextY;
}
void display() {
stroke(0);
strokeWeight(2);
point(prevX, prevY);
line(prevX, prevY, newX, newY);
}
}
It seems to function okay, but the lines I’m getting don’t seem to fully represent the point data that I get by removing all of the secondary point grabbing and go back to just plotting lines from the data.
This image is a side by side of the points and then lines I’m getting.
Anyone notice anything that I’m doing in my code that would throw my lines off? I know there’s likely a better way to get the secondary points, but it’s working thus far in terms of running.
Thanks in advance