Hi Martin,

Thanks for the reply to my last mail, that was exactly what i needed!!

but i have got another problem and that is with reprojecting images of UK
and USA. I ran this code (see below) on series of test images from
different areas, i found out that every image tested were projected
normally EXCEPT the ones for USA and UK, which reprojects at about 90
degree away from how they are suppose to reproject.

Unfortunately, i can not upload sample images i was trying to reproject
for you to try out, but, follow this link for the before and after
reprojection pictures of two of the images i was trying to reproject!!

http://docs.google.com/View?docid=dddh5sh9_05fjw4cgv




So, I am wondering what i am doing wrong or is this a bug with geotools??

package org.info.arch;

import java.io.File;
import java.io.IOException;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.processing.Operations;
import org.geotools.data.DataSourceException;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.gce.geotiff.GeoTiffWriter;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

public class ToMartin {

        /**
         * @param args
         * @throws IOException
         * @throws DataSourceException
         * @throws FactoryException
         * @throws NoSuchAuthorityCodeException
         */
        public static void main(String[] args) throws DataSourceException,
IOException, NoSuchAuthorityCodeException, FactoryException {
                // TODO Auto-generated method stub
                File path0 = new File("C:\\obv\\califonia_102003.tif");
                File destFile = new File("C:\\obv\\california_wgs.tif");


                GridCoverage2D src0 = (GridCoverage2D) (new
GeoTiffReader(path0)).read(null);

                CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");


                GridCoverage2D coverageTransf = (GridCoverage2D)
Operations.DEFAULT.resample(src0, targetCRS);


                GeoTiffWriter writer = new GeoTiffWriter(destFile);
                writer.write(coverageTransf, null);


        }

}




Thanks from prompt answer,


Michael


> 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