Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.
Hello John, Ethan, Yuan, Anyone! I'm having problems converting from NetCDF to GeoTIFF using the 'GeotiffWriter' class. I've attached some example code that will convert each 'GridDatatype' in a NetCDF file to a GeoTIFF. However, the resulting 32-bit GeoTIFFs will not display in ArcGIS (no data is found) or by GDAL/FWTools (listgeo.exe and gdalinfo.exe both crash). Note that the files I'm testing with don't have time or level dimensions. I've tested with 2.2.20, 2.2.22 and 4.0 and get the same results. I'm positive that this used to work. It actually does work in the Java NEXRAD Tools, which uses an older version of NCJ 2.2. I've tested the grayscale option, which works with ArcGIS, but still bombs with GDAL (listgeo.exe). Thanks, Steve import java.util.List; import ucar.nc2.dt.GridDataset; import ucar.nc2.dt.GridDatatype; import ucar.nc2.geotiff.GeotiffWriter; public class Nc2GTiff { /** * @param args */ public static void main(String[] args) { try { if (args.length != 1 || ! args[0].endsWith(".nc")) { System.err.println("Input argument must be a NetCDF (.nc) file!"); return; } String infile = args[0]; GridDataset dataset = ucar.nc2.dt.grid.GridDataset.open(infile); List<GridDatatype> grids = dataset.getGrids(); for (GridDatatype grid : grids) { String gridName = grid.getName(); String outfile = infile.substring(0, infile.length()-3)+"_"+gridName+"-4.0.tif"; GeotiffWriter gtWriter = new GeotiffWriter(outfile); gtWriter.writeGrid(dataset, grid, grid.readDataSlice(-1, -1, -1, -1), false); } dataset.close(); } catch (Exception e) { e.printStackTrace(); } } }
netcdf-java
archives: