Search in sources :

Example 1 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class TestKMLTransformerImpl method testPerformDefaultTransformationPolygonLocation.

@Test
public void testPerformDefaultTransformationPolygonLocation() throws CatalogTransformerException {
    MetacardImpl metacard = createMockMetacard();
    metacard.setLocation(POLYGON_WKT);
    Placemark placemark = kmlTransformer.performDefaultTransformation(metacard, null);
    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(Polygon.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) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 2 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class TestKMLTransformerImpl method testPerformDefaultTransformationMultiPolygonLocation.

@Test
public void testPerformDefaultTransformationMultiPolygonLocation() throws CatalogTransformerException {
    MetacardImpl metacard = createMockMetacard();
    metacard.setLocation(MULTIPOLYGON_WKT);
    Placemark placemark = kmlTransformer.performDefaultTransformation(metacard, null);
    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 multiPolygon = (MultiGeometry) multiGeo.getGeometry().get(1);
    assertThat(multiPolygon.getGeometry().size(), is(2));
    assertThat(multiPolygon.getGeometry().get(0), instanceOf(Polygon.class));
    assertThat(multiPolygon.getGeometry().get(1), instanceOf(Polygon.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) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 3 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KMLTransformerImpl method performDefaultTransformation.

/**
     * The default Transformation from a {@link Metacard} to a KML {@link Placemark}. Protected to
     * easily allow other default transformations.
     *
     * @param entry
     *            - the {@link Metacard} to transform.
     * @param urlToMetacard
     * @return
     * @throws javax.xml.transform.TransformerException
     */
protected Placemark performDefaultTransformation(Metacard entry, String url) throws CatalogTransformerException {
    // wrap metacard to work around classLoader/reflection issues
    entry = new MetacardImpl(entry);
    Placemark kmlPlacemark = KmlFactory.createPlacemark();
    kmlPlacemark.setId("Placemark-" + entry.getId());
    kmlPlacemark.setName(entry.getTitle());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    String effectiveTime = null;
    if (entry.getEffectiveDate() == null) {
        effectiveTime = dateFormat.format(new Date());
    } else {
        effectiveTime = dateFormat.format(entry.getEffectiveDate());
    }
    TimeSpan timeSpan = KmlFactory.createTimeSpan();
    timeSpan.setBegin(effectiveTime);
    kmlPlacemark.setTimePrimitive(timeSpan);
    kmlPlacemark.setGeometry(getKmlGeoFromWkt(entry.getLocation()));
    String description = entry.getTitle();
    Handlebars handlebars = new Handlebars(templateLoader);
    handlebars.registerHelpers(templateHelper);
    try {
        Template template = handlebars.compile(DESCRIPTION_TEMPLATE);
        description = template.apply(new HandlebarsMetacard(entry));
        LOGGER.debug(description);
    } catch (IOException e) {
        LOGGER.debug("Failed to apply description Template", e);
    }
    kmlPlacemark.setDescription(description);
    String styleUrl = styleMapper.getStyleForMetacard(entry);
    if (StringUtils.isNotBlank(styleUrl)) {
        kmlPlacemark.setStyleUrl(styleUrl);
    }
    return kmlPlacemark;
}
Also used : TimeSpan(de.micromata.opengis.kml.v_2_2_0.TimeSpan) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Handlebars(com.github.jknack.handlebars.Handlebars) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) LineString(com.vividsolutions.jts.geom.LineString) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) Template(com.github.jknack.handlebars.Template)

Example 4 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project java-mapollage by trixon.

the class Operation method addPhoto.

private void addPhoto(File file) throws ImageProcessingException, IOException {
    mPhotoInfo = new PhotoInfo(file, mProfileSource.isIncludeNullCoordinate());
    try {
        mPhotoInfo.init();
    } catch (ImageProcessingException | IOException e) {
        if (mPhotoInfo.hasExif()) {
            mNumOfExif++;
        }
        throw e;
    }
    boolean hasLocation = false;
    if (mPhotoInfo.hasExif()) {
        mNumOfExif++;
        hasLocation = mPhotoInfo.hasGps() && !mPhotoInfo.isZeroCoordinate();
        if (hasLocation) {
            mNumOfGps++;
        }
    } else {
        throw new ImageProcessingException(String.format("E010 %s", file.getAbsolutePath()));
    }
    Date exifDate = mPhotoInfo.getDate();
    if (hasLocation && mProfilePath.isDrawPath()) {
        mLineNodes.add(new LineNode(exifDate, mPhotoInfo.getLat(), mPhotoInfo.getLon()));
    }
    if (hasLocation || mProfileSource.isIncludeNullCoordinate()) {
        Folder folder = getFolder(file, exifDate);
        String imageId = String.format("%08x", FileUtils.checksumCRC32(file));
        String styleNormalId = String.format("s_%s", imageId);
        String styleHighlightId = String.format("s_%s_hl", imageId);
        String styleMapId = String.format("m_%s", imageId);
        Style normalStyle = mDocument.createAndAddStyle().withId(styleNormalId);
        IconStyle normalIconStyle = normalStyle.createAndSetIconStyle().withScale(1.0);
        Style highlightStyle = mDocument.createAndAddStyle().withBalloonStyle(mBalloonStyle).withId(styleHighlightId);
        IconStyle highlightIconStyle = highlightStyle.createAndSetIconStyle().withScale(1.1);
        if (mProfilePlacemark.isSymbolAsPhoto()) {
            Icon icon = KmlFactory.createIcon().withHref(String.format("%s/%s.jpg", mThumbsDir.getName(), imageId));
            normalIconStyle.setIcon(icon);
            normalIconStyle.setScale(mProfilePlacemark.getScale());
            double highlightZoom = mProfilePlacemark.getZoom() * mProfilePlacemark.getScale();
            highlightIconStyle.setIcon(icon);
            highlightIconStyle.setScale(highlightZoom);
        }
        if (mProfilePlacemark.isSymbolAsPhoto() || mProfilePhoto.getReference() == ProfilePhoto.Reference.THUMBNAIL) {
            File thumbFile = new File(mThumbsDir, imageId + ".jpg");
            mFileThumbMap.put(file, thumbFile);
            if (Files.isWritable(thumbFile.getParentFile().toPath())) {
                mPhotoInfo.createThumbnail(thumbFile);
            } else {
                mListener.onOperationLog(String.format(mBundle.getString("insufficient_privileges"), mDestinationFile.getAbsolutePath()));
                Thread.currentThread().interrupt();
                return;
            }
        }
        mDocument.createAndAddStyleMap().withId(styleMapId).addToPair(KmlFactory.createPair().withKey(StyleState.NORMAL).withStyleUrl("#" + styleNormalId)).addToPair(KmlFactory.createPair().withKey(StyleState.HIGHLIGHT).withStyleUrl("#" + styleHighlightId));
        Placemark placemark = KmlFactory.createPlacemark().withName(getSafeXmlString(getPlacemarkName(file, exifDate))).withOpen(Boolean.TRUE).withStyleUrl("#" + styleMapId);
        String desc = getPlacemarkDescription(file, mPhotoInfo, exifDate);
        if (!StringUtils.isBlank(desc)) {
            placemark.setDescription(desc);
        }
        placemark.createAndSetPoint().addToCoordinates(mPhotoInfo.getLon(), mPhotoInfo.getLat(), 0F);
        if (mProfilePlacemark.isTimestamp()) {
            TimeStamp timeStamp = KmlFactory.createTimeStamp();
            timeStamp.setWhen(mTimeStampDateFormat.format(exifDate));
            placemark.setTimePrimitive(timeStamp);
        }
        folder.addToFeature(placemark);
        mNumOfPlacemarks++;
    }
    mListener.onOperationLog(file.getAbsolutePath());
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) IOException(java.io.IOException) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Date(java.util.Date) TimeStamp(de.micromata.opengis.kml.v_2_2_0.TimeStamp) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) 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) Icon(de.micromata.opengis.kml.v_2_2_0.Icon) File(java.io.File)

Example 5 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KMLTransformerImplTest method testPerformDefaultTransformationLineStringLocation.

@Test
public void testPerformDefaultTransformationLineStringLocation() throws CatalogTransformerException {
    MetacardImpl metacard = createMockMetacard();
    metacard.setLocation(LINESTRING_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(LineString.class));
}
Also used : TimeSpan(de.micromata.opengis.kml.v_2_2_0.TimeSpan) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) 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)

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