M. Purbo a écrit :
My objective is:

to have a simple function to get an image given any box within the
boundary (3) above with a specific CRS. Something like:

Image getImage(float x1, float y1, float x2, float y2,
CoordinateReferenceSystem crs);

This function supposed to get some portion of one file, some from
another, etc., should the box requested covers the area of more than 1
image.

There is not method in Geotools at this time for assembling many images into a single one. GridCoverage2D may still be of some help however, especially if images have different CRS or resolution.

A GridCoverage2D is basically:

   RenderedImage + CRS + Envelope (+ some info about the pixel values)

Create one GridCoverage for each image with proper CRS and Envelope informations. Next, choose a CRS and image size for the destination image (the CRS doesn't need to be the same than source images). Then, create the GridGeometry2D which describe the geometry of yours target image:

Rectangle r = ... yours image size
Envelope  e = ... the envelope of the target image
GridGeometry2D gm = new GridGeometry2D(new GeneralGridRange(r), e);

Then, resample each source images using:

target = (GridCoverage2D) Operations.resample(source, crs, gm, null);

where 'crs' is yours target CRS (should be the same than the Envelope CRS, if a CRS were given to 'e' above). You will get a bunch of images with exactly the same size, envelope and CRS. You should be able to combine them using JAI operations (I have not searched the JAI javadoc for the exact method).

Note: the above method may take a fair amount of memory since each target image may have only a small area actually covered by pixel values. In order to crop each target image to only the required part, add the following line before the call to 'resample':

gm = new GridGeometry2D(null, gm.getGridToCoordinateSystem());

It will basically erase the 'grid range' information from the grid geometry. The resample operation will then compute the minimal grid range needed for each image. It will use less memory, but assembling images in a single one may be more difficult.

        Martin.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to