I am new to R. I am trying to transform elevation data in R for input into MaxEnt. Returned:

Error in .startAsciiwriting (x,filename ...): x has unequal horizontal and vertical resolutions. Such data cannot be stored arc-ascii format.

Further information as requested: The following script was run (from https://www.azavea.com/blog/2018/10/09/preparing-data-for-maxent-species-distribution-modeling-using-r/):

assign(paste0("elev_", "raw"), raster(“elevation.tif”))
assign(paste0("elev_", "projected"), projectRaster(elev_raw, crs=projection))
assign(paste0("elev_final"), elev_projected)
elev_extended <- extend(elev_final, ext, value=NA)
elev_final_re <- resample(elev_final, elev_final)
elev_tend <- extend(elev_final_re, ext, value=NA)
writeRaster(elev_tend, filename=”elev_output.asc”, format=’ascii’, overwrite=TRUE)

Error in .startAsciiwriting (x,filename ...): x has unequal horizontal and vertical resolutions. Such data cannot be stored arc-ascii format.

What does this mean and what can I do about this?


1 Answer 1


I imagine that your code is going sideways in the projectRaster function. You do not have the res argument defined so, it is likely that the cell resolution is not the same in the x,y dimensions. Since an ASCII Grid is a numeric array with a descriptive header, a symmetrical cell size is an absolute requirement. To address this just define the res argument with a single number representing the expected cell resolution (in the appropriate projection units).

Please ignore the way that the linked blog is creating objects, unless actually needed, using assign is very bad practice. There is absolutely no need to be pasting and assigning object names in this way. You can use "<-" or "=" to create and assign and object in R eg., elev_raw <- raster(“elevation.tif”) I also cannot see any need whatsoever to use raster::resample with the same object.

Your code can be reduced thus:

elev <- extend(projectRaster(raster("elevation.tif"), 
               res=30, crs=projection), ext, value=NA)
writeRaster(elev, filename="elev_output.asc", overwrite=TRUE)

I would recommend setting the "ext" object using the maximum extent of your study area following something like and if possible, using a projected geographic reference system, with distance based projection units (eg., feet, meters), and not a geographic projection, which has its projection units in decimal degrees.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.