Search in sources :

Example 1 with GeoCoding

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);
    }
}
Also used : ScreenPixelConverter(org.esa.s1tbx.dat.layers.ScreenPixelConverter) GeoCoding(org.esa.snap.core.datamodel.GeoCoding)

Example 2 with GeoCoding

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());
        }
    }
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) MetadataElement(org.esa.snap.core.datamodel.MetadataElement) Band(org.esa.snap.core.datamodel.Band) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding) TiePointGrid(org.esa.snap.core.datamodel.TiePointGrid) PixelPos(org.esa.snap.core.datamodel.PixelPos) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) TiePointGeoCoding(org.esa.snap.core.datamodel.TiePointGeoCoding)

Example 3 with GeoCoding

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);
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) Product(org.esa.snap.core.datamodel.Product) PixelPos(org.esa.snap.core.datamodel.PixelPos) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) Test(org.junit.Test)

Example 4 with GeoCoding

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);
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) PixelPos(org.esa.snap.core.datamodel.PixelPos) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) Test(org.junit.Test)

Example 5 with GeoCoding

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);
}
Also used : GeoPos(org.esa.snap.core.datamodel.GeoPos) Product(org.esa.snap.core.datamodel.Product) Band(org.esa.snap.core.datamodel.Band) File(java.io.File) PixelPos(org.esa.snap.core.datamodel.PixelPos) GeoCoding(org.esa.snap.core.datamodel.GeoCoding) Test(org.junit.Test)

Aggregations

GeoCoding (org.esa.snap.core.datamodel.GeoCoding)19 GeoPos (org.esa.snap.core.datamodel.GeoPos)17 PixelPos (org.esa.snap.core.datamodel.PixelPos)17 Product (org.esa.snap.core.datamodel.Product)10 Test (org.junit.Test)6 Band (org.esa.snap.core.datamodel.Band)5 TiePointGeoCoding (org.esa.snap.core.datamodel.TiePointGeoCoding)5 File (java.io.File)4 ScreenPixelConverter (org.esa.s1tbx.dat.layers.ScreenPixelConverter)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 Viewport (com.bc.ceres.grender.Viewport)2 MetadataElement (org.esa.snap.core.datamodel.MetadataElement)2 RasterDataNode (org.esa.snap.core.datamodel.RasterDataNode)2 TiePointGrid (org.esa.snap.core.datamodel.TiePointGrid)2 VirtualBand (org.esa.snap.core.datamodel.VirtualBand)2 OperatorException (org.esa.snap.core.gpf.OperatorException)2 TargetProduct (org.esa.snap.core.gpf.annotations.TargetProduct)2 Geometry (org.locationtech.jts.geom.Geometry)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1