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();
}
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();
}
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);
}
}
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);
}
}
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();
}
Aggregations