Ciao Ferdinando,
a few suggestions:

1> in order to downsample an image, i would take a look at the various
scale operations which are tailored for that scope.
There is only one caveaut: being based on JAI scale operations there
is no way to se the expected final width and heigh but this depends
slightly on the operation used. If you want to get some W and H
explicitly you need to use the resample operation which is backed by
the JAI Warp operation for subsampling.

2>If you just want to reproject to another CRS you can avoid providing
the gridgeometry. Just providing the target CRS would suffice.


Simone.

On Thu, Mar 27, 2008 at 3:16 PM, Ferdinando Villa
<[EMAIL PROTECTED]> wrote:
> Merci Martin,
>
> Much neater code, thanks. What I was doing wrong was to use a
> non-reprojected geometry parameter when asking for both reprojection and
> downsampling. I thought I tried that, but I used the wrong method to
> reproject the envelope; the semantics of the resample operation does not per
> se suggest which envelope is expected, original or transformed, when a
> transformation is also requested.
>
> I'm posting some working and commented stress-test code, so it's online in
> case anyone has the same doubts :)
>
> Thanks again,
> Ferdinando
> -----
>        // get input file - a 512x512 EPSG:26711 (NAD27 / 11)
>        final GeoTiffReader reader = new GeoTiffReader(new File(
>                "d:\\A\\utm.tif"));
>
>        final GridCoverage2D source = (GridCoverage2D) reader.read(null);
>        source.show();
>
>        // range corresponding to original size
>                GeneralGridRange range512 = new GeneralGridRange(new int[]
> {0, 0}, new int[] {512, 512});
>
>                Envelope2D quarterEnvelope = source.getEnvelope2D();
>                quarterEnvelope.height /= 2;
>                quarterEnvelope.width /= 2;
>
>                // original envelope (NAD27)
>                ReferencedEnvelope nad27Envelope =
>                        new ReferencedEnvelope(source.getEnvelope2D(),
> source.getCoordinateReferenceSystem());
>
>                ReferencedEnvelope nad27QuarterEnvelope =
>                        new ReferencedEnvelope(quarterEnvelope,
> source.getCoordinateReferenceSystem());
>
>                // half-resolution range
>                GeneralGridRange range256 = new GeneralGridRange(new int[]
> {0, 0}, new int[] {256, 256});
>
>                // WSG84-transformed envelope
>                ReferencedEnvelope wgs84Envelope = null;
>                ReferencedEnvelope wgs84QuarterEnvelope = null;
>
>                try {
>                        wgs84Envelope =
> nad27Envelope.transform(DefaultGeographicCRS.WGS84, true, 10);
>                        wgs84QuarterEnvelope =
> nad27QuarterEnvelope.transform(DefaultGeographicCRS.WGS84, true, 10);
>
>                } catch (Exception e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>
>                // all these geometries work when passed to resample with
> the appropriate projection
>                final GridGeometry2D gridGeometry_512_NAD27 = new
> GridGeometry2D(range512, nad27Envelope);
>                final GridGeometry2D gridGeometry_512_WGS84 = new
> GridGeometry2D(range512, wgs84Envelope);
>                final GridGeometry2D gridGeometry_256_NAD27 = new
> GridGeometry2D(range256, nad27Envelope);
>                final GridGeometry2D gridGeometry_256_WGS84 = new
> GridGeometry2D(range256, wgs84Envelope);
>                final GridGeometry2D gridGeometry_512_NAD27_Q = new
> GridGeometry2D(range512, nad27QuarterEnvelope);
>                final GridGeometry2D gridGeometry_512_WGS84_Q = new
> GridGeometry2D(range512, wgs84QuarterEnvelope);
>                final GridGeometry2D gridGeometry_256_NAD27_Q = new
> GridGeometry2D(range256, nad27QuarterEnvelope);
>                final GridGeometry2D gridGeometry_256_WGS84_Q = new
> GridGeometry2D(range256, wgs84QuarterEnvelope);
>
>                // choose one of the above; comment out the reprojection if
> using a NAD27 geometry
>                DefaultProcessor processor = new DefaultProcessor(null);
>                ParameterValueGroup resampleParams =
> processor.getOperation("Resample").getParameters();
>        resampleParams.parameter("Source").setValue(source);
>
> resampleParams.parameter("CoordinateReferenceSystem").setValue(DefaultGeogra
> phicCRS.WGS84);
>
> resampleParams.parameter("GridGeometry").setValue(gridGeometry_512_WGS84_Q);
>
>        // resample
>        final GridCoverage2D destination =
> (GridCoverage2D)processor.doOperation(resampleParams);
>        destination.show("transformed");
>
>
>
> -----Original Message-----
> From: Martin Desruisseaux [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 27, 2008 5:39 AM
> To: Ferdinando Villa
> Cc: [email protected]
> Subject: Re: [Geotools-gt2-users] Problem in coverage projection +
> resampling
>
> Typo:
>
> Martin Desruisseaux a écrit :
> > You would not suggest instantiate Resample() and invoke its
> doOperation(...)
> > method. I suggest to invoke processor.doOperation(resampleParams) instead.
>
> Was supposed to be:
> I would not suggest to instantiate Resample() and invoke its
> doOperation(...)
> method. I suggest to invoke processor.doOperation(resampleParams) instead.
>
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>



-- 
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions S.A.S.
Via Carignoni 51
55041 Camaiore (LU)
Italy

phone: +39 0584983027
fax: +39 0584983027
mob: +39 333 8128928


http://www.geo-solutions.it

-------------------------------------------------------

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to