use of de.micromata.opengis.kml.v_2_2_0.LineString in project ddf by codice.
the class MetacardToKmlTest method addJtsGeoPointsToKmlGeo.
@Test
public void addJtsGeoPointsToKmlGeo() {
final LineString kmlLineString = new LineString();
kmlLineString.setCoordinates(singletonList(new Coordinate(80.0, 170.0)));
doReturn(new org.locationtech.jts.geom.Coordinate()).when(jtsLineString).getCoordinate();
final Geometry newKmlGeometry = MetacardToKml.addJtsGeoPointsToKmlGeo(jtsLineString, kmlLineString);
assertTrue(newKmlGeometry instanceof MultiGeometry);
final MultiGeometry multiGeometry = (MultiGeometry) newKmlGeometry;
assertThat("New KML Geometry should be MultiGeometry containing 2 Geometries", multiGeometry.getGeometry(), hasSize(2));
}
use of de.micromata.opengis.kml.v_2_2_0.LineString in project ddf by codice.
the class KmlToJtsGeometryConverterTest method testConvertLineStringGeometry.
@Test
public void testConvertLineStringGeometry() {
InputStream stream = KmlToJtsGeometryConverterTest.class.getResourceAsStream("/kmlLineString.kml");
Kml kml = Kml.unmarshal(stream);
assertThat(kml, notNullValue());
LineString kmlLineString = ((LineString) ((Placemark) kml.getFeature()).getGeometry());
assertThat(kmlLineString, notNullValue());
org.locationtech.jts.geom.Geometry jtsGeometryLineString = KmlToJtsGeometryConverter.from(kmlLineString);
assertThat(jtsGeometryLineString, instanceOf(org.locationtech.jts.geom.LineString.class));
assertSpecificGeometry(kmlLineString, jtsGeometryLineString);
}
use of de.micromata.opengis.kml.v_2_2_0.LineString 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.LineString in project java-mapollage by trixon.
the class Operation method addPath.
private void addPath() {
Collections.sort(mLineNodes, (LineNode o1, LineNode o2) -> o1.getDate().compareTo(o2.getDate()));
mPathFolder = KmlFactory.createFolder().withName(Dict.PATH_GFX.toString());
mPathGapFolder = KmlFactory.createFolder().withName(Dict.PATH_GAP_GFX.toString());
String pattern = getPattern(mProfilePath.getSplitBy());
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
TreeMap<String, ArrayList<LineNode>> map = new TreeMap<>();
mLineNodes.forEach((node) -> {
String key = dateFormat.format(node.getDate());
if (!map.containsKey(key)) {
map.put(key, new ArrayList<>());
}
map.get(key).add(node);
});
// Add paths
for (ArrayList<LineNode> nodes : map.values()) {
if (nodes.size() > 1) {
Placemark path = mPathFolder.createAndAddPlacemark().withName(LineNode.getName(nodes));
Style pathStyle = path.createAndAddStyle();
pathStyle.createAndSetLineStyle().withColor("ff0000ff").withWidth(mProfilePath.getWidth());
LineString line = path.createAndSetLineString().withExtrude(false).withTessellate(true);
nodes.forEach((node) -> {
line.addToCoordinates(node.getLon(), node.getLat());
});
}
}
// Add path gap
ArrayList<LineNode> previousNodes = null;
for (ArrayList<LineNode> nodes : map.values()) {
if (previousNodes != null) {
Placemark path = mPathGapFolder.createAndAddPlacemark().withName(LineNode.getName(previousNodes, nodes));
Style pathStyle = path.createAndAddStyle();
pathStyle.createAndSetLineStyle().withColor("ff00ffff").withWidth(mProfilePath.getWidth());
LineString line = path.createAndSetLineString().withExtrude(false).withTessellate(true);
LineNode prevLast = previousNodes.get(previousNodes.size() - 1);
LineNode currentFirst = nodes.get(0);
line.addToCoordinates(prevLast.getLon(), prevLast.getLat());
line.addToCoordinates(currentFirst.getLon(), currentFirst.getLat());
}
previousNodes = nodes;
}
}
use of de.micromata.opengis.kml.v_2_2_0.LineString in project ddf by codice.
the class KmlToJtsLineStringConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
InputStream stream = KmlToJtsLineStringConverterTest.class.getResourceAsStream("/kmlLineString.kml");
Kml kml = Kml.unmarshal(stream);
testKmlLineString = ((LineString) ((Placemark) kml.getFeature()).getGeometry());
}
Aggregations