private int computeIndex(PixelPos pixelPos) { final int y = (int) pixelPos.getY(); final int index = y / gcStripeSceneHeight; if (index < smallestValidIndex) { return smallestValidIndex; } else if (index > biggestValidIndex) { return biggestValidIndex; } else { return index; } }
private void exportImageCoords(StringBuilder row, PixelPos pixelPos) { DecimalFormat formatter = new DecimalFormat("0.000"); row.append(formatter.format(pixelPos.getX())); row.append(getSeparator()); row.append(formatter.format(pixelPos.getY())); row.append(getSeparator()); }
private int computeIndex(PixelPos pixelPos) { final int y = (int) pixelPos.getY() + getScanlineOffset(); final int index = y / getScanlineHeight(); if (index < _smallestValidIndex) { return _smallestValidIndex; } else if (index > _biggestValidIndex) { return _biggestValidIndex; } else { return index; } }
if (pixelsPos != null) { final int x = (int) Math.floor(pixelsPos.getX()); final int y = (int) Math.floor(pixelsPos.getY());
@Override public TimeSeriesGraphUpdater.Position transformGeoPos(GeoPos geoPos) { geoCoding.getPixelPos(geoPos, pixelPos); return new TimeSeriesGraphUpdater.Position((int) pixelPos.getX(), (int) pixelPos.getY(), 0); } };
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 GeoPos getGeoPos(final PixelPos pixelPos, final GeoPos geoPos) { final PixelPos localPixelPos = new PixelPos(); localPixelPos.setLocation(pixelPos.getX() - _location.x, pixelPos.getY() - _location.y); return _geoGoding.getGeoPos(localPixelPos, geoPos); }
GeoApproximation getGeoPos(PixelPos p, GeoPos g) { GeoApproximation approximation = null; if (approximations != null) { if (g == null) { g = new GeoPos(); } if (p.isValid()) { approximation = GeoApproximation.findSuitable(approximations, p); if (approximation != null) { final double x = p.getX(); final double y = p.getY(); final Point2D q = new Point2D.Double(x, y); approximation.p2g(q); final double lon = q.getX(); final double lat = q.getY(); if (lon >= -180.0 && lon <= 180.0 && lat >= -90.0 && lat <= 90.0) { g.setLocation((float) lat, (float) lon); } else { g.setInvalid(); } } else { g.setInvalid(); } } else { g.setInvalid(); } } return approximation; }
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(); } }
if (pixelPos.isValid()) { int x0 = (int) Math.floor(pixelPos.getX()); int y0 = (int) Math.floor(pixelPos.getY()); if (x0 >= 0 && x0 < rasterWidth && y0 >= 0 && y0 < rasterHeight) { if (fractionAccuracy) { // implies tiling mode
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); }
if (pixelPos.isValid() && pixelPosIsInsideRasterWH(pixelPos)) { int x0 = (int) Math.floor(pixelPos.getX()); int y0 = (int) Math.floor(pixelPos.getY());
int y0 = (int) Math.floor(pixelPos.getY()); if (x0 >= 0 && x0 < width && y0 >= 0 && y0 < height) { if (x0 > 0 && pixelPos.x - x0 < 0.5f || x0 == width - 1) {
final int y = MathUtils.floorInt(pixelPos.getY()); if (product != null) { final int width = product.getSceneRasterWidth();
approximation.g2p(p); final double x = p.getX(); final double y = p.getY(); if (!EXTRAPOLATE && (x < bounds.getMinX() || x > bounds.getMaxX() || y < bounds.getMinY() || y > bounds.getMaxY())) { p.setInvalid();
@Test @Ignore public void testGetPixelPosForSimulatedSwath() { final int nx = 512; final int ny = 36000; final PlanarImage[] images = generateSwathCoordinates(nx, ny, 0.009, 0.009, new Rotator(0.0, -5.0, 269.0)); final PlanarImage lonImage = images[0]; final PlanarImage latImage = images[1]; final PlanarImage maskImage = images[2]; final PixelPosEstimator estimator = new PixelPosEstimator(lonImage, latImage, maskImage, 0.5); final GeoPos g = new GeoPos(); final PixelPos p = new PixelPos(); for (int y = 0; y < ny; y++) { final Rectangle region = new Rectangle(0, y, nx, 1); final Raster lonData = lonImage.getData(region); final Raster latData = latImage.getData(region); for (int x = 0; x < nx; x++) { final float lon = lonData.getSampleFloat(x, y, 0); final float lat = latData.getSampleFloat(x, y, 0); g.setLocation(lat, lon); estimator.getPixelPos(g, p); assertTrue(p.isValid()); assertEquals(x + 0.5, p.getX(), 0.5); assertEquals(y + 0.5, p.getY(), 0.5); } } }
@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); }
public void testTransferGeoCoding_WithSpatialSubset() throws IOException { final Scene srcScene = SceneFactory.createScene(createProduct()); final ProductSubsetDef subsetDef = new ProductSubsetDef(); subsetDef.setRegion(2, 2, PW - 4, PH - 4); subsetDef.setSubSampling(1,2); final Product destProduct = ProductSubsetBuilder.createProductSubset(new Product("test2", "test2", PW, PH), subsetDef, "test2", ""); final Scene destScene = SceneFactory.createScene(destProduct); final boolean transferred = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transferred); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertTrue(destGeoCoding instanceof TiePointGeoCoding); final GeoPos srcGeoPos = srcScene.getGeoCoding().getGeoPos(new PixelPos(4.5f, 6.5f), null); final PixelPos destPixelPos = destScene.getGeoCoding().getPixelPos(srcGeoPos, null); assertEquals(2.5, destPixelPos.getX(), 1.0e-1); assertEquals(1.5, destPixelPos.getY(), 1.0e-1); }
@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); }