void copyActivePlacemark() { Guardian.assertNotNull("product", product); Placemark activePlacemark = getSelectedPlacemark(); Guardian.assertNotNull("activePlacemark", activePlacemark); Placemark newPlacemark = Placemark.createPointPlacemark(activePlacemark.getDescriptor(), "copy_of_" + activePlacemark.getName(), activePlacemark.getLabel(), activePlacemark.getDescription(), activePlacemark.getPixelPos(), activePlacemark.getGeoPos(), activePlacemark.getProduct().getGeoCoding()); newPlacemark.setStyleCss(activePlacemark.getStyleCss()); if (PlacemarkDialog.showEditPlacemarkDialog(getPaneWindow(), product, newPlacemark, placemarkDescriptor)) { makePlacemarkNameUnique(newPlacemark); updateUIState(); } }
private List<Coordinate> extractCoordinates(File coordinatesFile) { final List<Coordinate> extractedCoordinates = new ArrayList<>(); FileReader fileReader = null; try { fileReader = new FileReader(coordinatesFile); final List<Placemark> pins = PlacemarkIO.readPlacemarks(fileReader, null, // no GeoCoding needed PinDescriptor.getInstance()); for (Placemark pin : pins) { final GeoPos geoPos = pin.getGeoPos(); if (geoPos != null) { final Date dateTimeValue = (Date) pin.getFeature().getAttribute(Placemark.PROPERTY_NAME_DATETIME); final Coordinate coordinate = new Coordinate(pin.getName(), geoPos.lat, geoPos.lon, dateTimeValue); extractedCoordinates.add(coordinate); } } } catch (IOException cause) { throw new OperatorException(cause); } finally { if (fileReader != null) { try { fileReader.close(); } catch (IOException ignored) { } } } return extractedCoordinates; }
private void handleGeoCodingChange() { for (int i = 0; i < pinGroup.getNodeCount(); i++) { final Placemark pin = pinGroup.get(i); final PlacemarkDescriptor pinDescriptor = pin.getDescriptor(); final PixelPos pixelPos = pin.getPixelPos(); GeoPos geoPos = pin.getGeoPos(); if (pixelPos != null) { geoPos = pinDescriptor.updateGeoPos(getGeoCoding(), pixelPos, geoPos); } pin.setGeoPos(geoPos); } }
protected void setPixelPosY(Object value, Placemark placemark) { if (value instanceof Float) { float pixelX; if (placemark.getPixelPos() == null) { pixelX = -1; } else { pixelX = placemark.getPixelPos().x; } placemark.setPixelPos(new PixelPos(pixelX, (Float) value)); } }
final PlacemarkDialog dialog = new PlacemarkDialog(parent, product, placemarkDescriptor, placemarkDescriptor instanceof PinDescriptor); boolean belongsToProduct = placemark.getProduct() != null; String titlePrefix = belongsToProduct ? "Edit" : "New"; String roleLabel = StringUtils.firstLetterUp(placemarkDescriptor.getRoleLabel()); dialog.setName(placemark.getName()); dialog.setLabel(placemark.getLabel()); dialog.setDescription(placemark.getDescription() != null ? placemark.getDescription() : ""); dialog.setPixelPos(placemark.getPixelPos()); GeoPos geoPos = placemark.getGeoPos(); dialog.setGeoPos(geoPos != null ? geoPos : new GeoPos(Float.NaN, Float.NaN)); dialog.adjusting = false; dialog.setStyleCss(placemark.getStyleCss()); boolean ok = (dialog.show() == ID_OK); if (ok) { placemark.setName(dialog.getName()); placemark.setLabel(dialog.getLabel()); placemark.setDescription(dialog.getDescription()); placemark.setGeoPos(dialog.getGeoPos()); placemark.setPixelPos(dialog.getPixelPos()); placemark.setStyleCss(dialog.getStyleCss());
private void writeGcpGeoCoding(GcpGeoCoding gcpGeoCoding, String nodeType, StringBuffer sb) { sb.append("\n"); sb.append("\nThe ").append(nodeType).append( " uses a geo-coding which is based on ground control points (GCPs).\n"); sb.append("\n"); ProductNodeGroup<Placemark> gcpGroup = getProduct().getGcpGroup(); String formatString = "%1$-18s \t%2$s\n"; sb.append(String.format(formatString, "Number Of GCPs:", String.valueOf(gcpGroup.getNodeCount()))); sb.append(String.format(formatString, "Function:", String.valueOf(gcpGeoCoding.getMethod()))); sb.append(String.format(formatString, "Datum:", String.valueOf(gcpGeoCoding.getDatum().getName()))); sb.append(String.format(formatString, "Latitude RMSE:", String.valueOf(gcpGeoCoding.getRmseLat()))); sb.append(String.format(formatString, "Longitude RMSE:", String.valueOf(gcpGeoCoding.getRmseLon()))); sb.append("\n"); sb.append("Table of used GCPs:\n"); Placemark[] gcps = gcpGroup.toArray(new Placemark[0]); formatString = "%1$-10s \t%2$-15s \t%3$-10s \t%4$-10s \t%5$-18s \t%6$-18s\n"; sb.append(String.format(formatString, "Number", "Label", "X", "Y", "Latitude", "Longitude")); for (int i = 0; i < gcps.length; i++) { Placemark gcp = gcps[i]; PixelPos pixelPos = gcp.getPixelPos(); GeoPos geoPos = gcp.getGeoPos(); sb.append(String.format(formatString, String.valueOf(i), gcp.getLabel(), String.valueOf(pixelPos.getX()), String.valueOf(pixelPos.getY()), geoPos.getLatString(), geoPos.getLonString())); } }
private Placemark createPlacemark(String name, PixelPos pixelPos, GeoPos geoPos) { return Placemark.createPointPlacemark(PinDescriptor.getInstance(), name, "", "", pixelPos, geoPos, null); } }
private void testReadStandardResult(List<Placemark> expectedPlacemarks, List<Placemark> actualPlacemarks, PlacemarkDescriptor descriptorInstance) { for (int i = 0; i < actualPlacemarks.size(); i++) { Placemark actualPlacemark = actualPlacemarks.get(i); Placemark expectedPlacemark = expectedPlacemarks.get(i); assertNotSame(expectedPlacemark, actualPlacemark); assertEquals(expectedPlacemark.getName(), actualPlacemark.getName()); assertEquals(expectedPlacemark.getLabel(), actualPlacemark.getLabel()); assertEquals(expectedPlacemark.getPixelPos(), actualPlacemark.getPixelPos()); assertEquals(expectedPlacemark.getGeoPos(), actualPlacemark.getGeoPos()); assertEquals(expectedPlacemark.getDescription(), actualPlacemark.getDescription()); PlacemarkDescriptor descriptor = expectedPlacemark.getDescriptor(); assertEquals(descriptor.getRoleLabel(), descriptorInstance.getRoleLabel()); } }
public static void writeXML(Placemark placemark, XmlWriter writer, int indent) { Guardian.assertNotNull("writer", writer); Guardian.assertGreaterThan("indent", indent, -1); final String[][] attributes = {new String[]{DimapProductConstants.ATTRIB_NAME, placemark.getName()}}; final String[] pinTags = XmlWriter.createTags(indent, DimapProductConstants.TAG_PLACEMARK, attributes); writer.println(pinTags[0]); indent++; writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LABEL, placemark.getLabel()); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_DESCRIPTION, placemark.getDescription()); final GeoPos geoPos = placemark.getGeoPos(); if (geoPos != null) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LATITUDE, geoPos.lat); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LONGITUDE, geoPos.lon); } final PixelPos pixelPos = placemark.getPixelPos(); if (pixelPos != null && pixelPos.isValid()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_X, pixelPos.x); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_Y, pixelPos.y); } final String styleCss = placemark.getStyleCss(); if (styleCss != null && !styleCss.isEmpty()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_STYLE_CSS, styleCss); } writer.println(pinTags[1]); }
@Test public void testCopyPlacemarkGroups() throws IOException { final PlacemarkDescriptor pinDescriptor = PinDescriptor.getInstance(); final Placemark pin = Placemark.createPointPlacemark(pinDescriptor, "P1", "", "", new PixelPos(1.5f, 1.5f), null, sourceProduct.getGeoCoding()); final Placemark gcp = Placemark.createPointPlacemark(pinDescriptor, "G1", "", "", new PixelPos(2.5f, 2.5f), null, sourceProduct.getGeoCoding()); sourceProduct.getPinGroup().add(pin); sourceProduct.getGcpGroup().add(gcp); parameterMap.put("crs", WGS84_CODE); Product targetProduct = createReprojectedProduct(); assertEquals(1, targetProduct.getPinGroup().getNodeCount()); assertEquals(1, targetProduct.getGcpGroup().getNodeCount()); final Placemark pin2 = targetProduct.getPinGroup().get(0); final Placemark gcp2 = targetProduct.getGcpGroup().get(0); assertEquals("P1", pin2.getName()); assertEquals("G1", gcp2.getName()); assertEquals(pin.getGeoPos(), pin2.getGeoPos()); assertEquals(gcp.getGeoPos(), gcp2.getGeoPos()); assertNotNull(pin2.getPixelPos()); assertNotNull(gcp2.getPixelPos()); } }
for (Placemark expectedPlacemark : expectedPlacemarks) { Object[] values = new Object[stdColumnName.length + addColumnName.length]; values[0] = expectedPlacemark.getPixelPos().x; values[1] = expectedPlacemark.getPixelPos().y; values[2] = expectedPlacemark.getGeoPos().lon; values[3] = expectedPlacemark.getGeoPos().lat; values[4] = expectedPlacemark.getLabel(); long dateInMillis = (long) (Math.random() * Long.MAX_VALUE); dateInMillis -= dateInMillis % 1000; // only second accuracy final Placemark actualPlacemark = actualPlacemarks.get(i); final Object expectedDateTimeAttribute = valuesList.get(i)[5]; final Object actualDateTimeAttribute = actualPlacemark.getFeature().getAttribute("dateTime"); assertEquals(expectedDateTimeAttribute, actualDateTimeAttribute);
@Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) { // Fill the tile with the constant sample value 12345 // for (Pos pos : targetTile) { targetTile.setSample(pos.x, pos.y, 12345); } // Set a pin, so that we can test that the header is rewritten after // a data model change. // final int minX = targetTile.getMinX(); final int minY = targetTile.getMinY(); Placemark placemark = Placemark.createPointPlacemark(PinDescriptor.getInstance(), band.getName() + "-" + minX + "-" + minY, "label", "descr", new PixelPos(minX, minY), null, targetProduct.getGeoCoding()); targetProduct.getPinGroup().add(placemark); System.out.println("placemark = " + placemark.getName()); }
public void testLabelSettings() { Placemark p = Placemark.createPointPlacemark(PinDescriptor.getInstance(), "rallamann", "rallamann", "", null, new GeoPos(), product.getGeoCoding()); assertEquals("rallamann", p.getName()); assertEquals("rallamann", p.getLabel()); p.setLabel("schanteri"); assertEquals("rallamann", p.getName()); assertEquals("schanteri", p.getLabel()); p.setLabel(null); assertEquals("", p.getLabel()); p.setLabel(""); assertEquals("", p.getLabel()); } }
@Test public void movePinByGeometry() { placemark.getFeature().setDefaultGeometry(newPoint(4.0, 2.0)); placemark.getProduct().getVectorDataGroup().get("pins").fireFeaturesChanged(placemark.getFeature()); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
private void setPixelPosAttribute(PixelPos pixelPos, boolean updateGeoPos, boolean updateDefaultGeometry) { final Coordinate newCoordinate = toCoordinate(pixelPos); final Coordinate oldCoordinate = getPixelPosAttribute(); if (!ObjectUtils.equalObjects(oldCoordinate, newCoordinate)) { if (oldCoordinate == null) { final GeometryFactory geometryFactory = new GeometryFactory(); setAttributeValue(PROPERTY_NAME_PIXELPOS, geometryFactory.createPoint(newCoordinate)); } else { final Point point = (Point) getAttributeValue(PROPERTY_NAME_PIXELPOS); point.getCoordinate().setCoordinate(newCoordinate); point.geometryChanged(); } // Make sure, object is in a consistent state if (updateDefaultGeometry) { updateDefaultGeometryAttribute(pixelPos); } if (updateGeoPos && getProduct() != null) { final GeoPos geoPos = getGeoPos(); descriptor.updateGeoPos(getProduct().getGeoCoding(), pixelPos, geoPos); setGeoPosAttribute(geoPos, false); } fireProductNodeChanged(PROPERTY_NAME_PIXELPOS); } }
@Test public void movePinByPixelPosition() { placemark.setPixelPos(new PixelPos(2.0f, 1.0f)); final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
private static boolean isValid(Placemark p) { final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); return pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid(); }
private void setGeoPosAttribute(GeoPos geoPos, boolean updatePixelPos) { final Coordinate newCoordinate = toCoordinate(geoPos); final Coordinate oldCoordinate = getGeoPosAttribute(); if (!ObjectUtils.equalObjects(oldCoordinate, newCoordinate)) { if (oldCoordinate == null) { final GeometryFactory geometryFactory = new GeometryFactory(); setAttributeValue(PROPERTY_NAME_GEOPOS, geometryFactory.createPoint(newCoordinate)); } else if (newCoordinate != null) { final Point point = (Point) getAttributeValue(PROPERTY_NAME_GEOPOS); point.getCoordinate().setCoordinate(newCoordinate); point.geometryChanged(); } if (updatePixelPos && getProduct() != null) { final PixelPos pixelPos = getPixelPos(); descriptor.updatePixelPos(getProduct().getGeoCoding(), geoPos, pixelPos); setPixelPosAttribute(pixelPos, false, true); } fireProductNodeChanged(PROPERTY_NAME_GEOPOS); } }
@Test public void initialState() { final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(1.0, x, 0.0); assertEquals(1.0, y, 0.0); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(2.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(2.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }