Ciao Martin,
this is a snippet that can help  I believe:

http://pastebin.com/Zqb7jzBt

It does show how to read and crop a coverage.

See also below...

---------------------------------------------------
Ing. Simone Giannecchini
GeoSolutions S.A.S.
Founder - Software Engineer
Via Carignoni 51
55041  Camaiore (LU)
Italy

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


http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.linkedin.com/in/simonegiannecchini
http://twitter.com/simogeo

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



On Wed, May 5, 2010 at 9:50 AM, Martin Tomko <[email protected]> wrote:
> Hi guys (Andrea *2, Michael )
> thanks for the hints. Indeed, the GridGeometry2D approach will not help
> my case, but a similar approach should be somehow possible.
>
> IN fact, if it was possible to read the current envelope of the geotiff
> in without the actual raster data, do the cropping operation and return
> a meaningful return envelope, and only read parts of the raster in it
> would be great.
>
> Thanks for the pointer to the cropping operation, I do something similar
> now, although it still requires having the whole original GridCoverage2D
> in memory...:

That is not correct.
By default in geotools, (at least with the raster formats I have been
involved to) creating a GC2D from a Reader does not imply that you
have loaded any data in memory since we rely on JAI  deferred loading
mechanism to load the data you really need only when you need it. This
means that if you create a GC2D from a geotiff, then you crop it and
then you write it as in the example provided, we will try, leveraging
JAI and ImageIO to read as less data as needed from disk.

In order to help with this approach, it is best to have a tiled
geotiff. You can use geotools itself to tile geotiffs, or you can use
the gdal_translate command line utility as follows:

gdal_translate -co "TILED=YES" -co "BLOCKXSIZE=512" -co
BLOCKYSIZE=512" infile outfile


Simone.


>
> public static GridCoverage2D cropGridCoverage(GridCoverage2D coverage,
> ReferencedEnvelope crop){
>         final AbstractProcessor processor = new DefaultProcessor(null);
>         final ParameterValueGroup param =
> processor.getOperation("CoverageCrop").getParameters();
>         param.parameter("Source").setValue( coverage );
>         param.parameter("Envelope").setValue( crop );
>         GridCoverage2D cropped = (GridCoverage2D)
> processor.doOperation(param);
>         return cropped;
>     }
>
> without the cloning, and directly using a referenced envelope.
>
> Cheers
> Martin
>
> On 5/5/2010 9:28 AM, Michael Bedward wrote:
>> Hi Andrea,
>>
>>
>>> If it is like you say I feel that is really a big missing piece that
>>> we should fill in, even if for now with a "dirty" cropping of the
>>> coverage.
>>>
>>>
>> I'd like to wait for Simone or Daniele to comment too but I certainly
>> agree with you. The present arrangement of providing a GridGeometry2D
>> object to the reader to set only the grid resolution seems pretty
>> obscure... secret knowledge in fact :-)
>>
>> If Simone is agreeable I think it would be really useful to flesh out
>> the parameters for the read method to cater for obvious requests
>> including Martin's case, plus document them.
>>
>> Michael
>>
>>
>>
>
>
> --
> Martin Tomko
> Postdoctoral Research Assistant
>
> Geographic Information Systems Division
> Department of Geography
> University of Zurich - Irchel
> Winterthurerstr. 190
> CH-8057 Zurich, Switzerland
>
> email:  [email protected]
> site:   http://www.geo.uzh.ch/~mtomko
> mob:    +41-788 629 558
> tel:    +41-44-6355256
> fax:    +41-44-6356848
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to