Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Geo Tools
Commits
ddfe22b9
Commit
ddfe22b9
authored
Jan 20, 2016
by
Matija Obreza
Browse files
Convert CSV to KML
parent
74a41e8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys/geotools/CSV2KML.java
0 → 100644
View file @
ddfe22b9
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
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment