Commit ddfe22b9 authored by Matija Obreza's avatar Matija Obreza
Browse files

Convert CSV to KML

parent 74a41e8f
package org.genesys.geotools;
import java.io.IOException;
import java.io.InputStreamReader;
import com.opencsv.CSVReader;
public class CSV2KML {
public static void main(String[] args) throws IOException {
int columnGenesysId = 0;
int columnAcceNumb = 1;
int columnInstCode = 2;
int columnLatitude = 4;
int columnLongitude = 3;
CSVReader reader = new CSVReader(new InputStreamReader(System.in), ',', '"', '\\', 0, false);
System.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
System.out.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
System.out.println("<Document>");
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
try {
String acceNumb = nextLine[columnAcceNumb].trim();
float latitude = Float.parseFloat(nextLine[columnLatitude].trim());
float longitude = Float.parseFloat(nextLine[columnLongitude].trim());
System.out.println("<Placemark>");
System.out.print("<name>");
System.out.print(nextLine[columnInstCode].trim());
System.out.print(": ");
System.out.print(acceNumb);
System.out.println("</name>");
System.out.print("<description>");
System.out.print("https://www.genesys-pgr.org/acn/id/" + nextLine[columnGenesysId].trim());
System.out.println("</description>");
System.out.println("<Point><coordinates>");
System.out.print(longitude);
System.out.print(",");
System.out.print(latitude);
System.out.println("</coordinates></Point>");
System.out.println("</Placemark>");
} catch (NumberFormatException e) {
System.err.println(e.getMessage());
}
}
System.out.println("</Document>");
System.out.println("</kml>");
reader.close();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment