use of dr.app.phylogeography.tools.kml.Location in project beast-mcmc by beast-dev.
the class TreeDensityKML method generateKMLTree.
private Element generateKMLTree(String name, RootedTree tree) {
Element element = generateContainer("Folder", name, null, null);
double longNoise = Random.nextGaussian() * 0.5;
double latNoise = Random.nextGaussian() * 0.5;
int nodeNumber = 0;
for (Node node : tree.getNodes()) {
nodeNumber++;
if (!tree.isRoot(node)) {
String state = (String) node.getAttribute(STATE_ATTRIBUTE_NAME);
Location location = locationMap.get(state);
if (location == null) {
throw new RuntimeException("No location called " + state + " in location list");
}
// Create each branch of the tree..
String nodeName = name + "_node" + nodeNumber;
Node parentNode = tree.getParent(node);
String parentState = (String) parentNode.getAttribute(STATE_ATTRIBUTE_NAME);
Location parentLocation = locationMap.get(parentState);
if (parentLocation == null) {
throw new RuntimeException("No location called " + parentState + " in location list");
}
Element branch = generateContainer("Placemark", nodeName, null, null);
// annotateBranch(element, height, startDate, finishDate, rate, support);
Element lineString = new Element("LineString");
lineString.addContent(generateElement("altitudeMode", "clampToGround"));
Element coordinates = new Element("coordinates");
coordinates.addContent("" + (parentLocation.getLongitude() + longNoise) + "," + (parentLocation.getLatitude() + latNoise) + "\r");
coordinates.addContent("" + (location.getLongitude() + longNoise) + "," + (location.getLatitude() + latNoise) + "\r");
lineString.addContent(coordinates);
branch.addContent(lineString);
element.addContent(branch);
}
}
return element;
}
use of dr.app.phylogeography.tools.kml.Location in project beast-mcmc by beast-dev.
the class TreeDensityKML method readCoordinates.
private static Map<String, Location> readCoordinates(String fileName) {
Map<String, Location> locationMap = new HashMap<String, Location>();
try {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line = reader.readLine();
while (line != null && line.trim().length() > 0) {
String[] parts = line.split("\t");
Location location;
if (parts.length == 4) {
location = new Location(parts[0], parts[1], Double.parseDouble(parts[2]), Double.parseDouble(parts[3]));
} else if (parts.length == 3) {
location = new Location(parts[0], parts[0], Double.parseDouble(parts[1]), Double.parseDouble(parts[2]));
} else {
throw new RuntimeException("Wrong number of columns in coordinates file");
}
locationMap.put(location.getState(), location);
line = reader.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return locationMap;
}