-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I found an example at this url. It is working perfectly :)

https://dev.cocos.bz/plugins/scmsvn/viewcvs.php/jgrass3.0/community/moovida/gsoc2009_netcdf/eu.hydrologis.jgrass.netcdf/src/eu/hydrologis/jgrass/netcdf/geotoolkit/NetcdfExample.java?rev=2572&root=jgrass&view=markup

Thanks

Steve Ansari wrote:
> Hello Fabien,
> 
> Thanks for the example.  No - I never got into using the
> gt-coverageio-netcdf stuff and can't really help with that.  If you get
> it working, please post it back to the list!
> 
> Thanks,
> Steve
> 
> 
> Fabien Carrion wrote:
>> I have make a small patch for the branch 2.6.x, so it support netcdf
>> 4.1 I hope you can use it.
>>
>> Thanks for this example, but in your example you are using a lot the
>> netcdf objects. I was thinking to something only based on geotools.
>>
>> import java.awt.image.BufferedImage;
>> import java.io.File;
>> import javax.imageio.ImageReader;
>> import javax.imageio.ImageReadParam;
>> import org.geotools.image.io.netcdf.NetcdfImageReader;
>> import org.geotools.image.io.netcdf.NetcdfImageReader.Spi;
>>
>> public class Test {
>>     public static void main(String[] args) throws Exception {
>>         NetcdfImageReader netcdfreader = (NetcdfImageReader) (new
>> Spi()).createReaderInstance(new Object());
>>         netcdfreader.setInput("Path_to_netcdf_file", false, false);
>>         ImageReadParam param = netcdfreader.getDefaultReadParam();
>>         BufferedImage out = netcdfreader.read(0, param);
>>         File file = new File("Path_to_new_image_file");
>>         javax.imageio.ImageIO.write(out, "png", file);
>>     }
>> }
>>
>> The problem is that I always get an empty image. I think my problem is
>> on the boundary which I should set in the ImageReadParam object.
>>
>> Do you have any piece of advice to give me?
>>
>> Thanks
>>
>> On Tue, Mar 2, 2010 at 2:50 PM, Steve Ansari <[email protected]> wrote:
>>   
>>> Hello Fabien,
>>>
>>> I pasted below a rough example that I put together several years ago.
>>> It is outdated, surely won't compile, uses Geotools 2.3.5 and NetCDF
>>> 2.2.22, but might help you get on the right track.  The general
>>> principles are still the same.
>>>
>>> Another good resource might be the ncWMS project, which uses GeoTools.
>>> http://www.resc.rdg.ac.uk/trac/ncWMS/
>>>
>>> I hope this helps.
>>>
>>> Steve
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> package steve.test;
>>>
>>> import java.io.*;
>>> import java.util.*;
>>> import java.net.*;
>>> import java.awt.image.*;
>>>
>>> import javax.media.jai.RasterFactory;
>>>
>>> import javax.media.jai.*;
>>> import org.geotools.coverage.processing.*;
>>>
>>> import ucar.ma2.*;
>>> import ucar.nc2.NetcdfFile;
>>> import ucar.nc2.dataset.NetcdfDataset;
>>> import ucar.nc2.dt.TypedDatasetFactory;
>>> import ucar.nc2.dt.grid.GeoGrid;
>>> import ucar.nc2.dt.grid.GridDataset;
>>> import ucar.nc2.util.DiskCache;
>>> import ucar.unidata.geoloc.*;
>>>
>>> import org.geotools.coverage.grid.GridCoverage2D;
>>> import org.geotools.coverage.grid.GridCoverageFactory;
>>> import org.geotools.geometry.*;
>>> import org.geotools.referencing.CRS;
>>> import org.geotools.referencing.crs.DefaultGeographicCRS;
>>> import org.opengis.referencing.FactoryException;
>>>
>>>
>>> public class ReprojectST4 {
>>>
>>>    private URL ncURL;
>>>
>>>    private GridDataset gridDataset;
>>>
>>>    private GridCoverageFactory gcFactory = new GridCoverageFactory();
>>>
>>>    private WritableRaster raster = null;
>>>
>>>    public ReprojectST4(URL ncURL) throws IOException {
>>>
>>>        System.out.println("SETTING DISK CACHE TO:
>>> "+System.getProperty("java.io.tmpdir"));
>>>        DiskCache.setRootDirectory(System.getProperty("java.io.tmpdir"));
>>>
>>>        this.ncURL = ncURL;
>>>        NetcdfFile ncfile = NetcdfFile.open(ncURL.toString());
>>>        NetcdfDataset ds = new NetcdfDataset(ncfile);
>>> //      NetcdfDataset ds = NetcdfDataset.openDataset(ncURL.toString());
>>>        StringBuffer errlog = new StringBuffer();
>>>        this.gridDataset = (GridDataset)TypedDatasetFactory.open(
>>> thredds.catalog.DataType.GRID, ds, null, errlog);
>>>        if (null == gridDataset) {
>>>            throw new IOException("Cant open GRID at location=
>>> "+ncURL.toString()+"; error message= "+errlog);
>>>        }
>>>    }
>>>
>>>    public GridDataset getGridDataset() {
>>>        return gridDataset;
>>>    }
>>>
>>>    private void listGrids() {
>>>        List grids = gridDataset.getGrids();
>>>        for (int i = 0; i < grids.size(); i++) {
>>>            GeoGrid grid = (GeoGrid) grids.get(i);
>>>            System.out.println(grid.toString());
>>>        }
>>>
>>>    }
>>>
>>>    public GridCoverage2D getGridCoverage(String geoGridName)
>>>    throws IOException, FactoryException {
>>>        return getGridCoverage(gridDataset.findGridByName(geoGridName));
>>>    }
>>>
>>>    public GridCoverage2D getGridCoverage(GeoGrid geoGrid) throws
>>> IOException, FactoryException {
>>>
>>>        int height = geoGrid.getYDimension().getLength();
>>>        int width = geoGrid.getXDimension().getLength();
>>>        int heightIndex = geoGrid.getYDimensionIndex()-1;
>>>        int widthIndex = geoGrid.getXDimensionIndex()-1;
>>>        raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT,
>>> width,
>>>                height, 1, null);
>>>
>>>        System.out.println("H-INDEX = " + heightIndex + " height=" +
>>> height);
>>>        System.out.println("W-INDEX = " + widthIndex + " width=" + width);
>>>
>>>        Array dataArray = geoGrid.readYXData(0, 0);
>>>        Index dataIndex = dataArray.getIndex();
>>>
>>>        int[] shape = dataArray.getShape();
>>>        System.out.println("shape.length=" + shape.length + " shape[0]="
>>>                + shape[0] + " shape[1]=" + shape[1]);
>>>
>>>        int count = 0;
>>>        int x = 0;
>>>        int y = 0;
>>>
>>>        try {
>>>
>>>            for (y = 0; y < height; y++) {
>>>                for (x = 0; x < width; x++) {
>>>
>>>                    count++;
>>>
>>>                    float val;
>>>                    if (heightIndex == 0) {
>>>                        val = dataArray.getFloat(dataIndex.set(y, x));
>>>                    } else {
>>>                        val = dataArray.getFloat(dataIndex.set(x, y));
>>>                    }
>>>                    raster.setSample(x, y, 0, val);
>>>
>>>                }
>>>                // System.out.println("count="+count+" y="+y);
>>>
>>>            }
>>>
>>>        } catch (Exception e) {
>>>            System.out.println(e);
>>>            e.printStackTrace();
>>>            System.out.println(x + " , " + y + " , " + count);
>>>            return null;
>>>        }
>>>
>>>
>>>
>>>        LatLonRect rect =
>>> geoGrid.getCoordinateSystem().getLatLonBoundingBox();
>>>        LatLonPoint llCorner = rect.getLowerLeftPoint();
>>>        LatLonPoint urCorner = rect.getUpperRightPoint();
>>>
>>>        System.out.println("llCorner: " + llCorner);
>>>        System.out.println("urCorner: " + urCorner);
>>>
>>>        // GeneralEnvelope env = new GeneralEnvelope(new
>>>        // java.awt.geom.Rectangle2D.Double(-95.0, 35.0, 10.0, 10.0));
>>>        GeneralEnvelope env = new GeneralEnvelope(
>>>                new
>>> java.awt.geom.Rectangle2D.Double(llCorner.getLongitude(),
>>>                        llCorner.getLatitude(),
>>>                        Math.abs(llCorner.getLongitude() -
>>> urCorner.getLongitude()),
>>>                        Math.abs(llCorner.getLatitude() -
>>> urCorner.getLatitude())
>>>                )
>>>        );
>>>        // Start reprojection stuff
>>>        String HRAPSTEREO_WKT =
>>> "PROJCS[\"Stereographic_North_Pole\",GEOGCS[\"Sphere\","+
>>>
>>> "DATUM[\"Sphere\",SPHEROID[\"Sphere\",6371200.0,0],TOWGS84[0,0,0,0,0,0,0]],"+
>>>        "PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],"+
>>>        "PROJECTION[\"Polar_Stereographic\"],"+
>>>
>>> "PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],"+
>>>        "PARAMETER[\"central_meridian\",-105.0],"+
>>>        "PARAMETER[\"latitude_of_origin\",60.0],UNIT[\"metre\",1.0]]";
>>>        env.setCoordinateReferenceSystem(CRS.parseWKT(HRAPSTEREO_WKT));
>>>        //env.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
>>>
>>>        GridCoverage2D gc = gcFactory.create("Original", raster, env);
>>>
>>>        return gc;
>>>    }
>>>
>>> Fabien Carrion wrote:
>>>     
>>>> Hello the list,
>>>>
>>>> I am trying to read a grib file with geotools through netcdf. I found
>>>> out there was some code in the unsupported module gt-coverageio-netcdf.
>>>> I haven't found out any example in the test part of the module. I would
>>>> like to know where can I found an example or any kind of documentation.
>>>>
>>>> Thanks!
>>>>
>>>>       
>>> ------------------------------------------------------------------------------
>>> Download Intel&#174; Parallel Studio Eval
>>> Try the new software tools for yourself. Speed compiling, find bugs
>>> proactively, and fine-tune applications for parallel performance.
>>> See why Intel Parallel Studio got high marks during beta.
>>> http://p.sf.net/sfu/intel-sw-dev
>>> _______________________________________________
>>> Geotools-gt2-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>
>>>
>>>
>>>     
>>
>>
>>
>>   
>> ------------------------------------------------------------------------
>>
>> ------------------------------------------------------------------------------
>> Download Intel&#174; Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> 

- --
Fabien Carrion

()  Campagne du ruban ASCII -- Contre les mails en html
/\  contre les pieces-jointes Microsoft
Web: http://fabien.carrion.free.fr/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuRU+YACgkQTe/bvZWuSM/Y5ACeNlfv8MOyEinFDC5W/7uK+85H
q4gAn3K3khBP06pMx5x8orrGcjwunSYk
=/+Cj
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to