Re: [netcdf-java] Get data through lat lon coordinates

Hello Pablo

Le 27/01/12 10:14, Pablo Rozas Larraondo a écrit :
I've succeeded in opening and reading Grib1 files, but I'm having problems trying to find out how to access data through lat lon coordinates. In the ECMWF API there is a function called grib_find_nearest(gid, lat,lon) in which you give a geocoordinate point and the function returns the value of the closest, or the four closest grid points.

Using the NetCDF API I can access the _CoordinateAxisType Attributes of the grib file which are GeoX and GeoY expressed in Km, but I wonder if there is a function for accessing values or translating points into geographic coordinates.

I'm not sure if the NetCDF API provides API for this task. But one possible approach may be to use a library which sit on top of the UCAR NetCDF library. If I use as an example the library which I known (but you can find other projects doing similar jobs), you could use the coverage module ( like below:

The read the image, the static convenience methods should provide an easy start (there is also other ways if you need more control, for example specifying a subsampling or the geographic area you want to read).

    GridCoverage coverage ="");

It will use the UCAR library under the hood for reading the data. To get the nearest value of a geodetic coordinate, you can do as below:

    float[] samples = null;
    GeneralDirectPosition pos = new GeneralDirectPosition(numberOfDimensions);
    // If you have to do a loop, do it here.
    samples = coverage.evaluate(pos, samples);

Thats it (if everything goes well - I'm actively working on improving the NetCDF support right now). If the position is not in the same coordinate reference system than the coverage, the library will do the reprojection for you. It is also possible to instruct the evaluate method do perform bilinear or bicubic interpolation automatically. There is also some other interesting stuff you can get automatically, like exporting the metadata found in your NetCDF file in an ISO 19139 compliant document.

Please let me known if you wish to know more. I could then give a more concrete starting point depending on your environment (e.g. if you use Maven or not).


  • 2012 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: