From: Martin D. <mar...@no...> - 2005-12-19 01:10:10
|
Tom Howe a =E9crit : > I need to take a grid coverage and clip it based on a Polygon. My > plan was to just loop through the cells of the coverage and check to > see if polygon.contains(point) from the cell. If so,, then add the > value to a new coverage. I was thinking about constraining this > further by only checking the cells in that are contained in the > bounding box of the polygon. Any thoughts on if this is the best way > to approach the problem or any suggestions on how to do this? I can > brute force it, but I wanted to see if anyone had better suggestions. If the polygon is actually a rectangle, the "resample" operation whould=20 be quite efficient (it should maps to a JAI's "Crop" operation): GridRange newRange =3D new GeneralGridRange(...); GridGeometry newGeometry =3D new GridGeometry2D(newRange,=20 (MathTransform)null); Coverage newCoverage =3D Operations.resample(source, null, newGeometry, n= ull); For more complex geometry, we don't have yet any explict API in=20 Geotools. But the most efficient way may be to use the JAI operations.=20 I'm not sure which JAI operation is the most appropriate, since I have=20 not yet investigated this problem. Maybe the "AndConst" operation with=20 some javax.media.jai.ROIShape inferred from yours Geometry. If an=20 appropriate JAI operation is found, we can get the RenderedImage using=20 GridCoverage2D.getRenderedImage(), apply the JAI operation and recreate=20 the GridCoverage2D with the operation result. Actually I don't really have an easy way to suggest right now... Martin. |