JAva解析kmlファイル
3703 ワード
package test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.math3.analysis.polynomials.PolynomialsUtils;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Boundary;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import de.micromata.opengis.kml.v_2_2_0.Folder;
import de.micromata.opengis.kml.v_2_2_0.Geometry;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.LineString;
import de.micromata.opengis.kml.v_2_2_0.LineStyle;
import de.micromata.opengis.kml.v_2_2_0.LinearRing;
import de.micromata.opengis.kml.v_2_2_0.MultiGeometry;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Point;
import de.micromata.opengis.kml.v_2_2_0.PolyStyle;
import de.micromata.opengis.kml.v_2_2_0.Polygon;
import de.micromata.opengis.kml.v_2_2_0.Style;
import de.micromata.opengis.kml.v_2_2_0.StyleSelector;
/**
*
* :Dream~
* :2015-8-7 11:38:00
* :[email protected]
* :
*/
public class DemoKML2 {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws NoSuchFieldException, SecurityException{
String color = null;
Integer width = null;
List kmlPointList = new ArrayList();
List kmlLineList = new ArrayList();
List kmlAreaList = new ArrayList();
KmlProperty kmlProperty = new KmlProperty();
List polygon = null;
List coordinates;
MultiGeometry multiGeometry = null;
LineString lineString = null;
LinearRing linearRing = null;
Point point = null;
final Kml kml = Kml.unmarshal(new File("C://x.kml"));
Document document = (Document) kml.getFeature();
/*final Placemark placemark = (Placemark) kml.getFeature();*/
Folder folder = (Folder) document.getFeature().get(1);
int folderSize = folder.getFeature().size();
// loop over all countries / Placemarks
for (int i = 0; i < folderSize; i++) {
Placemark placemark = (Placemark) folder.getFeature().get(i);
List style = placemark.getStyleSelector();
for(int m=0 ; m) placemark.getGeometry();
for(int j=0 ; j