Spatial reference error with arc.write

311
2
01-10-2019 04:33 PM
CassKalinski
New Contributor III

I am getting the following error from arc.write:

Error in .call_proxy("raster.create", .self, source, as.pairlist(args)) :
No spatial reference exists.

Full call in R:

arc.write(file.path(pathGDB, rasterNameDefault),
rasterDefault,
overwrite = TRUE)

"rasterNameDefault" is a character string. "pathGDB" is the full path to the local GDB. (It is a long path.) "rasterDefault" is a raster layer created with the raster package (via dismo::predict).

I verified the raster has a projection assigned.

> rasterDefault
class : RasterLayer
dimensions : 240, 130, 31200 (nrow, ncol, ncell)
resolution : 845.2344, 845.2344 (x, y)
extent : 353440.7, 463321.2, 4010519, 4213375 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0
data source : in memory
names : layer
values : 9.893558e-11, 0.004525617 (min, max)

To be sure, I went back and added this code prior to the arc.write call and reran it. Still get the error on arc.write.

crsProjection <- CRS("+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs")

crs(rasterDefault) <- crsProjection

What is doubly strange is that this is the same exact code pattern that I used in another part of the project about a month ago. It worked fine then and I was able to get rasters into ArcGIS Pro with no issues. Fast forward to today and the function does not work with a different set of rasters. I do not recall any updates to R or Pro during that time.

Versions:

ArcGIS Pro 2.2.4

R-Bridge 1.0.1.232

Microsoft R 3.51

dismo 1.1-4

raster 1.8-4

sp 1.3-1

This code does work and I can add the resulting rasters to ArcPro, but is not as clean as the arc.write in my workflow.

writeRaster(rasterDefault, file.path(pathMaxEntOutputs, "rasterDefault.bil"),
format="EHdr",
overwrite=TRUE,
progress="text",
prj=TRUE)

Thoughts on where I am off here on arc.write?  

0 Kudos
2 Replies
OrhunAydin
Esri Contributor

Hello Cass,

Can you please try using arc.write with explicit references to raster properties?

If you have a raster you read in that has the same SR and extents and so forth. I will call that raster object template in the code snippet below

##################################### CODE SNIPPET #########################################

## Create a Blank Raster Conforming to a Pre-existing Raster

output_raster <- arc.raster(NULL, path = 'C:/output_path/Default.gdb/raster_name',
nrow = template$nrow,

ncol = template$ncol,

pixel_type = template$pixel_type,

nband = 1,  ##or how many bands you would like to write
sr = template$sr$WKID,

extent = template$extent)

## Add the Data to the Empty Raster
output_raster$write_pixel_block(raster_data, nrow = template$nrow, ncol = template$ncol)

## Remove the R object for mid-step raster
rm(output_raster)

#################################### END CODE SNIPPET ######################################

Please let me know if that works or not. Also if you have a repro for me to work on, I would be happy to look at what is going wrong when writing the raster in your analysis as well.

Hope this helps,

Orhun

0 Kudos
CassKalinski
New Contributor III

Thank you for the reply Orhun. It may be late next week before I can test this. (Need to get a draft of my thesis to Dr Kemp!  ) Used the work around I noted for now but do want to sort out the bridge problem.