|
I am attempting to crop a raster by specifying a geobounds (ReferencedEnvelope) and a shapefile. My approach is to use the CoverageCrop processor using the ROI parameter. The ROI parameter is a GeometryCollection consisting of all the features in the shapefile (which are Polygons and MultiPolygons).
For broad bounds it seems to work. However, with narrow bounds, I see two modes of failure that I've traced down to Crop.java:
A. uncropped coverage.
pbj.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
pbj.add(null);
pbj.add(roiarr);
pbj.add(null);
pbj.add(CoverageUtilities.getBackgroundValues(sourceCoverage));
//prepare the final layout
final Rectangle bounds = rasterSpaceROI.getBounds2D().getBounds();
Rectangle.intersect(bounds, sourceGridRange, bounds);
if(bounds.isEmpty())
throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP));
// we do not have to crop in this case (should not really happen at
// this time)
if (bounds.getBounds().equals(sourceGridRange) && isSimpleTransform)
return sourceCoverage; /// Note that this is a silent failure.
B. IllegalArgumentException: Dimension are too large (??)
//conserve the input grid to world transformation
return new GridCoverageFactory(hints).create(
sourceCoverage.getName(),
croppedImage,
new GridGeometry2D(
new GridEnvelope2D(croppedImage.getBounds()), // getBounds fails. croppedImage.bounds has height == width == 0.0
sourceGridGeometry.getGridToCRS2D(PixelOrientation.CENTER),
sourceCoverage.getCoordinateReferenceSystem()
),
(GridSampleDimension[]) (actionTaken == 1 ?null :sourceCoverage.getSampleDimensions().clone()),
new GridCoverage[]
{ sourceCoverage }
,
rasterSpaceROI != null ?Collections.singletonMap("GC_ROI", rasterSpaceROI) :null
);
I am attaching a repro case that uses GT v10.0: See tutorial/org.geotools.msr.ImageTest.java:
// NG: returns uncropped coverage: ReferencedEnvelope bounds = new ReferencedEnvelope(-124.5, -122.25, 46.8, 48.5, DefaultGeographicCRS.WGS84);
// NG: Dimensions too large: ReferencedEnvelope bounds = new ReferencedEnvelope(-124.8, -122.25, 46.8, 48.5, DefaultGeographicCRS.WGS84);
// OK for smaller version of the shapefile with only USA feature,
// BUT NG for full dataset result in Dimensions too large: ReferencedEnvelope bounds = new ReferencedEnvelope(-125, -122.25, 46.8, 48.5, DefaultGeographicCRS.WGS84);
// OK
ReferencedEnvelope bounds = new ReferencedEnvelope(-130, -122.25, 46.8, 48.5, DefaultGeographicCRS.WGS84);
I've also reproduced with GT 2.7.3
|