@Override protected Void doInBackground(ProgressMonitor pm) throws Exception { final GeoCoding pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, validMask, searchRadius, pm); product.setGeoCoding(pixelGeoCoding); return null; }
private float interpolate(int x0, int y0, float wx, float wy, float[] data, int latLon) { final float min = (latLon == LAT) ? LAT_MIN : LON_MIN; final float max = (latLon == LAT) ? LAT_MAX : LON_MAX; final int x1 = x0 + 1; final int y1 = y0 + 1; final float d00 = data[width * y0 + x0]; if (d00 >= min && d00 <= max) { final float d10 = data[width * y0 + x1]; if (d10 >= min && d10 <= max) { final float d01 = data[width * y1 + x0]; if (d01 >= min && d01 <= max) { final float d11 = data[width * y1 + x1]; if (d11 >= min && d11 <= max) { if (latLon == LAT) { return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11); } else { return GeoCodingFactory.interpolateLon(wx, wy, d00, d10, d01, d11); } } } } } return d00; }
public static float interpolateLon(float wx, float wy, float d00, float d10, float d01, float d11) { float range = GeoCodingFactory.computeRange(d00, d01, d10, d11); if (range > 180f) { return GeoCodingFactory.interpolateSperical(wx, wy, d00, d10, d01, d11); } else { return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11); } }
@Override public boolean transferGeoCoding(final Scene srcScene, final Scene destScene, final ProductSubsetDef subsetDef) { final Band srcLatBand = getLatBand(); final Product destProduct = destScene.getProduct(); Band latBand = destProduct.getBand(srcLatBand.getName()); if (latBand == null) { latBand = GeoCodingFactory.createSubset(srcLatBand, destScene, subsetDef); destProduct.addBand(latBand); } final Band srcLonBand = getLonBand(); Band lonBand = destProduct.getBand(srcLonBand.getName()); if (lonBand == null) { lonBand = GeoCodingFactory.createSubset(srcLonBand, destScene, subsetDef); destProduct.addBand(lonBand); } String validMaskExpression = getValidMask(); try { if (validMaskExpression != null) { GeoCodingFactory.copyReferencedRasters(validMaskExpression, srcScene, destScene, subsetDef); } } catch (ParseException ignored) { validMaskExpression = null; } destScene.setGeoCoding(new PixelGeoCoding2(latBand, lonBand, validMaskExpression)); return true; }
static void copyReferencedRasters(String validMaskExpression, Scene sourceScene, Scene targetScene, ProductSubsetDef subsetDef) throws ParseException { final Product targetProduct = targetScene.getProduct(); final RasterDataNode[] nodes = BandArithmetic.getRefRasters(validMaskExpression, sourceScene.getProduct()); for (RasterDataNode node : nodes) { if (!targetProduct.containsRasterDataNode(node.getName())) { if (node instanceof TiePointGrid) { TiePointGrid tpg = TiePointGrid.createSubset((TiePointGrid) node, subsetDef); targetProduct.addTiePointGrid(tpg); } if (node instanceof Band) { final Band sourceBand = (Band) node; final Band band = createSubset(sourceBand, targetScene, subsetDef); targetProduct.addBand(band); setFlagCoding(band, sourceBand.getFlagCoding()); } } } }
private static void setFlagCoding(Band band, FlagCoding flagCoding) { if (flagCoding != null) { final String flagCodingName = flagCoding.getName(); final Product product = band.getProduct(); if (!product.getFlagCodingGroup().contains(flagCodingName)) { addFlagCoding(product, flagCoding); } band.setSampleCoding(product.getFlagCodingGroup().get(flagCodingName)); } }
Band latBand = destProduct.getBand(srcLatBand.getName()); if (latBand == null) { latBand = GeoCodingFactory.createSubset(srcLatBand, destScene, subsetDef); destProduct.addBand(latBand); Band lonBand = destProduct.getBand(srcLonBand.getName()); if (lonBand == null) { lonBand = GeoCodingFactory.createSubset(srcLonBand, destScene, subsetDef); destProduct.addBand(lonBand); try { if (validMaskExpression != null) { GeoCodingFactory.copyReferencedRasters(validMaskExpression, srcScene, destScene, subsetDef);
private static void addGeoCodingToProduct(Product product) { initTiePointGeoCoding(product); final boolean usePixeGeoCoding = Boolean.getBoolean(SYSPROP_ENVISAT_USE_PIXEL_GEO_CODING); if (usePixeGeoCoding) { Band latBand = product.getBand(EnvisatConstants.LAT_DS_NAME); if (latBand == null) { latBand = product.getBand(EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LATITUDE_BAND_NAME); } Band lonBand = product.getBand(EnvisatConstants.LON_DS_NAME); if (lonBand == null) { lonBand = product.getBand(EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LONGITUDE_BAND_NAME); } if (latBand != null && lonBand != null) { String validMask; if (EnvisatConstants.MERIS_L1_TYPE_PATTERN.matcher(product.getProductType()).matches()) { validMask = "NOT l1_flags.INVALID"; } else { validMask = "l2_flags.LAND or l2_flags.CLOUD or l2_flags.WATER"; } product.setGeoCoding(GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, validMask, 6)); } } }
private float interpolate(float wx, float wy, Raster raster, int band) { final int x0 = raster.getMinX(); final int x1 = x0 + 1; final int y0 = raster.getMinY(); final int y1 = y0 + 1; final float d00 = raster.getSampleFloat(x0, y0, band); final float d10 = raster.getSampleFloat(x1, y0, band); final float d01 = raster.getSampleFloat(x0, y1, band); final float d11 = raster.getSampleFloat(x1, y1, band); if (band == 0) { // lat return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11); } else { // lon return GeoCodingFactory.interpolateLon(wx, wy, d00, d10, d01, d11); } }
private static void testIllegalArgumentExceptionNotThrownByConstructor(Band b1, Band b2, String validMask, int searchRadius) { try { GeoCodingFactory.createPixelGeoCoding(b1, b2, validMask, searchRadius, ProgressMonitor.NULL); } catch (IOException e) { fail(); } catch (IllegalArgumentException e) { fail(); } }
float lon = GeoCodingFactory.interpolateLon(wx, wy, d00.lon, d10.lon, d01.lon, d11.lon); geoPos.setLocation(lat, lon); return geoPos;
private static GeoCoding readPixelGeoCoding(Product product) throws IOException { Band lonBand = product.getBand(Constants.LON_VAR_NAME); if (lonBand == null) { lonBand = product.getBand(Constants.LONGITUDE_VAR_NAME); } Band latBand = product.getBand(Constants.LAT_VAR_NAME); if (latBand == null) { latBand = product.getBand(Constants.LATITUDE_VAR_NAME); } if (latBand != null && lonBand != null) { return GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, latBand.getValidMaskExpression(), 5); } return null; }
private float interpolate(float wx, float wy, Raster raster, int latLon) { final float min = (latLon == LAT) ? LAT_MIN : LON_MIN; final float max = (latLon == LAT) ? LAT_MAX : LON_MAX; final int x0 = raster.getMinX() - raster.getSampleModelTranslateX(); final int x1 = x0 + 1; final int y0 = raster.getMinY() - raster.getSampleModelTranslateY(); final int y1 = y0 + 1; DataBuffer dataBuffer = raster.getDataBuffer(); SampleModel sampleModel = raster.getSampleModel(); final float d00 = sampleModel.getSampleFloat(x0, y0, 0, dataBuffer); if (d00 >= min && d00 <= max) { final float d10 = sampleModel.getSampleFloat(x1, y0, 0, dataBuffer); if (d10 >= min && d10 <= max) { final float d01 = sampleModel.getSampleFloat(x0, y1, 0, dataBuffer); if (d01 >= min && d01 <= max) { final float d11 = sampleModel.getSampleFloat(x1, y1, 0, dataBuffer); if (d11 >= min && d11 <= max) { if (latLon == LAT) { return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11); } else { return GeoCodingFactory.interpolateLon(wx, wy, d00, d10, d01, d11); } } } } } return d00; }
public void addGeocoding(final Product product) throws ProductIOException { final String longitude = "scat_beam_clon"; final String latitude = "scat_beam_clat"; Band latBand = null; Band lonBand = null; if (product.containsBand(latitude) && product.containsBand(longitude)) { latBand = product.getBand(latitude); lonBand = product.getBand(longitude); } if (latBand != null && lonBand != null) { product.setGeoCoding(GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 5)); } } }
private static GeoCoding createPixelGeoCoding(Product product, Datum datum, Element geoPosElem) { final String latBandName = geoPosElem.getChildTextTrim(DimapProductConstants.TAG_LATITUDE_BAND); final String lonBandName = geoPosElem.getChildTextTrim(DimapProductConstants.TAG_LONGITUDE_BAND); final Band latBand = product.getBand(latBandName); final Band lonBand = product.getBand(lonBandName); final Element searchRadiusElem = geoPosElem.getChild(DimapProductConstants.TAG_SEARCH_RADIUS); int searchRadius = Integer.parseInt(searchRadiusElem.getTextTrim()); if (searchRadius == 0) { searchRadius = 6; } String validMask = null; if (geoPosElem.getChild(DimapProductConstants.TAG_VALID_MASK_EXPRESSION) != null) { validMask = geoPosElem.getChildTextTrim(DimapProductConstants.TAG_VALID_MASK_EXPRESSION); } final Element posEstimatorElement = geoPosElem.getChild(DimapProductConstants.TAG_PIXEL_POSITION_ESTIMATOR); if (posEstimatorElement != null) { final Content posEstimatorContent = posEstimatorElement.detach(); final Document dom = new Document(); dom.addContent(posEstimatorContent); product.setGeoCoding(createGeoCoding(dom, product)[0]); } return GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, validMask, searchRadius); }
public void addGeocoding(final Product product) throws ProductIOException { final String longitude = "longitude"; final String latitude = "latitude"; Band latBand = product.getBand(latitude); Band lonBand = product.getBand(longitude); latBand.setNoDataValue(-999.); lonBand.setNoDataValue(-999.); latBand.setNoDataValueUsed(true); lonBand.setNoDataValueUsed(true); product.setGeoCoding(GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 5)); } }
private void initGeoCodings(Document dom) { final GeoCoding[] geoCodings = DimapProductHelpers.createGeoCoding(dom, product); if (geoCodings != null) { if (geoCodings.length == 1) { product.setGeoCoding(geoCodings[0]); } else { for (int i = 0; i < geoCodings.length; i++) { product.getBandAt(i).setGeoCoding(geoCodings[i]); } } } else { final Band lonBand = product.getBand("longitude"); final Band latBand = product.getBand("latitude"); if (latBand != null && lonBand != null) { final GeoCoding geoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 6); product.setGeoCoding(geoCoding); } } }
@Before public void setUp() throws Exception { sourceP = new Product("test", "test", 6, 7); final Band latBand = sourceP.addBand(bandNameLat, ProductData.TYPE_FLOAT32); fillWithData(latBand, 0.03f, 30f); final Band lonBand = sourceP.addBand(bandNameLon, ProductData.TYPE_FLOAT32); fillWithData(lonBand, 0.047f, 50f); pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 5); sourceP.setGeoCoding(pixelGeoCoding); }
/** * 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; }
Band latBand = p.getBand(Constants.LAT_VAR_NAME); if (latBand != null && lonBand != null) { geoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, latBand.getValidMaskExpression(), 5);