Store polygons from an xml list into polygon class with xy array
I have the following code that pulls polygon objects out of an xml document and draws them to the screen using the beginShape(), vertex(xMap, yMap), endShape(). I would like to put these objects into a Polygon class with the name of each polygon “the polygons are real building outlines with names” and an array for both the x and y coordinates. I want to due this because cycling through the xml document to draw my polygons kills the performance of my processing sketch and I’m thinking a class would be quicker. I’m not sure how to pass the data.
I would think it would be something like:
Polygon(name, xMap[], yMap[]);
void Draw_ESRI2XML()
{
float xWorld, yWorld, xMap, yMap;
XMLElement bldgsXML = new XMLElement(this,"Buildings.xml");
String names = bldgValues[5].getContent();//Pulls the name out of the xml
XMLElement[] bldgRecords = bldgsXML.getChildren("Data/Records/Record");
for (int i = 0; i < bldgRecords.length; i++)
{
XMLElement[] bldgValues = bldgRecords[i].getChildren("Values/Value");
XMLElement[] bldgCoords = bldgValues[1].getChildren("RingArray/Ring/PointArray/Point");
beginShape();
for (int j = 0; j < bldgCoords.length; j++)
{
xWorld = float(bldgCoords[j].getChild(0).getContent());
yWorld = float(bldgCoords[j].getChild(1).getContent());
xMap = map(xWorld, 6307107.02507646, 6311107.02507646, -width/2, width/2);
yMap = map(yWorld, 1864191.34421644, 1861191.34421644, -height/2, height/2);
vertex(xMap, yMap);
}
endShape();
}
}