BigDecimal minutes = new BigDecimal(Double.parseDouble(
temp.toString().substring(2, 4)));
BigDecimal sixty = new BigDecimal(60.00);
String direction = temp.toString().substring(4);
//Decimal Degrees = Degrees + minutes/60
BigDecimal convertedCoordinates = degrees.add(minutes.divide(sixty, new MathContext(5)));
//negate coordinate if it is -> South
if (direction.toLowerCase().equals("s")) {
convertedCoordinates.negate();
}
mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
} else if (temp != null && temp.toString().length() == 7) {//latitude with seconds
//Uses BigDecimal in order to enabe control of precision after the .
//and get precise coordinate value
//Get subSting of a number and convert it to BigDecimal
BigDecimal degrees = new BigDecimal(Double.parseDouble(
temp.toString().substring(0, 2)));
BigDecimal minutes = new BigDecimal(Double.parseDouble(
temp.toString().substring(2, 4)));
minutes = minutes.divide(new BigDecimal(60), new MathContext(5));
BigDecimal seconds = new BigDecimal(Double.parseDouble(
temp.toString().substring(4, 6)));
seconds = seconds.divide(new BigDecimal(3600), new MathContext(5));
String direction = temp.toString().substring(6);
//Decimal Degrees = Degrees + minutes/60
BigDecimal convertedCoordinates = degrees.add(minutes.add(seconds), new MathContext(5));
//negate coordinate if it is -> South
if (direction.toLowerCase().equals("s")) {
convertedCoordinates.negate();
}
mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
} else {
statusBar.setMessage("Data in selected column does not seem to be of appropriate type.");
return;
}
columnStatus.put(selectedColIndex, "Latitude");
}
statusBar.setMessage("Column data type set to - Latitude. Values converted to KML format.");
}
//if Longitude
if (coordinateType == 1 && jRadioButtonCoordinates.isSelected()) {
int rowCount = mainTable.getRowCount();
for (int i = 0; i < rowCount; i++) {
//get row from the selected column
Object temp = mainTable.getValueAt(i, selectedColIndex);
if (temp != null && temp.toString().length() == 6) { //Longitude without seconds
//Uses BigDecimal in order to enabe control of precision after the .
//and get precise coordinate value
//Get subSting of a number and convert it to BigDecimal
//degrees
BigDecimal degrees = new BigDecimal(Double.parseDouble(
temp.toString().substring(0, 3)));
//minutes/60
BigDecimal minutes = new BigDecimal(Double.parseDouble(
temp.toString().substring(3, 5)));
minutes = minutes.divide(new BigDecimal(60), new MathContext(5));
//direction
String direction = temp.toString().substring(5);
//Decimal Degrees = Degrees + minutes/60
BigDecimal convertedCoordinates = degrees.add(minutes, new MathContext(5));
//negate coordinate if it is -> West
if (direction.toLowerCase().equals("w")) {
convertedCoordinates = convertedCoordinates.negate();
}
mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
} else if (temp != null && temp.toString().length() == 8) {//Longitude with seconds
//Uses BigDecimal in order to enabe control of precision after the .
//and get precise coordinate value
//Get subSting of a number and convert it to BigDecimal
//degrees
BigDecimal degrees = new BigDecimal(Double.parseDouble(
temp.toString().substring(0, 3)));
//minutes/60
BigDecimal minutes = new BigDecimal(Double.parseDouble(
temp.toString().substring(3, 5)));
minutes = minutes.divide(new BigDecimal(60), new MathContext(5));
//seconds/3600
BigDecimal seconds = new BigDecimal(Double.parseDouble(
temp.toString().substring(4, 7)));
seconds = seconds.divide(new BigDecimal(3600), new MathContext(5));
//direction
String direction = temp.toString().substring(7);
//Decimal Degrees = Degrees + minutes/60 + seconds/3600
BigDecimal convertedCoordinates = degrees.add(minutes.add(seconds), new MathContext(5));
//negate coordinate if it is -> West
if (direction.toLowerCase().equals("w")) {
convertedCoordinates = convertedCoordinates.negate();
}