I have a large csv containing ~5 million rows containing Lat, Lon, and Depth bathymetry values. I want to generate a raster GRID (for use in Arc) from this, but the trouble is the lat/lons are irregularly spaced. I've figured out the basics for reading in the data, creating a spatial object, and writing a raster assuming the points are regular:
pts = read.csv("data.csv", header=T)
coordinates(pts) = ~Lon+Lat
proj4string(pts) = CRS("+init=epsg:4326")
gridded(pts) = TRUE #### FAILS
ras = raster(pts)
writeRaster(ras, "output.grd", "raster)
Currently it crashes on the gridded line with error:
suggested tolerance minimum: 0.0025975
Error in points2grid(points, tolerance, round) :
dimension 1 : coordinate intervals are not constant
Is there some way to fit a regular grid over these points, and then sample averages from the points within each cell?
I'm still learning R.
I'm open to python scripting with tools from ArcToolbox as well. Although I was under the impression that R would be faster. I have access to 3D Analyst, Geostatistical Analyst, Network Analyst, Spatial Analyst, and Tracking Analyst.
pts.grid = data.frame(Lat=seq(ymin, ymax, ylen/10000), Long=seq(xmin, xmax, xlen/10000)) pts.idw = idw(Depth~Long+Lat, ~Long+Lat, pts, pts.grid) names(pts.idw) = c("Long", "Lat", "Depth", "DepthVar") coordinates(pts.idw) = ~Long+Lat gridded(pts.idw) = TRUE ras = raster(pts.idw) projection(ras) = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") writeRaster(ras, "OMGBathy_Melville.grd")
But the result gives me a Raster Data Objects Error when added to ArcMap. Something must be wrong in the .GRD/.GRI file produced this way.