Search in sources :

Example 26 with Placemark

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;
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) ArrayList(java.util.ArrayList) LineStyle(de.micromata.opengis.kml.v_2_2_0.LineStyle) PolyStyle(de.micromata.opengis.kml.v_2_2_0.PolyStyle) Style(de.micromata.opengis.kml.v_2_2_0.Style) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) BalloonStyle(de.micromata.opengis.kml.v_2_2_0.BalloonStyle) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) TreeMap(java.util.TreeMap) SimpleDateFormat(java.text.SimpleDateFormat)

Example 27 with Placemark

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);
            });
        }
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Point(de.micromata.opengis.kml.v_2_2_0.Point) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Feature(de.micromata.opengis.kml.v_2_2_0.Feature)

Example 28 with Placemark

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));
}
Also used : TimeSpan(de.micromata.opengis.kml.v_2_2_0.TimeSpan) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) Point(de.micromata.opengis.kml.v_2_2_0.Point) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 29 with Placemark

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);
}
Also used : SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 30 with Placemark

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);
    }
}
Also used : Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) KmlTransformations.encloseKml(org.codice.ddf.spatial.kml.util.KmlTransformations.encloseKml) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) MimeTypeParseException(javax.activation.MimeTypeParseException) IOException(java.io.IOException)

Aggregations

Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)35 Test (org.junit.Test)29 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)23 InputStream (java.io.InputStream)20 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Point (de.micromata.opengis.kml.v_2_2_0.Point)19 TimeSpan (de.micromata.opengis.kml.v_2_2_0.TimeSpan)16 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)15 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)12 Polygon (de.micromata.opengis.kml.v_2_2_0.Polygon)10 BeforeClass (org.junit.BeforeClass)8 LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)5 Document (de.micromata.opengis.kml.v_2_2_0.Document)4 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)4 Style (de.micromata.opengis.kml.v_2_2_0.Style)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)4 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)3 IconStyle (de.micromata.opengis.kml.v_2_2_0.IconStyle)3