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[] { "<", ">", "&" }, 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());
}
}
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;
}
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;
}
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));
}
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));
}
Aggregations