use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.
the class KMLTransformerImpl method createKmlGeo.
private Geometry createKmlGeo(com.vividsolutions.jts.geom.Geometry geo) throws CatalogTransformerException {
Geometry kmlGeo = null;
if (Point.class.getSimpleName().equals(geo.getGeometryType())) {
Point jtsPoint = (Point) geo;
kmlGeo = KmlFactory.createPoint().addToCoordinates(jtsPoint.getX(), jtsPoint.getY());
} else if (LineString.class.getSimpleName().equals(geo.getGeometryType())) {
LineString jtsLS = (LineString) geo;
de.micromata.opengis.kml.v_2_2_0.LineString kmlLS = KmlFactory.createLineString();
List<Coordinate> kmlCoords = kmlLS.createAndSetCoordinates();
for (com.vividsolutions.jts.geom.Coordinate coord : jtsLS.getCoordinates()) {
kmlCoords.add(new Coordinate(coord.x, coord.y));
}
kmlGeo = kmlLS;
} else if (Polygon.class.getSimpleName().equals(geo.getGeometryType())) {
Polygon jtsPoly = (Polygon) geo;
de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
for (com.vividsolutions.jts.geom.Coordinate coord : jtsPoly.getCoordinates()) {
kmlCoords.add(new Coordinate(coord.x, coord.y));
}
kmlGeo = kmlPoly;
} else if (geo instanceof GeometryCollection) {
List<Geometry> geos = new ArrayList<Geometry>();
for (int xx = 0; xx < geo.getNumGeometries(); xx++) {
geos.add(createKmlGeo(geo.getGeometryN(xx)));
}
kmlGeo = KmlFactory.createMultiGeometry().withGeometry(geos);
} else {
throw new CatalogTransformerException("Unknown / Unsupported Geometry Type '" + geo.getGeometryType() + "'. Unale to preform KML Transform.");
}
return kmlGeo;
}
use of de.micromata.opengis.kml.v_2_2_0.Polygon in project java-mapollage by trixon.
the class Operation method addPolygon.
private void addPolygon(String name, ArrayList<Coordinate> coordinates, Folder polygonFolder) {
List<Point2D.Double> inputs = new ArrayList<>();
coordinates.forEach((coordinate) -> {
inputs.add(new Point2D.Double(coordinate.getLongitude(), coordinate.getLatitude()));
});
try {
List<Point2D.Double> convexHull = GrahamScan.getConvexHullDouble(inputs);
Placemark placemark = polygonFolder.createAndAddPlacemark().withName(name);
Style style = placemark.createAndAddStyle();
LineStyle lineStyle = style.createAndSetLineStyle().withColor("00000000").withWidth(0.0);
PolyStyle polyStyle = style.createAndSetPolyStyle().withColor("ccffffff").withColorMode(ColorMode.RANDOM);
Polygon polygon = placemark.createAndSetPolygon();
Boundary boundary = polygon.createAndSetOuterBoundaryIs();
LinearRing linearRing = boundary.createAndSetLinearRing();
convexHull.forEach((node) -> {
linearRing.addToCoordinates(node.x, node.y);
});
} catch (IllegalArgumentException e) {
System.err.println(e);
}
}
use of de.micromata.opengis.kml.v_2_2_0.Polygon in project java-mapollage by trixon.
the class Operation method addPolygons.
private void addPolygons(Folder polygonParent, List<Feature> features) {
for (Feature feature : features) {
if (feature instanceof Folder) {
Folder folder = (Folder) feature;
if (folder != mPathFolder && folder != mPathGapFolder && folder != mPolygonFolder) {
System.out.println("ENTER FOLDER=" + folder.getName());
System.out.println("PARENT FOLDER=" + polygonParent.getName());
Folder polygonFolder = polygonParent.createAndAddFolder().withName(folder.getName()).withOpen(true);
mFolderPolygonInputs.put(polygonFolder, new ArrayList<>());
addPolygons(polygonFolder, folder.getFeature());
System.out.println("POLYGON FOLDER=" + polygonFolder.getName() + " CONTAINS");
if (mFolderPolygonInputs.get(polygonFolder) != null) {
addPolygon(folder.getName(), mFolderPolygonInputs.get(polygonFolder), polygonParent);
}
System.out.println("EXIT FOLDER=" + folder.getName());
System.out.println("");
}
}
if (feature instanceof Placemark) {
Placemark placemark = (Placemark) feature;
System.out.println("PLACEMARK=" + placemark.getName() + "(PARENT=)" + polygonParent.getName());
Point point = (Point) placemark.getGeometry();
point.getCoordinates().forEach((coordinate) -> {
mFolderPolygonInputs.get(polygonParent).add(coordinate);
});
}
}
}
use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.
the class KmlLatLonBoxToJtsGeometryConverterTest method createKmlBoundingBoxCoordinates.
private static List<Coordinate> createKmlBoundingBoxCoordinates(double minX, double maxX, double minY, double maxY) {
List<Coordinate> coordinates = new ArrayList<>();
// This is the order that WKT wants the polygon
// Starting Upper Right, moving clockwise
coordinates.add(new Coordinate(maxX, maxY));
coordinates.add(new Coordinate(maxX, minY));
coordinates.add(new Coordinate(minX, minY));
coordinates.add(new Coordinate(minX, maxY));
coordinates.add(new Coordinate(maxX, maxY));
return coordinates;
}
use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.
the class KmlToJtsGeometryConverterTest method testConvertPolygonGeometry.
@Test
public void testConvertPolygonGeometry() {
InputStream stream = KmlToJtsGeometryConverterTest.class.getResourceAsStream("/kmlPolygon.kml");
Kml kml = Kml.unmarshal(stream);
assertThat(kml, notNullValue());
Polygon kmlPolygon = ((Polygon) ((Placemark) kml.getFeature()).getGeometry());
assertThat(kmlPolygon, notNullValue());
org.locationtech.jts.geom.Geometry jtsGeometryPolygon = KmlToJtsGeometryConverter.from(kmlPolygon);
assertThat(jtsGeometryPolygon, instanceOf(org.locationtech.jts.geom.Polygon.class));
assertSpecificGeometry(kmlPolygon, jtsGeometryPolygon);
}
Aggregations