Skip to content

Help with conversion from NetCDF to ASCII

3 messages · Narayani Barve, Michael Sumner, Robert J. Hijmans

#
Does it have to be that ascii format? There are much better options
for regular grids, such as GeoTIFF - but it depends on your target of
course. Note that some software supports different dx/dy sizes, namely
GDAL and Golden Surfer for this format:

http://www.gdal.org/frmt_various.html#AAIGrid

If it does need to be ESRI ASCII, you could write it out with square
cells and then reset the cell sizes in the target (if possible).

Is the requirement for square cells with the ESRI version of this
format, or with the software you want to use next?

As a last resort you could resample the grid using R's indexing/seq
functions, or with spsample in package sp, or warp it with an external
tool like gdalwarp.

Cheers, Mike.
On Tue, Feb 2, 2010 at 9:32 AM, Narayani Barve <narayani.ku at gmail.com> wrote:
#
If you really require square cells, then the resample function in
'raster' might be useful:

library(raster)
r = raster('ncdffile')
# or r=raster(matrix); extent(r) = c( , , , )
s = raster(r)
res(s) = min(res(s))
s = resample(r, s,  method='bilinear')
s = writeRaster(s, filename='abc.asc', format='ascii')

Or first do an interpolation first. Many options for that. E.g. see
?raster::interpolate

Robert
On Mon, Feb 1, 2010 at 2:49 PM, Michael Sumner <mdsumner at gmail.com> wrote: