Search in sources :

Example 1 with Coordinate

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

the class Operation method saveToFile.

private void saveToFile() {
    mListener.onOperationLog("");
    List keys = new ArrayList(mRootFolders.keySet());
    Collections.sort(keys);
    keys.stream().forEach((key) -> {
        mRootFolder.getFeature().add(mRootFolders.get((String) key));
    });
    if (mPathFolder != null && !mPathFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathFolder);
    }
    if (mPathGapFolder != null && !mPathGapFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathGapFolder);
    }
    if (mProfilePlacemark.isSymbolAsPhoto()) {
        mListener.onOperationLog("\n" + String.format(mBundle.getString("stored_thumbnails"), mThumbsDir.getAbsolutePath()));
    }
    try {
        StringWriter stringWriter = new StringWriter();
        mKml.marshal(stringWriter);
        String kmlString = stringWriter.toString();
        if (mOptions.isCleanNs2()) {
            mListener.onOperationLog(mBundle.getString("clean_ns2"));
            kmlString = StringUtils.replace(kmlString, "xmlns:ns2=", "xmlns=");
            kmlString = StringUtils.replace(kmlString, "<ns2:", "<");
            kmlString = StringUtils.replace(kmlString, "</ns2:", "</");
        }
        if (mOptions.isCleanSpace()) {
            mListener.onOperationLog(mBundle.getString("clean_space"));
            kmlString = StringUtils.replace(kmlString, "        ", "\t");
            kmlString = StringUtils.replace(kmlString, "    ", "\t");
        }
        kmlString = StringUtils.replaceEach(kmlString, new String[] { "&lt;", "&gt;", "&amp;" }, new String[] { "<", ">", "" });
        if (mOptions.isLogKml()) {
            mListener.onOperationLog("\n");
            mListener.onOperationLog(kmlString);
            mListener.onOperationLog("\n");
        }
        mListener.onOperationLog(String.format(Dict.SAVING.toString(), mDestinationFile.getAbsolutePath()));
        FileUtils.writeStringToFile(mDestinationFile, kmlString, "utf-8");
        String files = mBundle.getString("status_files");
        String exif = mBundle.getString("status_exif");
        String coordinate = mBundle.getString("status_coordinate");
        String time = mBundle.getString("status_time");
        String error = " " + Dict.Dialog.ERRORS.toString().toLowerCase();
        String placemarks = mBundle.getString("status_placemarks");
        int rightPad = files.length();
        rightPad = Math.max(rightPad, exif.length());
        rightPad = Math.max(rightPad, coordinate.length());
        rightPad = Math.max(rightPad, time.length());
        rightPad = Math.max(rightPad, error.length());
        rightPad = Math.max(rightPad, placemarks.length());
        rightPad++;
        int leftPad = 8;
        StringBuilder summaryBuilder = new StringBuilder("\n");
        String filesValue = String.valueOf(mFiles.size());
        summaryBuilder.append(StringUtils.rightPad(files, rightPad)).append(":").append(StringUtils.leftPad(filesValue, leftPad)).append("\n");
        String exifValue = String.valueOf(mNumOfExif);
        summaryBuilder.append(StringUtils.rightPad(exif, rightPad)).append(":").append(StringUtils.leftPad(exifValue, leftPad)).append("\n");
        String coordinateValue = String.valueOf(mNumOfGps);
        summaryBuilder.append(StringUtils.rightPad(coordinate, rightPad)).append(":").append(StringUtils.leftPad(coordinateValue, leftPad)).append("\n");
        String placemarksValue = String.valueOf(mNumOfPlacemarks);
        summaryBuilder.append(StringUtils.rightPad(placemarks, rightPad)).append(":").append(StringUtils.leftPad(placemarksValue, leftPad)).append("\n");
        String errorValue = String.valueOf(mNumOfErrors);
        summaryBuilder.append(StringUtils.rightPad(error, rightPad)).append(":").append(StringUtils.leftPad(errorValue, leftPad)).append("\n");
        String timeValue = String.valueOf(Math.round((System.currentTimeMillis() - mStartTime) / 1000.0));
        summaryBuilder.append(StringUtils.rightPad(time, rightPad)).append(":").append(StringUtils.leftPad(timeValue, leftPad)).append(" s").append("\n");
        mListener.onOperationFinished(summaryBuilder.toString(), mFiles.size());
    } catch (IOException ex) {
        mListener.onOperationFailed(ex.getLocalizedMessage());
    }
}
Also used : StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) IOException(java.io.IOException) Point(de.micromata.opengis.kml.v_2_2_0.Point)

Example 2 with Coordinate

use of de.micromata.opengis.kml.v_2_2_0.Coordinate in project collect by openforis.

the class SamplingPointDataKmlGenerator method generate.

public void generate() {
    Kml kml = KmlFactory.createKml();
    Document doc = kml.createAndSetDocument();
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLat lngLatAlt = createLngLat(coordinate);
        doc.createAndAddPlacemark().withName(Strings.joinNotBlank(item.getLevelCodes(), "|")).withOpen(true).createAndSetPoint().addToCoordinates(lngLatAlt.getLongitude(), lngLatAlt.getLatitude());
    }
    this.kml = kml;
}
Also used : LngLat(org.openforis.collect.model.LngLat) Coordinate(org.openforis.idm.model.Coordinate) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Document(de.micromata.opengis.kml.v_2_2_0.Document) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 3 with Coordinate

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

the class MetacardToKml method createPolygonGeo.

private static Geometry createPolygonGeo(Polygon jtsPoly) {
    de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
    List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
    for (org.locationtech.jts.geom.Coordinate coord : jtsPoly.getExteriorRing().getCoordinates()) {
        kmlCoords.add(new Coordinate(coord.x, coord.y));
    }
    for (int n = 0; n < jtsPoly.getNumInteriorRing(); n++) {
        kmlCoords = kmlPoly.createAndAddInnerBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
        org.locationtech.jts.geom.Coordinate[] childCoordinates = jtsPoly.getInteriorRingN(n).getCoordinates();
        for (org.locationtech.jts.geom.Coordinate coord : childCoordinates) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
    }
    return kmlPoly;
}
Also used : Point(org.locationtech.jts.geom.Point) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate)

Example 4 with Coordinate

use of de.micromata.opengis.kml.v_2_2_0.Coordinate 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));
}
Also used : Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) Test(org.junit.Test)

Example 5 with Coordinate

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

the class MetacardToKmlTest method getKmlPointGeoFromWkt.

@Test
public void getKmlPointGeoFromWkt() throws CatalogTransformerException {
    final Point kmlGeoFromWkt = (Point) MetacardToKml.getKmlGeoFromWkt("POINT (2 3)");
    final List<Coordinate> coordinates = kmlGeoFromWkt.getCoordinates();
    assertThat(coordinates, hasSize(1));
    assertThat(coordinates.get(0).getLatitude(), is(3.0));
    assertThat(coordinates.get(0).getLongitude(), is(2.0));
}
Also used : Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) Point(de.micromata.opengis.kml.v_2_2_0.Point) Test(org.junit.Test)

Aggregations

Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)9 ArrayList (java.util.ArrayList)4 Point (de.micromata.opengis.kml.v_2_2_0.Point)3 Test (org.junit.Test)3 Geometry (de.micromata.opengis.kml.v_2_2_0.Geometry)2 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)2 Location (de.micromata.opengis.kml.v_2_2_0.Location)2 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)2 List (java.util.List)2 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)1 LineString (com.vividsolutions.jts.geom.LineString)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)1 Boundary (de.micromata.opengis.kml.v_2_2_0.Boundary)1 Document (de.micromata.opengis.kml.v_2_2_0.Document)1 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1