Search in sources :

Example 11 with RectifiedGrid

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);
}
Also used : MetadataHelper(org.geotoolkit.image.io.metadata.MetadataHelper) SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata) RectifiedGrid(org.opengis.coverage.grid.RectifiedGrid) AffineTransform(java.awt.geom.AffineTransform)

Example 12 with RectifiedGrid

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);
                }
            }
        }
    }
}
Also used : MetadataHelper(org.geotoolkit.image.io.metadata.MetadataHelper) SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata) ImageCRS(org.opengis.referencing.crs.ImageCRS) RectifiedGrid(org.opengis.coverage.grid.RectifiedGrid) OutputStream(java.io.OutputStream) AffineTransform(java.awt.geom.AffineTransform) IIOException(javax.imageio.IIOException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

RectifiedGrid (org.opengis.coverage.grid.RectifiedGrid)12 AffineTransform (java.awt.geom.AffineTransform)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 SpatialMetadata (org.geotoolkit.image.io.metadata.SpatialMetadata)4 GridDomainAccessor (org.geotoolkit.internal.image.io.GridDomainAccessor)4 IIOException (javax.imageio.IIOException)3 MetadataHelper (org.geotoolkit.image.io.metadata.MetadataHelper)3 Georectified (org.opengis.metadata.spatial.Georectified)3 PixelOrientation (org.opengis.metadata.spatial.PixelOrientation)3 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)2 ImageMetadataException (org.geotoolkit.image.io.ImageMetadataException)2 GridEnvelope (org.opengis.coverage.grid.GridEnvelope)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 Dimension2D (java.awt.geom.Dimension2D)1 Point2D (java.awt.geom.Point2D)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1