I am trying to visualize data from an Open Data web page. The data is parsed from an XML-file with geo coordinates (latitude and longitude).
I am trying to make this XML-reader universal through OOP, so that I can use it for other purposes for another time. At the moment the XML-reader works, but I am having a bit of a hard time appropriating classes and objects in the reader. In my case I want to make one function that splits the lat/long coordinates and converts them to pixels. Then I also want a function that draws a polygon where the specific coordinates are.
But before making an XML-reader class I have to know what constructor my XML-reader is going to have.
So my question: Is there a standard (and maybe also a simple) way to do this in Java?
My code looks like this:
The xml file is this one: https://www.dropbox.com/s/3p7l2mqr7fcjjrn/parkerudenbom.x ml
I am trying to make this XML-reader universal through OOP, so that I can use it for other purposes for another time. At the moment the XML-reader works, but I am having a bit of a hard time appropriating classes and objects in the reader. In my case I want to make one function that splits the lat/long coordinates and converts them to pixels. Then I also want a function that draws a polygon where the specific coordinates are.
But before making an XML-reader class I have to know what constructor my XML-reader is going to have.
So my question: Is there a standard (and maybe also a simple) way to do this in Java?
My code looks like this:
Code:
XML xml;
ArrayList coordinates;
void setup() {
coordinates=new ArrayList();
xml = loadXML("parkerudenbom.xml");
XML[] folder = xml.getChildren("Folder");
XML[] Placemark=folder[0].getChildren("Placemark");
println(Placemark.length);
for(int i = 0; i < Placemark.length; i++) {
XML[] Polygon=Placemark[i].getChildren("Polygon");
for(int j= 0; j < Polygon.length; j++) {
XML[] outerBoundaryIs=Polygon[j].getChildren("outerBoundaryIs");
XML[] LinearRing=outerBoundaryIs[0].getChildren("LinearRing");
XML[] coords = LinearRing[0].getChildren("coordinates");
coordinates.add(coords[0].getContent());
println(coords[0].getContent());
}
}
}
Comment