use of org.opengis.coverage.grid.RectifiedGrid in project geotoolkit by Geomatys.
the class ImageCoverageWriterInspector method assertRectifiedGridEquals.
/**
* Tests that the rectified grid is equals to the given affine transform coefficients.
*
* @since 3.17
*/
public void assertRectifiedGridEquals(final double scaleX, final double scaleY, final double translateX, final double translateY) throws ImageMetadataException {
assertInstanceOf("Expected a spatial metadata", SpatialMetadata.class, metadata);
final MetadataHelper helper = new MetadataHelper(null);
final RectifiedGrid rg = ((SpatialMetadata) metadata).getInstanceForType(RectifiedGrid.class);
final AffineTransform tr = helper.getAffineTransform(rg, null);
assertEquals("shearX", 0, tr.getShearX(), EPS);
assertEquals("shearY", 0, tr.getShearY(), EPS);
assertEquals("scaleX", scaleX, tr.getScaleX(), EPS);
assertEquals("scaleY", scaleY, tr.getScaleY(), EPS);
assertEquals("translateX", translateX, tr.getTranslateX(), EPS);
assertEquals("translateY", translateY, tr.getTranslateY(), EPS);
}
use of org.opengis.coverage.grid.RectifiedGrid in project geotoolkit by Geomatys.
the class WorldFileImageWriter method writeImageMetadata.
/**
* Invoked by the {@code write} methods when image metadata needs to be written.
* The default implementation writes the <cite>World File</cite> if an affine
* transform can be build from the {@linkplain RectifiedGrid rectified grid domain}.
*/
@Override
protected void writeImageMetadata(final IIOMetadata metadata, final int imageIndex, final ImageWriteParam param) throws IOException {
if (imageIndex != 0) {
throw new IIOException(Errors.getResources(locale).getString(Errors.Keys.IndexOutOfBounds_1, imageIndex));
}
if (metadata instanceof SpatialMetadata) {
final SpatialMetadata md = (SpatialMetadata) metadata;
final RectifiedGrid rf = md.getInstanceForType(RectifiedGrid.class);
if (rf != null) {
final MetadataHelper mh = new MetadataHelper(md);
final AffineTransform tr = mh.getAffineTransform(rf, param);
final Object path = createOutput("tfw");
if (path != null) {
try (OutputStream out = IOUtilities.openWrite(path)) {
SupportFiles.writeTFW(out, tr);
}
}
}
/*
* Write the CRS if non-null and not an instance of ImageCRS. The ImageCRS case is
* excluded because it is the default CRS assigned by WorldFileImageReader when no
* ".prj" file were found.
*/
final CoordinateReferenceSystem crs = md.getInstanceForType(CoordinateReferenceSystem.class);
if (crs != null && !(crs instanceof ImageCRS)) {
final Object path = createOutput("prj");
if (path != null) {
try (OutputStream out = IOUtilities.openWrite(path)) {
PrjFiles.write(crs, out);
}
}
}
}
}
Aggregations