Hello Xinke,
In your code, this expression...
(double) clippingAreaVertsModelCoors[2 * 1]
should be...
(double) clippingAreaVertsModelCoors[2 * i]
Michael
On 13 November 2011 18:38, lxkwh <[email protected]> wrote:
> Hi, I am going to crop Geotiff image using the Crop class in
> GeoTools(version 8.0-M2),but after running,message displayed as follows:
>
> Exception in thread "AWT-EventQueue-0"
> org.geotools.coverage.processing.CannotCropException: An error occurred
> while cropping.
>
> Why? How to modify the codes. Thans for your help.
>
> Below are my codes.
>
> GeoTiffReader gtReader = new GeoTiffReader(orthoImageFile);
>
> final GridCoverage2D gc = gtReader.read(null);
>
> GeometryFactory gf=new GeometryFactory();
>
>
>
> LinearRing lr=null;
>
> Coordinate coors[]=new Coordinate[count+1];
>
> for(int i=0;i<count;i++) coors[i]=new
> Coordinate((double)clippingAreaVertsModelCoors[2*1],(double)clippingAreaVertsModelCoors[2*i+1]);
>
> coors[count]=coors[0];
>
> lr=gf.createLinearRing(coors);
>
> com.vividsolutions.jts.geom.Polygon croppedPolygon=new
> com.vividsolutions.jts.geom.Polygon(lr, null, gf);
>
> Crop orthoImageCrop = new Crop();
>
> ParameterValueGroup orthoImageCropParameterValueGroup =
> orthoImageCrop.getParameters();
> orthoImageCropParameterValueGroup.parameter("Source").setValue(gc);
> orthoImageCropParameterValueGroup.parameter(Crop.PARAMNAME_ROI).setValue(croppedPolygon);
> // croppedPolygon
> (com.vividsolutions.jts.geom.Polygon)
>
> Hints hints=new Hints();
>
> GridCoverage2D gcCrop = (GridCoverage2D)
> orthoImageCrop.doOperation(orthoImageCropParameterValueGroup, hints).
>
> Li
> Xinke
> [email protected]
>
>
> 2011-11-13
> ________________________________
> lxkwh
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users