private boolean placemarkHasGeoPos(int rowIndex) { return getPlacemarkAt(rowIndex).getGeoPos() != null; } }
private static Placemark[] getValidGcps(ProductNodeGroup<Placemark> gcpGroup) { final List<Placemark> gcpList = new ArrayList<Placemark>(gcpGroup.getNodeCount()); for (int i = 0; i < gcpGroup.getNodeCount(); i++) { final Placemark p = gcpGroup.get(i); final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); if (pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid()) { gcpList.add(p); } } return gcpList.toArray(new Placemark[gcpList.size()]); }
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(); }
@Override public void mouseMoved(MouseEvent e) { int rowIndex = placemarkTable.rowAtPoint(e.getPoint()); if (rowIndex != _rowIndex) { _rowIndex = rowIndex; if (_rowIndex >= 0 && _rowIndex < placemarkTable.getRowCount()) { GeoPos geoPos = getPlacemarkAt(placemarkTable.getActualRowAt(_rowIndex)).getGeoPos(); if (geoPos != null) { placemarkTable.setToolTipText(geoPos.getLonString() + " / " + geoPos.getLatString()); } } } }
private void initCoordinates(Placemark[] gcps) { for (final Placemark gcp : gcps) { final PixelPos pixelPos = gcp.getPixelPos(); final GeoPos geoPos = gcp.getGeoPos(); if (pixelPos == null || !pixelPos.isValid() || geoPos == null || !geoPos.isValid()) { throw new IllegalArgumentException("Invalid ground control point."); } } x = new double[gcps.length]; y = new double[gcps.length]; lons = new double[gcps.length]; lats = new double[gcps.length]; for (int i = 0; i < gcps.length; i++) { final PixelPos pixelPos = gcps[i].getPixelPos(); x[i] = pixelPos.getX(); y[i] = pixelPos.getY(); final GeoPos geoPos = gcps[i].getGeoPos(); lons[i] = geoPos.getLon(); lats[i] = geoPos.getLat(); } }
private void testReadMinimalPlacemarkTextFile(PlacemarkDescriptor descriptor) throws IOException { String output = "Name\tLat\tLon\n"; output += "name_1\t10.2\t12.4\n"; output += "name_2\t40.0\t-2.9\n"; List<Placemark> actualPlacemarks = PlacemarkIO.readPlacemarks(new StringReader(output), GEO_CODING, descriptor); assertEquals(2, actualPlacemarks.size()); assertEquals(actualPlacemarks.get(0).getName(), "name_1"); assertEquals(actualPlacemarks.get(0).getGeoPos().lat, 10.2f, 1.0e-4); assertEquals(actualPlacemarks.get(0).getGeoPos().lon, 12.4f, 1.0e-4); assertEquals(actualPlacemarks.get(1).getName(), "name_2"); assertEquals(actualPlacemarks.get(1).getGeoPos().lat, 40.0f, 1.0e-4); assertEquals(actualPlacemarks.get(1).getGeoPos().lon, -2.9f, 1.0e-4); } }
public Coordinate[] getCoordinates() { Coordinate[] coordinates = new Coordinate[coordinateTableModel.getRowCount()]; for (int i = 0; i < coordinateTableModel.getRowCount(); i++) { final Placemark placemark = coordinateTableModel.getPlacemarkAt(i); SimpleFeature feature = placemark.getFeature(); final Date dateTime = (Date) feature.getAttribute(Placemark.PROPERTY_NAME_DATETIME); final Coordinate.OriginalValue[] originalValues = PixExOp.getOriginalValues(feature); if (placemark.getGeoPos() == null) { final Point point = (Point) feature.getDefaultGeometry(); coordinates[i] = new Coordinate(placemark.getName(), (float) point.getY(), (float) point.getX(), dateTime, originalValues); } else { coordinates[i] = new Coordinate(placemark.getName(), placemark.getGeoPos().getLat(), placemark.getGeoPos().getLon(), dateTime, originalValues); } } return coordinates; }
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); } }
@Override protected Object getStandardColumnValueAt(int rowIndex, int columnIndex) { switch (columnIndex) { case 0: return getPlacemarkAt(rowIndex).getName(); case 1: if (placemarkHasGeoPos(rowIndex)) { return getPlacemarkAt(rowIndex).getGeoPos().getLat(); } return ((Point) getPlacemarkAt(rowIndex).getFeature().getDefaultGeometry()).getY(); case 2: if (placemarkHasGeoPos(rowIndex)) { return getPlacemarkAt(rowIndex).getGeoPos().getLon(); } return ((Point) getPlacemarkAt(rowIndex).getFeature().getDefaultGeometry()).getX(); case 3: return getPlacemarkAt(rowIndex).getFeature().getAttribute(Placemark.PROPERTY_NAME_DATETIME); default: throw new IllegalArgumentException(String.format("Invalid columnIndex = %d", columnIndex)); } }
private void writeGcpGeoCoding(GcpGeoCoding gcpGeoCoding, String nodeType) { addEmptyRow(); addRow("The " + nodeType + " uses a geo-coding which is based on ground control points (GCPs)."); addEmptyRow(); ProductNodeGroup<Placemark> gcpGroup = getProduct().getGcpGroup(); addRow("Number Of GCPs", String.valueOf(gcpGroup.getNodeCount())); addRow("Function", String.valueOf(gcpGeoCoding.getMethod())); addRow("Datum", String.valueOf(gcpGeoCoding.getDatum().getName())); addRow("Latitude RMSE", String.valueOf(gcpGeoCoding.getRmseLat())); addRow("Longitude RMSE", String.valueOf(gcpGeoCoding.getRmseLon())); addEmptyRow(); addRow("Table of used GCPs"); Placemark[] gcps = gcpGroup.toArray(new Placemark[0]); addRow("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(); addRow(String.valueOf(i), gcp.getLabel(), String.valueOf(pixelPos.getX()), String.valueOf(pixelPos.getY()), geoPos.getLatString(), geoPos.getLonString()); } setFirstColumnWidth(40); }
@Test public void testReadPlacemarkTextFileWithDateTimeFromConstantInput() throws Exception { final StringWriter stringWriter = new StringWriter(WRITER_INITIAL_SIZE); PrintWriter writer = new PrintWriter(stringWriter); writer.printf("Name Lat Lon DateTime%n"); writer.printf("One 59.885 10.664 2005-04-18T17:53:58%n"); writer.printf("Two 59.883 10.657 2006-08-06T12:54:58%n"); writer.printf("Three 59.88 10.65 2007-09-01T07:55:58%n"); List<Placemark> actualPlacemarks = PlacemarkIO.readPlacemarks(new StringReader(stringWriter.toString()), GEO_CODING, PinDescriptor.getInstance()); assertEquals(3, actualPlacemarks.size()); final Placemark mark1 = actualPlacemarks.get(0); assertEquals("One", mark1.getLabel()); assertDateTime(mark1, 2005, 3, 18, 17, 53, 58); assertEquals(59.885, mark1.getGeoPos().getLat(), 1.0e-3); assertEquals(10.664, mark1.getGeoPos().getLon(), 1.0e-3); final Placemark mark2 = actualPlacemarks.get(1); assertEquals("Two", mark2.getLabel()); assertDateTime(mark2, 2006, 7, 6, 12, 54, 58); assertEquals(59.883, mark2.getGeoPos().getLat(), 1.0e-3); assertEquals(10.657, mark2.getGeoPos().getLon(), 1.0e-3); final Placemark mark3 = actualPlacemarks.get(2); assertEquals("Three", mark3.getLabel()); assertDateTime(mark3, 2007, 8, 1, 7, 55, 58); assertEquals(59.88, mark3.getGeoPos().getLat(), 1.0e-3); assertEquals(10.65, mark3.getGeoPos().getLon(), 1.0e-3); }
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); } }
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()); } }
@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); }
@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()); } }
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(); } }
@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); }
@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); }