Added checkbox to flip Latitude/Longitude. Added prompt if Latitude may
actually be wrong. Added <Document> tags to output file to properly process .
This commit is contained in:
parent
8bf67d2af0
commit
5c1905d2ef
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
-97.998046875,31.503629305773032
|
-97.998046875,31.503629305773032
|
||||||
-96.998046875ABCDEFG31.503629305773032
|
-96.998046875,31.503629305773032
|
18
KMLConverter/output.kml
Normal file
18
KMLConverter/output.kml
Normal file
@ -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.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class KMLConverter {
|
public class KMLConverter {
|
||||||
final static String TEMPLATE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
final static String TEMPLATE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
+ "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n"
|
+ "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n"
|
||||||
|
+ "<Document>\n"
|
||||||
+ "{MARKERS}"
|
+ "{MARKERS}"
|
||||||
|
+ "</Document>\n"
|
||||||
+ "</kml>\n";
|
+ "</kml>\n";
|
||||||
final static String MARKER_TEMPLATE = "<Placemark>\n"
|
final static String MARKER_TEMPLATE = "<Placemark>\n"
|
||||||
+ "<Point>\n"
|
+ "<Point>\n"
|
||||||
@ -26,22 +30,41 @@ public class KMLConverter {
|
|||||||
|
|
||||||
static KMLWindow window;
|
static KMLWindow window;
|
||||||
|
|
||||||
KMLConverter(String input_fileloc, String output_fileloc) {
|
KMLConverter(String input_fileloc, String output_fileloc, boolean flip_vals) {
|
||||||
String markers = "";
|
String markers = "";
|
||||||
|
|
||||||
File f = new File(input_fileloc);
|
File f = new File(input_fileloc);
|
||||||
Scanner reader;
|
Scanner reader;
|
||||||
int datapoints = 0;
|
int datapoints = 0;
|
||||||
|
boolean lastanswer=false;
|
||||||
try {
|
try {
|
||||||
reader = new Scanner(f);
|
reader = new Scanner(f);
|
||||||
double numb1,numb2;
|
double numb1,numb2;
|
||||||
window.addStatusMessage("Reading file from "+input_fileloc+"...");
|
window.addStatusMessage("Reading file from "+input_fileloc+"...");
|
||||||
|
boolean flipped = false;
|
||||||
while (reader.hasNextLine()) {
|
while (reader.hasNextLine()) {
|
||||||
String nextLine = reader.nextLine();
|
String nextLine = reader.nextLine();
|
||||||
try {
|
try {
|
||||||
Point2D.Double vals = SplitLine(nextLine);
|
Point2D.Double vals = SplitLine(nextLine);
|
||||||
|
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;
|
numb1 = vals.x;
|
||||||
numb2 = vals.y;
|
numb2 = vals.y;
|
||||||
|
}
|
||||||
window.addStatusMessage("Read coords ("+(datapoints+1)+"): ["+numb1+","+numb2+"]");
|
window.addStatusMessage("Read coords ("+(datapoints+1)+"): ["+numb1+","+numb2+"]");
|
||||||
markers = ((markers.length()>0)?markers+"\n":"")+MARKER_TEMPLATE.replace("{COORDINATES}", numb1+","+numb2+",0")+"\n";
|
markers = ((markers.length()>0)?markers+"\n":"")+MARKER_TEMPLATE.replace("{COORDINATES}", numb1+","+numb2+",0")+"\n";
|
||||||
datapoints++;
|
datapoints++;
|
||||||
@ -68,6 +91,10 @@ public class KMLConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean InvalidLatitudeFound(double y) {
|
||||||
|
return y<-90 || y>90;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -11,25 +11,31 @@ import java.io.IOException;
|
|||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSeparator;
|
import javax.swing.JSeparator;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
public class KMLWindow extends JFrame{
|
public class KMLWindow extends JFrame{
|
||||||
JFrame f = new JFrame("KMLConverter 1.0");
|
JFrame f = new JFrame("KMLConverter 1.1");
|
||||||
String input_fileloc="./input.txt", output_fileloc="./output.txt";
|
String input_fileloc="./input.txt", output_fileloc="./output.kml";
|
||||||
ButtonLabel input = null,output = null;
|
ButtonLabel input = null,output = null;
|
||||||
JTextArea status_window = null;
|
JTextArea status_window = null;
|
||||||
JScrollPane pane;
|
JScrollPane pane;
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel(),checkboxpanel = new JPanel();
|
||||||
|
JCheckBox latlong = new JCheckBox("Latitude values are first? (Lat,Long)");
|
||||||
KMLWindow() {
|
KMLWindow() {
|
||||||
|
latlong.setBackground(new Color(170,180,200));
|
||||||
|
checkboxpanel.setLayout(new BoxLayout(checkboxpanel,BoxLayout.LINE_AXIS));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
input=new ButtonLabel("Browse...",new File(".").getCanonicalPath(),"Input",this);
|
input=new ButtonLabel("Browse...",new File(input_fileloc).getCanonicalPath(),"Input",this);
|
||||||
output=new ButtonLabel("Browse...",new File(".").getCanonicalPath(),"Output",this);
|
output=new ButtonLabel("Browse...",new File(output_fileloc).getCanonicalPath(),"Output",this);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -37,7 +43,11 @@ public class KMLWindow extends JFrame{
|
|||||||
ActionListener convert_action = new ActionListener(){
|
ActionListener convert_action = new ActionListener(){
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
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.setBackground(new Color(0,0,96));
|
||||||
status_window.setForeground(new Color(220,220,220));
|
status_window.setForeground(new Color(220,220,220));
|
||||||
|
|
||||||
|
checkboxpanel.add(latlong);
|
||||||
|
//checkboxpanel.add(Box.createHorizontalStrut(latlong.getWidth()/2));
|
||||||
|
|
||||||
pane = new JScrollPane(status_window);
|
pane = new JScrollPane(status_window);
|
||||||
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
pane.setPreferredSize(new Dimension(320,64));
|
pane.setPreferredSize(new Dimension(320,64));
|
||||||
panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
|
panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
|
||||||
input.Initialize(panel);
|
input.Initialize(panel);
|
||||||
|
panel.add(checkboxpanel);
|
||||||
|
panel.add(Box.createVerticalStrut(6));
|
||||||
|
panel.add(new JSeparator());
|
||||||
|
panel.add(Box.createVerticalStrut(6));
|
||||||
output.Initialize(panel);
|
output.Initialize(panel);
|
||||||
panel.add(Box.createVerticalStrut(6));
|
panel.add(Box.createVerticalStrut(6));
|
||||||
panel.add(new JSeparator());
|
panel.add(new JSeparator());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user