Added checkbox to flip Latitude/Longitude. Added prompt if Latitude may

actually be wrong. Added <Document> tags to output file to properly
process .
master
sigonasr2 7 years ago
parent 8bf67d2af0
commit 5c1905d2ef
  1. BIN
      KMLConverter/KMLConverter.jar
  2. 2
      KMLConverter/input.txt
  3. 18
      KMLConverter/output.kml
  4. 33
      KMLConverter/src/sig/kml/KMLConverter.java
  5. 29
      KMLConverter/src/sig/kml/KMLWindow.java

Binary file not shown.

@ -1,2 +1,2 @@
-97.998046875,31.503629305773032
-96.998046875ABCDEFG31.503629305773032
-96.998046875,31.503629305773032

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Placemark>
<Point>
<coordinates>-97.998046875,31.503629305773032,0</coordinates>
</Point>
</Placemark>
<Placemark>
<Point>
<coordinates>-96.998046875,31.503629305773032,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>

@ -13,10 +13,14 @@ import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
public class KMLConverter {
final static String TEMPLATE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n"
+ "<Document>\n"
+ "{MARKERS}"
+ "</Document>\n"
+ "</kml>\n";
final static String MARKER_TEMPLATE = "<Placemark>\n"
+ "<Point>\n"
@ -26,22 +30,41 @@ public class KMLConverter {
static KMLWindow window;
KMLConverter(String input_fileloc, String output_fileloc) {
KMLConverter(String input_fileloc, String output_fileloc, boolean flip_vals) {
String markers = "";
File f = new File(input_fileloc);
Scanner reader;
int datapoints = 0;
boolean lastanswer=false;
try {
reader = new Scanner(f);
double numb1,numb2;
window.addStatusMessage("Reading file from "+input_fileloc+"...");
boolean flipped = false;
while (reader.hasNextLine()) {
String nextLine = reader.nextLine();
try {
Point2D.Double vals = SplitLine(nextLine);
numb1 = vals.x;
numb2 = vals.y;
if (flip_vals) {
double tmp = vals.y;
vals.y = vals.x;
vals.x = tmp;
}
if (!flipped && !lastanswer && InvalidLatitudeFound(vals.y)) {
lastanswer=true;
if (JOptionPane.showOptionDialog(window, "We detected Latitude values greater than 90 or less than -90. This is usually because your Longitude and Latitude values are flipped.\n\nWould you like us to flip the values for you?", "Invalid Latitude Values", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION)==JOptionPane.YES_OPTION) {
window.addStatusMessage("Flipping values...");
flipped=true;
}
}
if (flipped) {
numb1 = vals.y;
numb2 = vals.x;
} else {
numb1 = vals.x;
numb2 = vals.y;
}
window.addStatusMessage("Read coords ("+(datapoints+1)+"): ["+numb1+","+numb2+"]");
markers = ((markers.length()>0)?markers+"\n":"")+MARKER_TEMPLATE.replace("{COORDINATES}", numb1+","+numb2+",0")+"\n";
datapoints++;
@ -68,6 +91,10 @@ public class KMLConverter {
}
}
private boolean InvalidLatitudeFound(double y) {
return y<-90 || y>90;
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {

@ -11,25 +11,31 @@ import java.io.IOException;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
public class KMLWindow extends JFrame{
JFrame f = new JFrame("KMLConverter 1.0");
String input_fileloc="./input.txt", output_fileloc="./output.txt";
JFrame f = new JFrame("KMLConverter 1.1");
String input_fileloc="./input.txt", output_fileloc="./output.kml";
ButtonLabel input = null,output = null;
JTextArea status_window = null;
JScrollPane pane;
JPanel panel = new JPanel();
JPanel panel = new JPanel(),checkboxpanel = new JPanel();
JCheckBox latlong = new JCheckBox("Latitude values are first? (Lat,Long)");
KMLWindow() {
latlong.setBackground(new Color(170,180,200));
checkboxpanel.setLayout(new BoxLayout(checkboxpanel,BoxLayout.LINE_AXIS));
try {
input=new ButtonLabel("Browse...",new File(".").getCanonicalPath(),"Input",this);
output=new ButtonLabel("Browse...",new File(".").getCanonicalPath(),"Output",this);
input=new ButtonLabel("Browse...",new File(input_fileloc).getCanonicalPath(),"Input",this);
output=new ButtonLabel("Browse...",new File(output_fileloc).getCanonicalPath(),"Output",this);
} catch (IOException e) {
e.printStackTrace();
}
@ -37,7 +43,11 @@ public class KMLWindow extends JFrame{
ActionListener convert_action = new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
new KMLConverter(input_fileloc,output_fileloc);
new KMLConverter(input_fileloc,output_fileloc,latlong.isSelected());
}
private boolean InvalidLatitudeFound() {
return true;
}
};
@ -54,12 +64,19 @@ public class KMLWindow extends JFrame{
status_window.setBackground(new Color(0,0,96));
status_window.setForeground(new Color(220,220,220));
checkboxpanel.add(latlong);
//checkboxpanel.add(Box.createHorizontalStrut(latlong.getWidth()/2));
pane = new JScrollPane(status_window);
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
pane.setPreferredSize(new Dimension(320,64));
panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
input.Initialize(panel);
panel.add(checkboxpanel);
panel.add(Box.createVerticalStrut(6));
panel.add(new JSeparator());
panel.add(Box.createVerticalStrut(6));
output.Initialize(panel);
panel.add(Box.createVerticalStrut(6));
panel.add(new JSeparator());

Loading…
Cancel
Save