diff --git a/KMLConverter/KMLConverter.jar b/KMLConverter/KMLConverter.jar index a9de4c5..4989e1a 100644 Binary files a/KMLConverter/KMLConverter.jar and b/KMLConverter/KMLConverter.jar differ diff --git a/KMLConverter/input.txt b/KMLConverter/input.txt index 8127d56..95c0435 100644 --- a/KMLConverter/input.txt +++ b/KMLConverter/input.txt @@ -1,2 +1,2 @@ -97.998046875,31.503629305773032 --96.998046875ABCDEFG31.503629305773032 \ No newline at end of file +-96.998046875,31.503629305773032 \ No newline at end of file diff --git a/KMLConverter/output.kml b/KMLConverter/output.kml new file mode 100644 index 0000000..2864280 --- /dev/null +++ b/KMLConverter/output.kml @@ -0,0 +1,18 @@ + + + + + +-97.998046875,31.503629305773032,0 + + + + + + +-96.998046875,31.503629305773032,0 + + + + + diff --git a/KMLConverter/src/sig/kml/KMLConverter.java b/KMLConverter/src/sig/kml/KMLConverter.java index 090aaa1..3beb29e 100644 --- a/KMLConverter/src/sig/kml/KMLConverter.java +++ b/KMLConverter/src/sig/kml/KMLConverter.java @@ -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 = "\n" + "\n" + + "\n" + "{MARKERS}" + + "\n" + "\n"; final static String MARKER_TEMPLATE = "\n" + "\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() { diff --git a/KMLConverter/src/sig/kml/KMLWindow.java b/KMLConverter/src/sig/kml/KMLWindow.java index 4b201ce..81074f2 100644 --- a/KMLConverter/src/sig/kml/KMLWindow.java +++ b/KMLConverter/src/sig/kml/KMLWindow.java @@ -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());