use of de.micromata.opengis.kml.v_2_2_0.Placemark 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.Placemark 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.Placemark in project ddf by codice.
the class KMLTransformerImplTest method testPerformDefaultTransformationMultiPointLocation.
@Test
public void testPerformDefaultTransformationMultiPointLocation() throws CatalogTransformerException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(MULTIPOINT_WKT);
Placemark placemark = kmlTransformer.performDefaultTransformation(metacard);
assertThat(placemark.getId(), is("Placemark-" + ID));
assertThat(placemark.getName(), is(TITLE));
assertThat(placemark.getTimePrimitive(), instanceOf(TimeSpan.class));
TimeSpan timeSpan = (TimeSpan) placemark.getTimePrimitive();
assertThat(timeSpan.getBegin(), is(dateFormat.format(metacard.getEffectiveDate())));
assertThat(placemark.getGeometry(), instanceOf(MultiGeometry.class));
MultiGeometry multiGeo = (MultiGeometry) placemark.getGeometry();
assertThat(multiGeo.getGeometry().size(), is(2));
assertThat(multiGeo.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiGeo.getGeometry().get(1), instanceOf(MultiGeometry.class));
MultiGeometry multiPoint = (MultiGeometry) multiGeo.getGeometry().get(1);
assertThat(multiPoint.getGeometry().size(), is(3));
assertThat(multiPoint.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiPoint.getGeometry().get(1), instanceOf(Point.class));
assertThat(multiPoint.getGeometry().get(2), instanceOf(Point.class));
}
use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.
the class KMLTransformerImplTest method testTransformMetacardFromUpstreamResponse.
@Test
public void testTransformMetacardFromUpstreamResponse() throws CatalogTransformerException, IOException, XpathException, SAXException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(POINT_WKT);
Result result = new ResultImpl(metacard);
SourceResponseImpl sourceResponse = new SourceResponseImpl(null, singletonList(result));
BinaryContent content = kmlTransformer.transform(sourceResponse, emptyMap());
assertThat(content.getMimeTypeValue(), is(KMLTransformerImpl.KML_MIMETYPE.toString()));
final String kmlString = IOUtils.toString(content.getInputStream(), StandardCharsets.UTF_8);
assertXpathEvaluatesTo("Results (1)", "/m:kml/m:Document/m:name", kmlString);
assertXpathExists("//m:Placemark[@id='Placemark-1234567890']", kmlString);
assertXpathEvaluatesTo("myTitle", "//m:Placemark/m:name", kmlString);
}
use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.
the class KMLTransformerImpl method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
try {
Placemark placemark = transformEntry(null, metacard, arguments);
if (placemark.getStyleSelector().isEmpty() && StringUtils.isBlank(placemark.getStyleUrl())) {
placemark.getStyleSelector().addAll(defaultStyle);
}
Kml kml = KmlFactory.createKml().withFeature(placemark);
String transformedKmlString = kmlMarshaller.marshal(kml);
InputStream kmlInputStream = new ByteArrayInputStream(transformedKmlString.getBytes(StandardCharsets.UTF_8));
return new BinaryContentImpl(kmlInputStream, KML_MIMETYPE);
} catch (Exception e) {
LOGGER.debug("Error transforming metacard ({}) to KML: {}", metacard.getId(), e.getMessage());
throw new CatalogTransformerException("Error transforming metacard to KML.", e);
}
}
Aggregations