Matt Foster wrote:
Yuan,
I'm not sure I understand what is missing from the netCDF file.
Looking at the headers, it contains the projection type (Lambert
Conformal), the origin lat/lon and std. parallel. What is
GeotiffWriter looking for that this netCDF file is lacking?
Also, where is there documentation on GeotiffWriter?
Matt
Matt,
The missing part is the coordinate, when I run a ncdump I got
the following:
netcdf MaxT_test {
dimensions:
DIM_1 = 1 ;
DIM_81 = 81 ;
DIM_140 = 140 ;
variables:
float MaxT_SFC(DIM_1, DIM_81, DIM_81) ;
MaxT_SFC:validTimes = 1126634400, 1126638000 ;
MaxT_SFC:descriptiveName = "Maximum Temperature" ;
MaxT_SFC:gridSize = 81, 81 ;
MaxT_SFC:domainOrigin = 47.1875, 22.875 ;
MaxT_SFC:domainExtent = 5., 5. ;
................................
There is no data section for the dimensions, and I don't think there is
any software can understand this coordinate. NetCDF software will
automatically translate this coordinate
to x = 0, 1, 2, 3, ...., 80 and y = 0, 1, 2, 3, ...., 80. A good
netCDF file should have a data section for both dimensions, and better
not using the same dimension name if you want
your data to project to a geospacial coordinate.
Yuan
Yuan Ho wrote:
Matt Foster wrote:
Update...
Upon further review of the error I'm getting...GeotiffWriter is
failing with the NullPointerException on "grid.getCoordinateSystem"
(the error is pointing to line 99 in GeotiffWriter.java). That
seems to me to be saying that it doesn't like something in my netCDF
file. I'm attaching the netCDF file on which I've been testing.
Matt
Matt,
Yes, there is something in the test file that can not be
processed. I think it is the coordinate system of this file,
GeotiffWriter was looking for the lat/lon coordinate
and failed for what this file had.
Yuan
Matt Foster wrote:
Yuan,
The sample you supplied is very close to what I started with, which
came from a post you made in September of 2004. The problem is
that call to GeotiffWriter seems to be short an argument. I looked
at the source code for GeotiffWriter, and it seems to me (again,
I'm a Java newbie) that this form of call to GeotiffWriter needs
one more argument after the boolean, and that argument gets passed
to "LatLonRect", and that is where I am currently stuck.
I tried passing 'null' as the argument, thinking that would cause
LatLonRect to return a rectangle covering the entire earth, but I
got a NullPointerException. I'm attaching the latest incarnation
of my code.
BTW, where is there documentation for GeotiffWriter? I don't see
any on the netcdf-java documentation site.
Matt
Yuan Ho wrote:
John Caron wrote:
-------- Original Message --------
Subject: Problem using GeotiffWriter
Date: Wed, 14 Sep 2005 09:23:19 -0500
From: Matt Foster <Matthew.Foster@xxxxxxxx>
Organization: UCAR/Unidata
To: netcdf-java@xxxxxxxxxxxxxxxx
I'm a serious Java newbie, so be gentle if I've done something
stupid here...
I wrote the attached short program, which is based off of a post
to this list last year, to read a single element from a netCDF
file, and write a GeoTIFF file, however, I get the following
error message when I try to compile it with javac...
GeoTifWriter.java:16: cannot resolve symbol
symbol : method writeGrid
(java.lang.String,java.lang.String,int,int,boolean)
location: class ucar.nc2.geotiff.GeotiffWriter
writer.writeGrid("/home/mwfoster/MaxT_test.cdf", "MaxT_SFC",
0, 0, false);
^
The "caret" symbol is actually under the dot between writer and
writeGrid, in case a variable-width font messed that up.
Can someone help me out here?
Matthew,
Here is a small example of using GeotiffWriter class:
import ucar.ma2.*;
import ucar.nc2.*;
import ucar.nc2.dataset.*;
import ucar.nc2.geotiff;
import ucar.nc2.dataset.grid.*;
import ucar.unidata.geoloc.*;
import ucar.unidata.geoloc.projection.*;
import java.io.*;
import java.util.*;
public static void main(String args[]) throws IOException {
String fileOut = "totalr1.tif";
GeotiffWriter writer = new GeotiffWriter(fileOut);
writer.writeGrid("2003091116_ruc2.nc", "P_sfc", 0, 0, false);
writer.close();
}
If this does not work for you, email me your java code.
Yuan
Matt
------------------------------------------------------------------------
import ucar.ma2.*;
import ucar.nc2.*;
import ucar.nc2.dataset.*;
import ucar.nc2.geotiff.*;
import ucar.nc2.dataset.grid.*;
import ucar.unidata.geoloc.*;
import ucar.unidata.geoloc.projection.*;
import java.io.*;
import java.util.*;
class NetcdfToGeotif {
public static void main(String args[]) throws IOException {
String fileOut = "/home/mwfoster/netCDF/maxT_test.tiff";
GeotiffWriter writer = new GeotiffWriter(fileOut);
writer.writeGrid("/home/mwfoster/MaxT_test.cdf", "MaxT_SFC",
0, 0, false, null);
writer.close();
}
}