use of org.esa.snap.core.datamodel.GeoCoding in project s1tbx by senbox-org.
the class MapToolsLayer method renderLayer.
@Override
protected void renderLayer(final Rendering rendering) {
final GeoCoding geoCoding = product.getSceneGeoCoding();
if (geoCoding == null)
return;
final ScreenPixelConverter screenPixel = new ScreenPixelConverter(rendering.getViewport(), raster);
if (!screenPixel.withInBounds()) {
return;
}
final Graphics2D graphics = rendering.getGraphics();
for (MapToolsComponent component : components) {
component.render(graphics, screenPixel);
}
}
use of org.esa.snap.core.datamodel.GeoCoding in project s1tbx by senbox-org.
the class Sentinel1Level1Directory method addGeoCoding.
@Override
protected void addGeoCoding(final Product product) {
TiePointGrid latGrid = product.getTiePointGrid(OperatorUtils.TPG_LATITUDE);
TiePointGrid lonGrid = product.getTiePointGrid(OperatorUtils.TPG_LONGITUDE);
if (latGrid != null && lonGrid != null) {
setLatLongMetadata(product, latGrid, lonGrid);
final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
product.setSceneGeoCoding(tpGeoCoding);
return;
}
final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
final String acquisitionMode = absRoot.getAttributeString(AbstractMetadata.ACQUISITION_MODE);
int numOfSubSwath;
switch(acquisitionMode) {
case "IW":
numOfSubSwath = 3;
break;
case "EW":
numOfSubSwath = 5;
break;
default:
numOfSubSwath = 1;
}
String[] bandNames = product.getBandNames();
Band firstSWBand = null, lastSWBand = null;
boolean firstSWBandFound = false, lastSWBandFound = false;
for (String bandName : bandNames) {
if (!firstSWBandFound && bandName.contains(acquisitionMode + 1)) {
firstSWBand = product.getBand(bandName);
firstSWBandFound = true;
}
if (!lastSWBandFound && bandName.contains(acquisitionMode + numOfSubSwath)) {
lastSWBand = product.getBand(bandName);
lastSWBandFound = true;
}
}
if (firstSWBand != null && lastSWBand != null) {
final GeoCoding firstSWBandGeoCoding = bandGeocodingMap.get(firstSWBand);
final int firstSWBandHeight = firstSWBand.getRasterHeight();
final GeoCoding lastSWBandGeoCoding = bandGeocodingMap.get(lastSWBand);
final int lastSWBandWidth = lastSWBand.getRasterWidth();
final int lastSWBandHeight = lastSWBand.getRasterHeight();
final PixelPos ulPix = new PixelPos(0, 0);
final PixelPos llPix = new PixelPos(0, firstSWBandHeight - 1);
final GeoPos ulGeo = new GeoPos();
final GeoPos llGeo = new GeoPos();
firstSWBandGeoCoding.getGeoPos(ulPix, ulGeo);
firstSWBandGeoCoding.getGeoPos(llPix, llGeo);
final PixelPos urPix = new PixelPos(lastSWBandWidth - 1, 0);
final PixelPos lrPix = new PixelPos(lastSWBandWidth - 1, lastSWBandHeight - 1);
final GeoPos urGeo = new GeoPos();
final GeoPos lrGeo = new GeoPos();
lastSWBandGeoCoding.getGeoPos(urPix, urGeo);
lastSWBandGeoCoding.getGeoPos(lrPix, lrGeo);
final float[] latCorners = { (float) ulGeo.getLat(), (float) urGeo.getLat(), (float) llGeo.getLat(), (float) lrGeo.getLat() };
final float[] lonCorners = { (float) ulGeo.getLon(), (float) urGeo.getLon(), (float) llGeo.getLon(), (float) lrGeo.getLon() };
ReaderUtils.addGeoCoding(product, latCorners, lonCorners);
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_lat, ulGeo.getLat());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_long, ulGeo.getLon());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_lat, urGeo.getLat());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_long, urGeo.getLon());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_lat, llGeo.getLat());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_long, llGeo.getLon());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_lat, lrGeo.getLat());
AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_long, lrGeo.getLon());
// add band geocoding
final Band[] bands = product.getBands();
for (Band band : bands) {
band.setGeoCoding(bandGeocodingMap.get(band));
}
} else {
try {
final String annotFolder = getRootFolder() + "annotation";
final String[] filenames = listFiles(annotFolder);
addTiePointGrids(product, null, filenames[0], "");
latGrid = product.getTiePointGrid(OperatorUtils.TPG_LATITUDE);
lonGrid = product.getTiePointGrid(OperatorUtils.TPG_LONGITUDE);
if (latGrid != null && lonGrid != null) {
setLatLongMetadata(product, latGrid, lonGrid);
final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid);
product.setSceneGeoCoding(tpGeoCoding);
}
} catch (IOException e) {
SystemUtils.LOG.severe("Unable to add tpg geocoding " + e.getMessage());
}
}
}
use of org.esa.snap.core.datamodel.GeoCoding in project s1tbx by senbox-org.
the class TestGeocoding method testProcessing.
/**
* Processes a product and compares it to processed product known to be correct
*
* @throws Exception general exception
*/
@Test
public void testProcessing() throws Exception {
final Product sourceProduct = TestUtils.readSourceProduct(inputFile);
GeoCoding gc = sourceProduct.getSceneGeoCoding();
GeoPos geo = new GeoPos();
PixelPos pix1 = new PixelPos();
PixelPos pix2 = new PixelPos();
double errorX = 0, errorY = 0;
int n = 0;
for (int i = 0; i < 1000; i += 10) {
pix1.setLocation(i + 0.5, i + 0.5);
gc.getGeoPos(pix1, geo);
gc.getPixelPos(geo, pix2);
errorX += Math.abs(pix1.getX() - pix2.getX());
errorY += Math.abs(pix1.getY() - pix2.getY());
TestUtils.log.info(pix1.getX() + " == " + pix2.getX() + ", " + pix1.getY() + " == " + pix2.getY());
++n;
}
System.out.println("\nerrorX=" + errorX);
System.out.println("errorY=" + errorY);
}
use of org.esa.snap.core.datamodel.GeoCoding in project s1tbx by senbox-org.
the class TestDEM2 method testPositionsUsingDEM.
/**
* Processes a product and compares it to processed product known to be correct
*
* @throws Exception general exception
*/
@Test
public void testPositionsUsingDEM() throws Exception {
GeoCoding geoCoding = sourceProduct.getSceneGeoCoding();
GeoPos geoPosUL = geoCoding.getGeoPos(new PixelPos(0, 0), null);
assertEquals(1924.39318847, srtmDem.getElevation(geoPosUL), 1e-8);
GeoPos geoPosUR = geoCoding.getGeoPos(new PixelPos(productWidth, 0), null);
assertEquals(1937.62377929, srtmDem.getElevation(geoPosUR), 1e-8);
GeoPos geoPosLL = geoCoding.getGeoPos(new PixelPos(0, productHeight), null);
assertEquals(564.75238037, srtmDem.getElevation(geoPosLL), 1e-8);
GeoPos geoPosLR = geoCoding.getGeoPos(new PixelPos(productWidth, productHeight), null);
assertEquals(2460.29052734, srtmDem.getElevation(geoPosLR), 1e-8);
GeoPos geoPosCenter = geoCoding.getGeoPos(new PixelPos(productWidth / 2.0, productHeight / 2.0), null);
assertEquals(3010.99121093, srtmDem.getElevation(geoPosCenter), 1e-8);
}
use of org.esa.snap.core.datamodel.GeoCoding in project s1tbx by senbox-org.
the class TestDEM2 method testPositionsUsingProductReader.
@Test
public void testPositionsUsingProductReader() throws Exception {
// trigger download of DEM file if not yet local
srtmDem.getElevation(new GeoPos(46.5, 10.5));
File demInstallDir = srtmDescriptor.getDemInstallDir();
File demFile = new File(demInstallDir, "srtm_39_03.zip");
Product demProduct = ProductIO.readProduct(demFile);
Band demBand = demProduct.getBandAt(0);
GeoCoding sourceGC = sourceProduct.getSceneGeoCoding();
GeoCoding demGC = demProduct.getSceneGeoCoding();
PixelPos ppUL = getDemPixelPos("ppUL", sourceGC, demGC, 0, 0);
assertEquals(1875, demBand.getSampleFloat((int) ppUL.getX(), (int) ppUL.getY()), 1.0e-6);
PixelPos ppUR = getDemPixelPos("ppUR", sourceGC, demGC, productWidth, 0);
assertEquals(1888, demBand.getSampleFloat((int) ppUR.getX(), (int) ppUR.getY()), 1.0e-6);
PixelPos ppLL = getDemPixelPos("ppLL", sourceGC, demGC, 0, productHeight);
assertEquals(515, demBand.getSampleFloat((int) ppLL.getX(), (int) ppLL.getY()), 1.0e-6);
PixelPos ppLR = getDemPixelPos("ppLR", sourceGC, demGC, productWidth, productHeight);
assertEquals(2410, demBand.getSampleFloat((int) ppLR.getX(), (int) ppLR.getY()), 1.0e-6);
PixelPos ppCenter = getDemPixelPos("ppCenter", sourceGC, demGC, (int) (productWidth / 2.0), (int) (productHeight / 2.0));
assertEquals(2961, demBand.getSampleFloat((int) ppCenter.getX(), (int) ppCenter.getY()), 1.0e-6);
}
Aggregations