private static boolean transferGeoCoding(final Scene sourceScene, final Scene targetScene, final ProductSubsetDef subsetDef) { final GeoCoding sourceGeoCoding = sourceScene.getGeoCoding(); if (sourceGeoCoding == null) { targetScene.setGeoCoding(null); return true; } if (sourceGeoCoding instanceof AbstractGeoCoding) { AbstractGeoCoding abstractGeoCoding = (AbstractGeoCoding) sourceGeoCoding; return abstractGeoCoding.transferGeoCoding(sourceScene, targetScene, subsetDef); } return false; }
public void testTransferGeoCoding() { final Scene srcScene = SceneFactory.createScene(createProduct()); final Scene destScene = SceneFactory.createScene(new Product("test2", "test2", PW, PH)); final boolean transferred = srcScene.transferGeoCodingTo(destScene, null); assertTrue(transferred); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertTrue(destGeoCoding instanceof TiePointGeoCoding); final PixelPos pixelPos = new PixelPos(PW/2.0f, PH/2.0f); final GeoPos srcGeoPos = srcScene.getGeoCoding().getGeoPos(pixelPos, null); final GeoPos destGeoPos = destScene.getGeoCoding().getGeoPos(pixelPos, null); assertEquals(srcGeoPos, destGeoPos); }
/** * Creates a model for an image pyramid. The method makes us of the * {@link org.esa.beam.framework.datamodel.Product#getNumResolutionsMax()} method in order to determine the * number of resolution levels for the pyramid. * * @param productNode The product node requesting the model. * @return A new image pyramid model. */ public static MultiLevelModel createMultiLevelModel(ProductNode productNode) { final Scene scene = SceneFactory.createScene(productNode); if (scene == null) { return null; } final int w = scene.getRasterWidth(); final int h = scene.getRasterHeight(); final AffineTransform i2mTransform = getImageToModelTransform(scene.getGeoCoding()); final Product product = scene.getProduct(); if (product != null && product.getNumResolutionsMax() > 0) { return new DefaultMultiLevelModel(product.getNumResolutionsMax(), i2mTransform, w, h); } else { return new DefaultMultiLevelModel(i2mTransform, w, h); } }
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); }
/** * Transfers the geo-coding of the {@link org.esa.beam.framework.datamodel.Scene srcScene} to the {@link org.esa.beam.framework.datamodel.Scene destScene} with respect to the given * {@link org.esa.beam.framework.dataio.ProductSubsetDef subsetDef}. * * @param srcScene the source scene * @param destScene the destination scene * @param subsetDef the definition of the subset, may be <code>null</code> * @return true, if the geo-coding could be transferred. */ @Override public boolean transferGeoCoding(final Scene srcScene, final Scene destScene, final ProductSubsetDef subsetDef) { BowtiePixelGeoCoding srcGeocoding = (BowtiePixelGeoCoding) srcScene.getGeoCoding(); final String latBandName = srcGeocoding._latBand.getName(); final String lonBandName = srcGeocoding._lonBand.getName(); ensureLatLonBands(destScene, subsetDef); final Band targetLatBand = destScene.getProduct().getBand(latBandName); final Band targetLonBand = destScene.getProduct().getBand(lonBandName); if (subsetDef != null) { if (subsetDef.getSubSamplingY() != 1) { destScene.setGeoCoding(GeoCodingFactory.createPixelGeoCoding(targetLatBand, targetLonBand, null, 5)); return true; } } if (targetLatBand != null && targetLonBand != null) { destScene.setGeoCoding(new BowtiePixelGeoCoding(targetLatBand, targetLonBand, srcGeocoding._scanlineHeight)); return true; } return false; }
@Test public void testCrossing180() throws Exception { final Rectangle imageBounds = new Rectangle(10, 20); srcGeoCoding = createCrsGeoCodingCross180(imageBounds); assertTrue(srcGeoCoding.isCrossingMeridianAt180()); final Band srcNode = new Band("srcDummy", ProductData.TYPE_INT8, 10, 20); srcNode.setGeoCoding(srcGeoCoding); srcScene = SceneFactory.createScene(srcNode); final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setRegion(2, 2, 8, 8); subsetDef.setSubSampling(2, 2); boolean transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); assertTrue(destScene.getGeoCoding().isCrossingMeridianAt180()); subsetDef.setRegion(2, 2, 2, 2); transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); assertFalse(destScene.getGeoCoding().isCrossingMeridianAt180()); }
final MapGeoCoding srcMapGeoCoding = ((MapGeoCoding) srcScene.getGeoCoding()); final MapInfo srcMapInfo = srcMapGeoCoding.getMapInfo(); float pixelX = srcMapInfo.getPixelX();
@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)); }
@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)); }
public void testTransferGeoCodingWithoutSubset() { MapGeoCoding mapGeoCoding = createIdentityMapGeoCoding(); final Band destNode = new Band("destDummy", ProductData.TYPE_INT8, 10, 20); final Band srcNode = new Band("srcDummy", ProductData.TYPE_INT8, 10, 20); srcNode.setGeoCoding(mapGeoCoding); final Scene destScene = SceneFactory.createScene(destNode); final Scene srcScene = SceneFactory.createScene(srcNode); srcScene.transferGeoCodingTo(destScene, null); assertNotSame(mapGeoCoding, destScene.getGeoCoding()); final MapInfo origMapInfo = mapGeoCoding.getMapInfo(); final MapInfo copyMapInfo = ((MapGeoCoding) destScene.getGeoCoding()).getMapInfo(); assertNotSame(origMapInfo, copyMapInfo); assertEquals(origMapInfo.getEasting(), copyMapInfo.getEasting(), 1e-6); assertEquals(origMapInfo.getNorthing(), copyMapInfo.getNorthing(), 1e-6); assertSame(origMapInfo.getDatum(), copyMapInfo.getDatum()); assertEquals(origMapInfo.getElevationModelName(), copyMapInfo.getElevationModelName()); assertEquals(origMapInfo.getMapProjection().getName(), copyMapInfo.getMapProjection().getName()); assertEquals(origMapInfo.getOrientation(), copyMapInfo.getOrientation(), 1e-6); assertEquals(origMapInfo.getPixelSizeX(), copyMapInfo.getPixelSizeX(), 1e-6); assertEquals(origMapInfo.getPixelSizeY(), copyMapInfo.getPixelSizeY(), 1e-6); assertEquals(origMapInfo.getPixelX(), copyMapInfo.getPixelY(), 1e-6); assertEquals(destScene.getRasterHeight(), copyMapInfo.getSceneHeight(), 1e-6); assertEquals(destScene.getRasterWidth(), copyMapInfo.getSceneWidth(), 1e-6); }
@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)); }
@Test public void testTransferGeoCodingWithSubset_SubsamplingAndRegion() { final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setRegion(2, 2, 8, 8); subsetDef.setSubSampling(2, 2); 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(2, 2), new PixelPos(0, 0)); comparePixelPos(destGeoCoding, new PixelPos(10, 2), new PixelPos(4, 0)); comparePixelPos(destGeoCoding, new PixelPos(10, 10), new PixelPos(4, 4)); comparePixelPos(destGeoCoding, new PixelPos(2, 10), new PixelPos(0, 4)); }
public void testTransferGeoCodingWithSubSampling() { final Scene srcScene = SceneFactory.createScene(new Band("srcTest", ProductData.TYPE_UINT8, 10, 10)); final Scene destScene = SceneFactory.createScene(new Band("destTest", ProductData.TYPE_UINT8, 4, 4)); final ProductSubsetDef subsetDef = new ProductSubsetDef("testSubset"); subsetDef.setSubSampling(3, 3); _srcGeoCoding.transferGeoCoding(srcScene, destScene, subsetDef); final GeoCoding actGeoCoding = destScene.getGeoCoding(); assertNotNull(actGeoCoding); final PixelPos srcPixelPos = new PixelPos(); final PixelPos destPixelPos = new PixelPos(); srcPixelPos.setLocation(0, 0); destPixelPos.setLocation(0, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(3, 0); destPixelPos.setLocation(1, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(6, 0); destPixelPos.setLocation(2, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(9, 0); destPixelPos.setLocation(3, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); }
public void testTransferGeoCodingWithRegion() { final Scene srcScene = SceneFactory.createScene(new Band("srcTest", ProductData.TYPE_UINT8, 10, 10)); final Scene destScene = SceneFactory.createScene(new Band("destTest", ProductData.TYPE_UINT8, 4, 3)); final ProductSubsetDef subsetDef = new ProductSubsetDef("testSubset"); subsetDef.setRegion(3, 1, 4, 3); _srcGeoCoding.transferGeoCoding(srcScene, destScene, subsetDef); final GeoCoding actGeoCoding = destScene.getGeoCoding(); assertNotNull(actGeoCoding); final PixelPos srcPixelPos = new PixelPos(); final PixelPos destPixelPos = new PixelPos(); srcPixelPos.setLocation(3, 1); destPixelPos.setLocation(0, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(5, 1); destPixelPos.setLocation(2, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(6, 2); destPixelPos.setLocation(3, 1); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(4, 3); destPixelPos.setLocation(1, 2); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); }
public void testTransferGeoCodingWithRegionAndSubsampling() { final Scene srcScene = SceneFactory.createScene(new Band("srcTest", ProductData.TYPE_UINT8, 10, 10)); final Scene destScene = SceneFactory.createScene(new Band("destTest", ProductData.TYPE_UINT8, 2, 2)); final ProductSubsetDef subsetDef = new ProductSubsetDef("testSubset"); subsetDef.setRegion(3, 1, 4, 3); subsetDef.setSubSampling(2, 2); _srcGeoCoding.transferGeoCoding(srcScene, destScene, subsetDef); final GeoCoding actGeoCoding = destScene.getGeoCoding(); assertNotNull(actGeoCoding); final PixelPos srcPixelPos = new PixelPos(); final PixelPos destPixelPos = new PixelPos(); srcPixelPos.setLocation(3, 1); destPixelPos.setLocation(0, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(5, 1); destPixelPos.setLocation(1, 0); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(3, 3); destPixelPos.setLocation(0, 1); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); srcPixelPos.setLocation(5, 3); destPixelPos.setLocation(1, 1); assertEquals(_srcGeoCoding.getGeoPos(srcPixelPos, null), actGeoCoding.getGeoPos(destPixelPos, null)); }