A family friendly commit message updating the kml generator with

This commit is contained in:
Michael Peters 2019-11-02 15:30:49 -04:00
parent e54edd01c3
commit 9096723584
4 changed files with 97 additions and 4 deletions

19
data/test.kml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Polygon Placemark</name>
<description>This is a polygon</description>
<Polygon>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs><LinearRing><coordinates>
-1.000000,-1.000000
-1.000000,1.000000
0.000000,2.000000
1.000000,1.000000
1.000000,-1.000000
0.000000,-2.000000
</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
<Style><PolyStyle><color>#a00000ff</color><outline>0</outline></PolyStyle></Style>
</Placemark>
</kml>

View File

@ -1,7 +1,54 @@
package evac;
class KmlGenerator {
static String createKml(OutputModel model) {
public class KmlGenerator {
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
private static final String HEADER = "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
private static final String FOOTER = "</kml>\n";
public static String createKml(OutputModel model) {
return null; // convert the model to KML that can be displayed in Google Earth
}
public static String createKml(Position position) {
StringBuilder builder = new StringBuilder();
builder.append(XML_HEADER);
builder.append(HEADER);
builder.append("<Placemark>\n");
builder.append(" <name>Position Placemark</name>\n");
builder.append(" <description>This is a position</description>\n");
builder.append(" <Point>\n");
builder.append(String.format(" <coordinates>%f,%f</coordinates>\n", position.latitude, position.longitude));
builder.append(" </Point>\n");
builder.append("</Placemark>\n");
builder.append(FOOTER);
return builder.toString();
}
public static String createKml(Polygon polygon) {
StringBuilder builder = new StringBuilder();
builder.append(XML_HEADER);
builder.append(HEADER);
builder.append("<Placemark>\n");
builder.append(" <name>Polygon Placemark</name>\n");
builder.append(" <description>This is a polygon</description>\n");
builder.append(" <Polygon>\n");
builder.append(" <altitudeMode>clampToGround</altitudeMode>\n");
builder.append(" <outerBoundaryIs><LinearRing><coordinates>\n");
for (Position position : polygon.positions) {
builder.append(String.format(" %f,%f\n", position.latitude, position.longitude));
}
builder.append(" </coordinates></LinearRing></outerBoundaryIs>\n");
builder.append(" </Polygon>\n");
builder.append(" <Style><PolyStyle><color>#a00000ff</color><outline>0</outline></PolyStyle></Style>\n");
builder.append("</Placemark>\n");
builder.append(FOOTER);
return builder.toString();
}
}

27
src/evac/KmlTest.java Normal file
View File

@ -0,0 +1,27 @@
package evac;
import java.util.ArrayList;
import java.util.List;
public class KmlTest {
public static void main(String[] args) {
String kml;
//Position position = new Position(0, 0);
// kml = KmlGenerator.createKml(position);
// System.out.print(kml);
List<Position> polygonPoints = new ArrayList<Position>();
polygonPoints.add(new Position(-1, -1));
polygonPoints.add(new Position(1, -1));
polygonPoints.add(new Position(2, 0));
polygonPoints.add(new Position(1, 1));
polygonPoints.add(new Position(-1, 1));
polygonPoints.add(new Position(-2, 0));
Polygon polygon = new Polygon(polygonPoints);
kml = KmlGenerator.createKml(polygon);
System.out.print(kml);
}
}

View File

@ -1,10 +1,10 @@
package evac;
public class SolvedEdge {
class SolvedEdge {
final Edge edge;
final int flow;
public SolvedEdge(Edge edge, int flow) {
SolvedEdge(Edge edge, int flow) {
this.edge = edge;
this.flow = flow;
}