Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-338] Refactor Raster Construction to use AffineTrasform instead of Envelope #938

Closed

Conversation

iGN5117
Copy link
Contributor

@iGN5117 iGN5117 commented Aug 2, 2023

Did you read the Contributor Guide?

Is this PR related to a JIRA ticket?

What changes were proposed in this PR?

  • Refactor Raster Construction

How was this patch tested?

  • Verified existing tests

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the docs.

// Create a new coverage
GridCoverageFactory gridCoverageFactory = CoverageFactoryFinder.getGridCoverageFactory(null);
return gridCoverageFactory.create("genericCoverage", raster, referencedEnvelope);
return gridCoverageFactory.create("genericCoverage", raster, crs, transform, null, null, null, null, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can specify the anchor to be PixelInCell.CELL_CORNER to follow the convention of GDAL and PostGIS. I have some code for doing this, you can take a look.

        // Create a new empty raster
        int rasterDataType = DataBuffer.TYPE_DOUBLE;
        WritableRaster raster = RasterFactory.createBandedRaster(rasterDataType, widthInPixel, heightInPixel, numBand, null);
        MathTransform transform = new AffineTransform2D(scaleX, skewY, skewX, scaleY, upperLeftX, upperLeftY);
        GridGeometry2D gridGeometry = new GridGeometry2D(
                new GridEnvelope2D(0, 0, widthInPixel, heightInPixel),
                PixelInCell.CELL_CORNER,
                transform, crs, null);

        // Create a new coverage
        final ColorSpace cs = new BogusColorSpace(numBand);
        final int[] nBits = new int[numBand];
        Arrays.fill(nBits, DataBuffer.getDataTypeSize(rasterDataType));
        ColorModel colorModel =
                new ComponentColorModel(cs, nBits, false, true, Transparency.OPAQUE, rasterDataType);
        final RenderedImage image = new BufferedImage(colorModel, raster, false, null);
        GridCoverageFactory gridCoverageFactory = CoverageFactoryFinder.getGridCoverageFactory(null);
        return gridCoverageFactory.create("genericCoverage", image, gridGeometry, null, null, null);

@Kontinuation
Copy link
Member

I've taken over this task and submitted #940.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants