Hello Mickael

Michael Owonibi a écrit :
> I am wondering how do I derive/define a gridcoverage2d from an array of
> image cell values, arranged in a way such as this –{ pixel 1 band1,
> pixel 1 band 2, pixel 1 band 3 …..pixel 1 band m, pixel 2 band 1,  pixel
> 2 band 2, pixel 2 band 3 …pixel 2 band m …….pixel n band m} (...snip...)

GridCoverage2D are wrappers around RenderedImage, adding metadata like bounding
box, etc. So the question is how to create a RenderedImage for data arranged in
the way you describe. So the first steps described below is about creating a
J2SE image from your data. Only the last steps are GeoTools-specific.


---- BEGIN STANDARD JAVA API -----------------------------------------------

1) Create a DataBuffer wrapping your data. Note that you don't need
   to copy your data; they will be directly wrapped. You will need to
   select one of the DataBuffer subclass matching your data type, for
   example DataBufferFloat if they are float values.

http://java.sun.com/javase/6/docs/api/java/awt/image/DataBuffer.html


2) Create a SampleModel that describe the way your data are arranged.
   In the above case, its look like that the following subclass would
   fit:

http://java.sun.com/javase/6/docs/api/java/awt/image/PixelInterleavedSampleModel.html


3) Create a WritableRaster with the above SampleModel and DataBuffer
   (no subclass to look at in this case):

http://java.sun.com/javase/6/docs/api/java/awt/image/WritableRaster.html

You could stop at this point since (if my memory serve me right) there is a
GridCoverageFactory method which accept directly a Raster. However if you want
more control it may be worth to continue.

Note: the following step could also be skipped if you create a JAI image (which
accepts null ColorModel), but for now I'm assuming you will create a J2SE image,
which require non-null ColorModel.

4) Create a ColorSpace which describe how you want to translate the values
   to colors. Note that this is not styling; we are just defining the initial
   representation of your data. Note that if you have 1, 3 or 4 bands, one of
   the pre-defined ColorSpace could fit. But I assume that you have an
   arbitrary number of bands in which case you may need to define your own
   ColorSpace:

http://java.sun.com/javase/6/docs/api/java/awt/color/ColorSpace.html


5) Define a ColorModel compatible with the SampleModel you defined at step 2.
   Its look like that ComponentColorModel would fit. It requires a ColorSpace,
   which is why I wrote this step 4 just before.

http://java.sun.com/javase/6/docs/api/java/awt/image/ComponentColorModel.html


6) Create a BufferedImage, giving to the constructor the ColorModel and the
   WritableRaster you created in the above steps.

http://java.sun.com/javase/6/docs/api/java/awt/image/BufferedImage.html

You can display you BufferedImage using a Swing widget for example in order to
test it.

---- END OF STANDARD JAVA API -----------------------------------------------


Once you have your BufferedImage defined at step 6 or you raster defined at step
3, you have to:

a) Create a SampleDimension for each band. Note that SampleDimensions just
   describes the band (they are metadata) - they do not contain the data;
   the later are stored in the DataBuffer you created at step 1 and can
   have whatever layout you managed to describe through a SampleModel.

b) Use one of the GridCoverageFactory method for creating a GridCoverage2D
   using the RenderedImage or Raster, together with you bounding box, CRS
   and the array of SampleDimensions.

        Martin

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to