private PixelPos getRrPixelPos(int x, int y) throws OperatorException { PixelPos frsPixelPos = new PixelPos(x, y); GeoPos geoPos = frsGeoCoding.getGeoPos(frsPixelPos, null); PixelPos rrPixelPos = rrGeoCoding.getPixelPos(geoPos, null); final int xrr = Math.round(rrPixelPos.x); final int yrr = Math.round(rrPixelPos.y); if (rrProduct.containsPixel(xrr, yrr)) { return rrPixelPos; } else { throw new OperatorException("RR product does not contain data for this coordinate: x=" + x + " y=" + y); } }
@Override public CoordinateReferenceSystem getMapCRS() { return geoCoding.getMapCRS(); }
@Override @Deprecated public GeoPos updateGeoPos(GeoCoding geoCoding, PixelPos pixelPos, GeoPos geoPos) { if (geoCoding == null || !geoCoding.canGetGeoPos()) { return geoPos; } return geoCoding.getGeoPos(pixelPos, geoPos); } }
@Override @Deprecated public PixelPos updatePixelPos(GeoCoding geoCoding, GeoPos geoPos, PixelPos pixelPos) { if (geoCoding == null || !geoCoding.canGetPixelPos() || geoPos == null) { return pixelPos; } return geoCoding.getPixelPos(geoPos, pixelPos); }
/** * Gets the coordinate reference system used for the model space. The model space is coordinate system * that is used to render images for display. * * @param geoCoding A geo-coding, may be {@code null}. * @return The coordinate reference system used for the model space. If {@code geoCoding} is {@code null}, * it will be a default image coordinate reference system (an instance of {@code org.opengis.referencing.crs.ImageCRS}). */ public static CoordinateReferenceSystem getModelCrs(GeoCoding geoCoding) { if (geoCoding != null) { final MathTransform image2Map = geoCoding.getImageToMapTransform(); if (image2Map instanceof AffineTransform) { return geoCoding.getMapCRS(); } return geoCoding.getImageCRS(); } else { return DEFAULT_IMAGE_CRS; } }
final Rectangle destArea) { Guardian.assertNotNull("sourceGeoCoding", sourceGeoCoding); Guardian.assertEquals("sourceGeoCoding.canGetPixelPos()", sourceGeoCoding.canGetPixelPos(), true); Guardian.assertNotNull("destGeoCoding", destGeoCoding); Guardian.assertEquals("destGeoCoding.canGetGeoPos()", destGeoCoding.canGetGeoPos(), true); Guardian.assertNotNull("destArea", destArea); pixelPos.x = x + 0.5f; pixelPos.y = y + 0.5f; destGeoCoding.getGeoPos(pixelPos, geoPos); sourceGeoCoding.getPixelPos(geoPos, pixelPos); if (pixelPos.x >= 0.0f && pixelPos.x < sourceWidth && pixelPos.y >= 0.0f && pixelPos.y < sourceHeight) {
protected GeoPos getGeoPos(PixelPos pixelPos) { final GeoPos geoPos = new GeoPos(); gc.getGeoPos(pixelPos, geoPos); return geoPos; }
private PixelPos performReverseLocationModel(GeoPos geoPos, PixelPos pixelPos) { return geoCoding.getPixelPos(geoPos, pixelPos); }
private void assertEquality(final GeoCoding gc1, final GeoCoding gc2, float accuracy) { assertNotNull(gc2); assertEquals(gc1.canGetGeoPos(), gc2.canGetGeoPos()); assertEquals(gc1.canGetPixelPos(), gc2.canGetPixelPos()); assertEquals(gc1.isCrossingMeridianAt180(), gc2.isCrossingMeridianAt180()); if (gc1 instanceof CrsGeoCoding) { assertEquals(CrsGeoCoding.class, gc2.getClass()); CRS.equalsIgnoreMetadata(gc1, gc2); } else if (gc1 instanceof TiePointGeoCoding) { assertEquals(TiePointGeoCoding.class, gc2.getClass()); } final int width = outProduct.getSceneRasterWidth(); final int height = outProduct.getSceneRasterHeight(); GeoPos geoPos1 = null; GeoPos geoPos2 = null; final String msgPattern = "%s at [%d,%d] is not equal:"; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { final PixelPos pixelPos = new PixelPos(i, j); geoPos1 = gc1.getGeoPos(pixelPos, geoPos1); geoPos2 = gc2.getGeoPos(pixelPos, geoPos2); assertEquals(String.format(msgPattern, "Latitude", i, j), geoPos1.lat, geoPos2.lat, accuracy); assertEquals(String.format(msgPattern, "Longitude", i, j), geoPos1.lon, geoPos2.lon, accuracy); } } }
throw new IllegalArgumentException("searchRadius < 2"); crossingMeridianAt180 = pixelPosEstimator.isCrossingMeridianAt180(); GeoPos p0 = pixelPosEstimator.getGeoPos(new PixelPos(0.5f, 0.5f), null); GeoPos p1 = pixelPosEstimator.getGeoPos(new PixelPos(1.5f, 0.5f), null);
@Override public boolean accept(Product product) { final GeoCoding geoCoding = product.getGeoCoding(); return geoCoding != null && geoCoding.canGetGeoPos() && geoCoding.canGetPixelPos(); } }
@Test public void testTransferGeoCodingWithoutSubset() { final boolean returnValue = srcScene.transferGeoCodingTo(destScene, null); assertTrue(returnValue); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); assertEquals(srcGeoCoding.getGeoCRS(), destGeoCoding.getGeoCRS()); assertEquals(srcGeoCoding.getGeoPos(new PixelPos(3.5f, 0.5f), null), destGeoCoding.getGeoPos(new PixelPos(3.5f, 0.5f), null)); }
@Test public void testTransferGeoCodingWithSubset_Subsampling() { final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setSubSampling(2, 4); final boolean transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); assertEquals(srcGeoCoding.getGeoCRS(), destGeoCoding.getGeoCRS()); comparePixelPos(destGeoCoding, new PixelPos(0, 0), new PixelPos(0, 0)); comparePixelPos(destGeoCoding, new PixelPos(8, 0), new PixelPos(4, 0)); comparePixelPos(destGeoCoding, new PixelPos(8, 16), new PixelPos(4, 4)); comparePixelPos(destGeoCoding, new PixelPos(0, 16), new PixelPos(0, 4)); }
/** * Checks whether or not this geo-coding can determine the pixel position from a geodetic position. * * @return <code>true</code>, if so */ @Override public boolean canGetPixelPos() { return getGeoCoding().canGetPixelPos(); }
public static GeoTIFFMetadata createGeoTIFFMetadata(GeoCoding geoCoding, int width, int height) { GeoTIFFMetadata metadata = null; if (geoCoding instanceof CrsGeoCoding || geoCoding instanceof MapGeoCoding) { metadata = createProjectedGeoTIFFMetadata(geoCoding.getMapCRS(), geoCoding.getImageToMapTransform()); } else if (geoCoding != null) { metadata = createFallbackGeoTIFFMetada(geoCoding, width, height); } return metadata; }
/** * Checks whether or not this geo-coding can determine the geodetic position from a pixel position. * * @return <code>true</code>, if so */ @Override public boolean canGetGeoPos() { return getGeoCoding().canGetGeoPos(); }
@Test public void testTransferGeoCodingWithSubset_Region() { final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setRegion(2, 2, 4, 4); final boolean transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); // position (3,3) in source equals (1,1) in dest comparePixelPos(destGeoCoding, new PixelPos(3, 3), new PixelPos(1, 1)); }
/** * Releases all of the resources used by this object instance and all of its owned children. Its primary use is to * allow the garbage collector to perform a vanilla job. * <p/> * <p>This method should be called only if it is for sure that this object instance will never be used again. The * results of referencing an instance of this class after a call to <code>dispose()</code> are undefined. */ @Override public void dispose() { for (GeoCoding gc : _gcList) { if (gc != null) { gc.dispose(); } } _gcList.clear(); }
private static Rectangle2D createMapBoundary(final Product product, CoordinateReferenceSystem targetCrs) { try { final CoordinateReferenceSystem sourceCrs = product.getGeoCoding().getImageCRS(); final int sourceW = product.getSceneRasterWidth(); final int sourceH = product.getSceneRasterHeight(); final Rectangle2D rect = XRectangle2D.createFromExtremums(0.5, 0.5, sourceW - 0.5, sourceH - 0.5); int pointsPerSide = Math.max(sourceH, sourceW) / 10; pointsPerSide = Math.max(9, pointsPerSide); final ReferencedEnvelope sourceEnvelope = new ReferencedEnvelope(rect, sourceCrs); final ReferencedEnvelope targetEnvelope = sourceEnvelope.transform(targetCrs, true, pointsPerSide); double minX = targetEnvelope.getMinX(); double width = targetEnvelope.getWidth(); if (product.getGeoCoding().isCrossingMeridianAt180()) { minX = -180.0; width = 360; } return new Rectangle2D.Double(minX, targetEnvelope.getMinY(), width, targetEnvelope.getHeight()); } catch (Exception e) { throw new IllegalStateException(e); } }
/** * Checks whether or not the longitudes of this geo-coding cross the +/- 180 degree meridian. * * @return <code>true</code>, if so */ @Override public boolean isCrossingMeridianAt180() { return getGeoCoding().isCrossingMeridianAt180(); }