0

I have some NetCDF files that aren't displaying correcly in ArcMap 10.7 (or when plotted in R...). I found some help fixing the extent here. Here is what I see for the extent:

library(ncdf4)
library(raster)
library(rgdal)
library(gdalUtils)

filename <- "./netcdf_test/comp20180702.120000.nc"

tpw_raster <- brick(filename, varname="tpwGrid")

Result:

> tpw_raster <- brick(filename, varname="tpwGrid")
[1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named lon BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
[1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named lat BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
tpw_raster; class(tpw_raster)

Result:

> tpw_raster; class(tpw_raster)
class      : RasterBrick 
dimensions : 721, 1440, 1038240, 1  (nrow, ncol, ncell, nlayers)
resolution : 1, 1.998611  (x, y)
extent     : 0.5, 1440.5, 0.0006944444, 1440.999  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : comp20180702.120000.nc 
names      : layer 
varname    : tpwGrid 

[1] "RasterBrick"
attr(,"package")
[1] "raster"

Here I check the extent info, then fix the extent, and try to write the file:

polnc <- nc_open(filename)

#Get extent info
ncvar_get(polnc, "lonArr")
ncvar_get(polnc, "latArr")

extent(tpw_raster) <- c(-180, 179.75, -90, 90)

#plot(tpw_raster)

writeRaster(tpw_raster, "./netcdf_test/test01.nc", format="CDF", varname="tpw", xname="lon", yname="lat", overwrite=TRUE)
#Creates a .nc file, but it is does not open in ArcGIS: "ERROR 000237 One or more dimensions are invald"

#writeGDAL(tpw_raster, "./netcdf_test/test01.adf",drivername = "AIG", type = "Float32")
#Error in (function (classes, fdef, mtable)  : 
#  unable to find an inherited method for function ‘gridded’ for signature ‘"RasterBrick"’

When I use writeRaster a file is produced but I get the stated error when I try to open it in ArcGIS. I first tried writeGDAL because ultimately I want it to be in GRID format but I get an error for that also. Here's what I see when I look at in in R (it seems to plot fine):

filename2 <- "./netcdf_test/test01.nc"

tpw_out <- brick(filename2, varname="tpw")
tpw_out; class(tpw_out)

Result:

> tpw_raster; class(tpw_raster)
class      : RasterBrick 
dimensions : 721, 1440, 1038240, 1  (nrow, ncol, ncell, nlayers)
resolution : 0.2498264, 0.2496533  (x, y)
extent     : -180, 179.75, -90, 90  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : comp20180702.120000.nc 
names      : layer 
varname    : tpwGrid 

[1] "RasterBrick"
attr(,"package")
[1] "raster"
> filename2 <- "./netcdf_test/test01.nc"
> tpw_out <- brick(filename2, varname="tpw")
> tpw_out; class(tpw_out)
class      : RasterBrick 
dimensions : 721, 1440, 1038240, 1  (nrow, ncol, ncell, nlayers)
resolution : 0.2498264, 0.2496533  (x, y)
extent     : -180, 179.75, -90, 90  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : test01.nc 
names      :       X1 
min values :   0.0625 
max values : 106.9375 
z (unknown): 1 
varname    : tpw 

[1] "RasterBrick"
attr(,"package")
[1] "raster"

Could ArcMap not liking it have something to do with the "z (unknown)?"

I don't have or need a time dimension or any other z dimension.

3
  • Historically, ESRI software does not care for rasters with different x,y cell dimensions. Perhaps, try setting the cell resolution to the same value eg., res(x) <- c(0.2498264, 0.2498264) Commented Jun 23, 2021 at 0:33
  • Thanks for the suggestion. I tried res(tpw_raster) <- c(0.2498264, 0.2498264) before extent(tpw_raster) <- c(-180, 179.75, -90, 90) and I get Warning message: In .local(x, filename, ...) : all cell values are NA. When I switch the order I get Warning message: In .couldBeLonLat(x, warnings = warnings) : raster has a longitude/latitude CRS, but coordinates do not match that. Either way I still get the same error in ArcGIS.
    – Chris
    Commented Jun 23, 2021 at 3:36
  • Any help on this? I think the issue I'm having here has to do with the z (unknown): 1 statement. When I try to add it in ArcGIS 'z' shows up as an option for for x dimension and y dimension. I have tried looking for ArcGIS and/or Python solutions to this and I've come up blank on both. I don't really care what solution to use, but I ultimately need to get these NetCDFs into GRID files with the right extent.
    – Chris
    Commented Jun 24, 2021 at 20:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.