How to convert netcdf file into ASCII format?

Apr 23, 2011 at 11:50 AM

Hi,

Does anyone have a C# code snippet to convert netcdf file into ASCII?

Thanks.

Developer
Apr 25, 2011 at 8:56 AM
Edited Apr 25, 2011 at 9:55 AM

Hi,

you can use sds command line utility, installed as a part of the installation package, to copy NetCDF file into text CSV file:

 

sds copy original.nc result.csv

 

If you don't need metadata appended to the end of the output file, use the following syntax:

 

sds copy original.nc "result.csv?appendMetadata=false"

 

 

 

Regards,  

Dmitry

Apr 25, 2011 at 2:48 PM

Hi,

Thanks for your reply.  I was able to convert netcdf into csv format based on sds command line utility. 

But I can't process the resulting .csv file using ESRI's ArcGIS software.  My ultimate task is to convert netcdf files into rasters with NAD_1983_Albers projection.  I have ESRI tools to convert .asc to rasters; but not .csv into rasters.  The netcdf files I'm using are downloaded from http://water.weather.gov/precip/p_download_new/

 

Apr 27, 2011 at 12:06 PM

I am very intrested in your approach ... please post back here if anything usefull comes out of it!

May 4, 2011 at 1:06 PM

Hi,

I haven't had luck converting csv file to ESRI ASCII file.  However, I found a tool from NOAA for converting NetCdf to ESRI ASCII (http://www.ncdc.noaa.gov/oa/wct/index.php).  I'm using sds to pull out the metadata and use NOAA's Weather and Climate tool to export netcdf into ascii.

Wish there's a "one-stop" shop to do all this.

May 12, 2011 at 12:04 PM

I think it is better to find a way to do this using sds, maybe we should just understand

[a] how to convert these lat, lon coordinates to a rectangular grid (by finding the min/max lat lon coordinates)

[b] creating a grid using a custom cell size or [ncols] [nrows} values then

[c] finding values on each cell and fill the grid

finaly export the grid as an space-seperated value with a header like this on the top of the file:

 

NCOLS xxx

NROWS xxx

XLLCENTER xxx | XLLCORNER xxx

YLLCENTER xxx | YLLCORNER xxx

CELLSIZE xxx

NODATA_VALUE xxx

row 1row 2

...

row n


if i could solve the problem [a] then all other steps should be easy to implement
May 13, 2011 at 8:49 AM

Maybe not quite what you are trying to do, but I have written some code using SDS and DotSpatial to determine which NetCDF cell (which is in Lat lon system @ 0.25 deg) is located above each cell in my raster layer (which is in BNG on a 5km grid). The calculation is based on finding the lat-lon of the centroid of each raster cell (using the reprojection functions within DotSpatial) and then finding the closest NetCDF cell to the centroid.  I can send this code if you are interested?

May 17, 2011 at 12:26 PM
chriscounsell wrote:

Maybe not quite what you are trying to do, but I have written some code using SDS and DotSpatial to determine which NetCDF cell (which is in Lat lon system @ 0.25 deg) is located above each cell in my raster layer (which is in BNG on a 5km grid). The calculation is based on finding the lat-lon of the centroid of each raster cell (using the reprojection functions within DotSpatial) and then finding the closest NetCDF cell to the centroid.  I can send this code if you are interested?


Hi,

Yes, not quite, but still extremely helpful.  One of our problems is determining the boundary of a hydrologic area.  I would like to include an additional pixel to the boundary so that it doesn't come out as jagged edge (thereby losing some accuracy when I perform a calculation).  I'd be interested in your code.