Search in sources :

Example 1 with GCP

use of it.geosolutions.imageio.core.GCP in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest method testGCP.

/**
 * Test Read exploiting JAI-ImageIO tools capabilities
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void testGCP() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    String fileName = "gcp.tif.vrt";
    final File file = TestData.file(this, fileName);
    ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
    reader.setInput(file);
    GDALCommonIIOImageMetadata metadata = (GDALCommonIIOImageMetadata) reader.getImageMetadata(0);
    final int gcpNumber = metadata.getGcpNumber();
    Assert.assertEquals(gcpNumber, 4);
    final List<GCP> gcps = metadata.getGCPs();
    Assert.assertNotNull(gcps);
    Assert.assertFalse(gcps.isEmpty());
    for (int i = 0; i < 4; i++) {
        Assert.assertEquals(gcps.get(i), referenceGCPs.get(i));
    }
    reader.dispose();
}
Also used : GCP(it.geosolutions.imageio.core.GCP) GDALCommonIIOImageMetadata(it.geosolutions.imageio.gdalframework.GDALCommonIIOImageMetadata) ImageReader(javax.imageio.ImageReader) File(java.io.File) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 2 with GCP

use of it.geosolutions.imageio.core.GCP in project imageio-ext by geosolutions-it.

the class GeoTiffTest method testGCP.

/**
 * Test Read exploiting JAI-ImageIO tools capabilities
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void testGCP() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    String fileName = "gcp.tif";
    final File file = TestData.file(this, fileName);
    ImageReader reader = new GeoTiffImageReaderSpi().createReaderInstance();
    reader.setInput(file);
    GDALCommonIIOImageMetadata metadata = (GDALCommonIIOImageMetadata) reader.getImageMetadata(0);
    final int gcpNumber = metadata.getGcpNumber();
    Assert.assertEquals(gcpNumber, 4);
    final List<GCP> gcps = metadata.getGCPs();
    Assert.assertNotNull(gcps);
    Assert.assertFalse(gcps.isEmpty());
    for (int i = 0; i < 4; i++) {
        Assert.assertEquals(gcps.get(i), referenceGCPs.get(i));
    }
    reader.dispose();
}
Also used : GCP(it.geosolutions.imageio.core.GCP) GDALCommonIIOImageMetadata(it.geosolutions.imageio.gdalframework.GDALCommonIIOImageMetadata) ImageReader(javax.imageio.ImageReader) File(java.io.File) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 3 with GCP

use of it.geosolutions.imageio.core.GCP in project imageio-ext by geosolutions-it.

the class GeoTiffTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    File file = TestData.file(this, "test-data.zip");
    Assert.assertTrue(file.exists());
    // unzip it
    TestData.unzipFile(this, "test-data.zip");
    final int[] columns = new int[] { 0, 50, 0, 50 };
    final int[] rows = new int[] { 0, 50, 50, 0 };
    final int[] easting = new int[] { -180, -135, -180, -135 };
    final int[] northing = new int[] { 90, 45, 45, 90 };
    for (int i = 0; i < 4; i++) {
        GCP gcp = new GCP();
        gcp.setId(Integer.toString(i + 1));
        gcp.setDescription("");
        gcp.setColumn(columns[i]);
        gcp.setRow(rows[i]);
        gcp.setEasting(easting[i]);
        gcp.setNorthing(northing[i]);
        referenceGCPs.add(gcp);
    }
}
Also used : GCP(it.geosolutions.imageio.core.GCP) File(java.io.File) Before(org.junit.Before)

Example 4 with GCP

use of it.geosolutions.imageio.core.GCP in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    File file = TestData.file(this, "test-geotiff-data.zip");
    Assert.assertTrue(file.exists());
    // unzip it
    TestData.unzipFile(this, "test-geotiff-data.zip");
    final int[] columns = new int[] { 0, 50, 0, 50 };
    final int[] rows = new int[] { 0, 50, 50, 0 };
    final int[] easting = new int[] { -180, -135, -180, -135 };
    final int[] northing = new int[] { 90, 45, 45, 90 };
    for (int i = 0; i < 4; i++) {
        GCP gcp = new GCP();
        gcp.setId(Integer.toString(i + 1));
        gcp.setDescription("");
        gcp.setColumn(columns[i]);
        gcp.setRow(rows[i]);
        gcp.setEasting(easting[i]);
        gcp.setNorthing(northing[i]);
        referenceGCPs.add(gcp);
    }
}
Also used : GCP(it.geosolutions.imageio.core.GCP) File(java.io.File) Before(org.junit.Before)

Example 5 with GCP

use of it.geosolutions.imageio.core.GCP in project imageio-ext by geosolutions-it.

the class GDALCommonIIOImageMetadata method getGCPs.

/**
 * Returns the Ground Control Points
 */
public List<GCP> getGCPs() {
    if (super.getGCPs().isEmpty()) {
        Dataset ds = null;
        try {
            // Getting the number of GCPs
            final int nGCP = getGcpNumber();
            List<org.gdal.gdal.GCP> gcps = new Vector<org.gdal.gdal.GCP>(nGCP);
            ds = GDALUtilities.acquireDataSet(getDatasetName(), gdalconst.GA_ReadOnly);
            ds.GetGCPs((Vector<org.gdal.gdal.GCP>) gcps);
            // Scan GCPs
            if (gcps != null && !gcps.isEmpty()) {
                final List<GCP> groundControlPoints = new ArrayList<GCP>(nGCP);
                final Iterator<org.gdal.gdal.GCP> it = gcps.iterator();
                while (it.hasNext()) {
                    org.gdal.gdal.GCP gdalGcp = null;
                    try {
                        // Setting up a GCP
                        gdalGcp = (org.gdal.gdal.GCP) it.next();
                        GCP gcp = new GCP();
                        gcp.setId(gdalGcp.getId());
                        gcp.setDescription(gdalGcp.getInfo());
                        gcp.setColumn((int) gdalGcp.getGCPPixel());
                        gcp.setRow((int) gdalGcp.getGCPLine());
                        gcp.setEasting(gdalGcp.getGCPX());
                        gcp.setNorthing(gdalGcp.getGCPY());
                        gcp.setElevation(gdalGcp.getGCPZ());
                        groundControlPoints.add(gcp);
                    } finally {
                        if (gdalGcp != null) {
                            try {
                                // Releasing native GCP object
                                gdalGcp.delete();
                            } catch (Throwable e) {
                                if (LOGGER.isLoggable(Level.FINEST))
                                    LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
                            }
                        }
                    }
                }
                setGcps(groundControlPoints);
            }
        } finally {
            if (ds != null) {
                try {
                    // Closing the dataset
                    GDALUtilities.closeDataSet(ds);
                } catch (Throwable e) {
                    if (LOGGER.isLoggable(Level.FINEST))
                        LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
                }
            }
        }
    }
    return super.getGCPs();
}
Also used : GCP(it.geosolutions.imageio.core.GCP) Dataset(org.gdal.gdal.Dataset) org.gdal.gdal.gdal(org.gdal.gdal.gdal) ArrayList(java.util.ArrayList) Vector(java.util.Vector)

Aggregations

GCP (it.geosolutions.imageio.core.GCP)5 File (java.io.File)4 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)2 GDALCommonIIOImageMetadata (it.geosolutions.imageio.gdalframework.GDALCommonIIOImageMetadata)2 ImageReader (javax.imageio.ImageReader)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 Dataset (org.gdal.gdal.Dataset)1 org.gdal.gdal.gdal (org.gdal.gdal.gdal)1