I'm trying to parse a Kml file in Java. Cause I need to take the coordinates of a Placemark, to generate a poligon in java, and use it.
But my problem , is that i'm using JAK this library to parse it, and i'm not able to extract the information that i want.(I read the "help" in the official page, but I didn't found any help abut my problem)
I'm trying to do something like that:
final Kml kml = Kml.unmarshal(new File("C:/Users/A556520/Documents/Proyectos/GeoFencing/res/labasa.kml"));
final Document document = (Document)kml.getFeature();
List<Feature> listafeatures = document.getFeature();
But in this point I don't know how to extract the coordinates.
The file I'm trying to parse is this one: la basa
Following the javadocs (unofficial) you need to check - using
instanceof
- eachFeature
whether is is aPlacemark
, if yes cast to it and get theGeometry
which itself needs to be checked whether it is aPolygon
, if yes then cast to it. After that the path to the coordinates is the following (just as it come in the kml-file):Here is how it looks like in code:
Thanks @A4L This is really an update and a more groovier way of doing the same So changed for Groovy and also attempts more types than the example given as well digs deep within a document layer:
Came across this post, so here is part of the code of function I have been using in my app to extract Place mark name & coordinates from a String kmlText.