Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Following the <a href="https://code.google.com/p/javaapiforkml/downloads/detail?name=JavaAPIforKml-apidocs.zip" rel="nofollow noreferrer">javadocs</a> (<a href="http://www.nilab.info/docs/jak091130/" rel="nofollow noreferrer">unofficial</a>) you need to check - using <code>instanceof</code> - each <code>Feature</code> whether is is a <code>Placemark</code>, if yes cast to it and get the <code>Geometry</code> which itself needs to be checked whether it is a <code>Polygon</code>, if yes then cast to it. After that the path to the coordinates is the following (just as it come in the kml-file):</p> <pre><code>getOuterBoundaryIs &gt; getlinearRing &gt; getCoordinates </code></pre> <p>Here is how it looks like in code:</p> <pre><code>@Test public void parseKml() { String src = "misctests/stackoverflow/kml/labasa.kml"; try(InputStream is = getClass().getClassLoader().getResourceAsStream(src)) { Assert.assertNotNull(is); Kml kml = Kml.unmarshal(is); Feature feature = kml.getFeature(); parseFeature(feature); } } private void parseFeature(Feature feature) { if(feature != null) { if(feature instanceof Document) { Document document = (Document) feature; List&lt;Feature&gt; featureList = document.getFeature(); for(Feature documentFeature : featureList) { if(documentFeature instanceof Placemark) { Placemark placemark = (Placemark) documentFeature; Geometry geometry = placemark.getGeometry(); parseGeometry(geometry); } } } } } private void parseGeometry(Geometry geometry) { if(geometry != null) { if(geometry instanceof Polygon) { Polygon polygon = (Polygon) geometry; Boundary outerBoundaryIs = polygon.getOuterBoundaryIs(); if(outerBoundaryIs != null) { LinearRing linearRing = outerBoundaryIs.getLinearRing(); if(linearRing != null) { List&lt;Coordinate&gt; coordinates = linearRing.getCoordinates(); if(coordinates != null) { for(Coordinate coordinate : coordinates) { parseCoordinate(coordinate); } } } } } } } private void parseCoordinate(Coordinate coordinate) { if(coordinate != null) { System.out.println("Longitude: " + coordinate.getLongitude()); System.out.println("Latitude : " + coordinate.getLatitude()); System.out.println("Altitude : " + coordinate.getAltitude()); System.out.println(""); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload