From 909672358444cb409650a7197f6d6b051a109065 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sat, 2 Nov 2019 15:30:49 -0400 Subject: [PATCH] A family friendly commit message updating the kml generator with --- data/test.kml | 19 ++++++++++++++ src/evac/KmlGenerator.java | 51 ++++++++++++++++++++++++++++++++++++-- src/evac/KmlTest.java | 27 ++++++++++++++++++++ src/evac/SolvedEdge.java | 4 +-- 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 data/test.kml create mode 100644 src/evac/KmlTest.java diff --git a/data/test.kml b/data/test.kml new file mode 100644 index 0000000..565ccfc --- /dev/null +++ b/data/test.kml @@ -0,0 +1,19 @@ + + + + Polygon Placemark + This is a polygon + + clampToGround + + -1.000000,-1.000000 + -1.000000,1.000000 + 0.000000,2.000000 + 1.000000,1.000000 + 1.000000,-1.000000 + 0.000000,-2.000000 + + + + + diff --git a/src/evac/KmlGenerator.java b/src/evac/KmlGenerator.java index ed6ee43..0a6ca2f 100644 --- a/src/evac/KmlGenerator.java +++ b/src/evac/KmlGenerator.java @@ -1,7 +1,54 @@ package evac; -class KmlGenerator { - static String createKml(OutputModel model) { +public class KmlGenerator { + private static final String XML_HEADER = "\n"; + private static final String HEADER = "\n"; + + private static final String FOOTER = "\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("\n"); + builder.append(" Position Placemark\n"); + builder.append(" This is a position\n"); + builder.append(" \n"); + builder.append(String.format(" %f,%f\n", position.latitude, position.longitude)); + builder.append(" \n"); + builder.append("\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("\n"); + builder.append(" Polygon Placemark\n"); + builder.append(" This is a polygon\n"); + builder.append(" \n"); + builder.append(" clampToGround\n"); + builder.append(" \n"); + for (Position position : polygon.positions) { + builder.append(String.format(" %f,%f\n", position.latitude, position.longitude)); + } + builder.append(" \n"); + builder.append(" \n"); + builder.append(" \n"); + builder.append("\n"); + + builder.append(FOOTER); + return builder.toString(); + } + + } diff --git a/src/evac/KmlTest.java b/src/evac/KmlTest.java new file mode 100644 index 0000000..0f9ae0c --- /dev/null +++ b/src/evac/KmlTest.java @@ -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 polygonPoints = new ArrayList(); + 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); + } +} diff --git a/src/evac/SolvedEdge.java b/src/evac/SolvedEdge.java index e41cb69..a56bc92 100644 --- a/src/evac/SolvedEdge.java +++ b/src/evac/SolvedEdge.java @@ -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; }