NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi Yuanzheng, ShaoYuanzheng wrote: > Hi list, > I have got the netcdf file, which is generated from OIS(DMSP data) by > ucar.nc2.FileWriter.writeToFile(). Because the OIS data contain visible > and infrared imagery, so the next step I want to extract these two > imagery and put them into different geotiff file. I learned that > GeotiffWriter can perform this work. But I met some problems in the > course of using GeotiffWriter. > > The following code pieces indicate the error information. > //////////////////////////////////////////////////////////////////////////// > step1: using ucar.nc2.FileWriter to convert OIS into netcdf file > //////////////////////////////////////////////////////////////////////////// > String datasetIn = "C:/13532264810612.ois"; > String datasetOut = "C:/13532264810612.nc"; > try { > NetcdfFile ncfileIn = ucar.nc2.Net cdfFile.open(datasetIn, null); > NetcdfFile ncfileOut = ucar.nc2.FileWriter.writeToFile(ncfileIn, > datasetOut, false); > ncfileIn.close(); > ncfileOut.close(); > System.out.println("NetcdfFile written = " + ncfileOut); > } catch (Exception e) { > e.printStackTrace(); > } Unless you have another reason you want a netCDF file, you don't need to read the OIS and write the data as a netCDF file. The netCDF-Java library can read the OIS file the same as it reads a netCDF file. > //////////////////////////////////////////////////////////////////////////////////////// > step2. Write the infrared information from netcdf to geotiff > //////////////////////////////////////////////////////////////////////////////////////// > writer.writeGrid("C:/13532264810612.nc", "infraredImagery", 0, 0, true, > llr); My comment above means that this line could instead be written: writer.writeGrid( "C:/13532264810612.ois", "infraredImagery", 0, 0, true, llr); Though you will still run into the same problem which I discuss below. > ... > ... > public void writeGrid(String fileName, String gridName, int time, int > level, boolean greyScale, LatLonRect pt) throws IOException { > double scaler; > GridDataset dataset = ucar.nc2.dt .grid.GridDataset.open(fileName); > GridDatatype grid = dataset.findGridDatatype(gridName); > GridCoordSystem gcs = grid.getCoordinateSystem(); > ProjectionImpl proj = grid.getProjection(); > if (grid == null) > throw new IllegalArgumentException("No grid named " + gridName + " > in fileName"); > if (!gcs.isRegularSpatial())//syz The problem! > throw new IllegalArgumentException("Must have 1D x and y axes for > " + grid.getName()); > //////////////////////////////////////////////////////////////////////////// > > The above red code will throw the error info "Must have 1D x and y axes > for infraredImagery" > > The method "boolean isRegularSpatial()" in GridCoordSystem return > false.T he GridCorrdSystem need both X and Y axes are 1 dimension, but > actually, the netcdf is 32 dimension in netccdf, because the longitude > and latitude both are decided by the scan line and sample order. GeoTIFF requires 1-D regularly spaced X and Y in some *known* projection. The DMSP data is swath data so it isn't in a known projection. We do some crunching with the satellite location and scan pattern to come up with the 2-D latitude(numScans, numSamplesPerScan) and longitude(numScans, numSamplesPerScan) coordinates. > I also viewed the "13532264810612.nc" in the NetCDF 2.2 Tools. And the > imagery could displayed correctly in the Viewer tab. > So I doubt the Dimension information maybe something omitted, and I > tried to add the LatitudeDimension and LongitudeDimension to the netcdf > file, but it doesn't work. The latitude and longitude don't work for GeoTIFF but they do allow us to view the data as you mention you did in ToolsUI. Ethan > Thanks very much. Any advices is appreciate. > > Yuanzheng Shao > State Key Lab of Information Engineering in Surveying Mapping and Remote > Sensing, > Wuhan University -- Ethan R. Davis Telephone: (303) 497-8155 Software Engineer Fax: (303) 497-8690 UCAR Unidata Program Center E-mail: edavis@xxxxxxxx P.O. Box 3000 Boulder, CO 80307-3000 http://www.unidata.ucar.edu/ ---------------------------------------------------------------------------
netcdf-java
archives: