I am running a project that requires reading .tif files as rasters. However, when I try to load the files in now, I get th error:
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
In addition: Warning message: 'file location/name.tif' not recognized as a supported file format. (GDAL error 4)
I'm using the function raster("file location/name.tif") and it has been working until recently.
I am currently working with the raster package along with sp and rgdal. I've updated each of the packages and still get this error. I've also tried installing and using the terra package but get the same error with that as well.
I'm not sure what to do at this point since I'm pretty sure it isn't an issue with the code I'm running because I haven't changed anything since the last time it worked.
Related
I'm trying to read my shapefile in R and still getting an error message
I installed these libraries
library(sf)
library(ggplot2)
library(tmap)
library(tmaptools)
library(leaflet)
library(dplyr)
mydata<-st_read("C:/Users/User/Documents/PlotLocations_HARV.shp",stringsAsFactors = FALSE)
I got this error message:
Cannot open data source C:\Users\User\Documents\PlotLocations_HARV.shp
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
Open failed.
In addition: Warning message:
In CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
GDAL Error 4: Unable to open C:\Users\User\Documents\PlotLocations_HARV.shx or C:\Users\User\Documents\PlotLocations_HARV.SHX.Try --config SHAPE_RESTORE_SHX true to restore or create it
I have the entire file as well
aoi_boundary_HARV <- st_read("C:\Users\rhusein\Documents\NEONDSSiteLayoutFiles\NEON-DS-Site-Layout-Files\HARV\HarClip_UTMZ18.shp")
and still getting the error message
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, : Open failed. – julia 1 hour ago
Verify that the file PlotLocations_HARV.shx exists in the same folder as PlotLocations_HARV.shp
yes both are in the folder
now I am good thanks
A "shapefile" is made up of several files with different extensions.
.shp -- this file contains the features' geometries.
.shx -- the spatial index
.dbf -- attribute values
The file will not open unless these files are all there. It's a little misleading for ESRI to call it a shapefile but there you have it.
You'll see a couple of others, such as .prj for spatial referencing and .xml for metadata but they are not required.
Your error was
Unable to open C:\Users\User\Documents\PlotLocations_HARV.shx
meaning that you couldn't open the spatial index file for some reason.
So solve the problem, you can make sure the *.shx file is in the same folder as the .shp file, or use the option SHAPE_RESTORE_SHX to regenerate the index.
You said "now I am good" so I assume that you found the file and moved it there, or regenerated the index.
I am getting an error when trying to run the diskImageR package, specifically the IJMacro function, regarding an inability to locate ImageJ. This is what I think the error is stating although I do not know for sure.
I already tried changing the path and by following the pdf associated with running the package, but I still get the same error.
IJMacro("newProject",imageJLoc ="C:\\Users\\user\\Desktop\\ImageJ")
[1] "Searching for application name or filepath: ImageJ"
Error in ij$runScript(paste(script, IJarguments)) :
The imageJ binaries have not been located. Re-initialise the imageJInterface object with the correct location for the imageJ binaries
In addition: Warning message:
In setFilePath(filePath) :
The ImageJ application could not be found in the common install location on your system
I am working with R package raster for sometime now. Recently I updated my system to Windows 10 where I used the a backup R package file to install-back all my packages.
Now while using raster packages especially when I use:
getData('SRTM', lon= Longitiude, lat =Latitude)
I get the follwoing error:
trying URL 'ftp://xftp.jrc.it/pub/srtmV4/tiff/srtm_50_08.zip'
downloaded 263 bytes
Error in .SRTM(..., download = download, path = path) : file not found
In addition: Warning message:
In utils::unzip(zipfilename, exdir = dirname(zipfilename)) :
error 1 in extracting from zip file
I read through a few post that says that the url is no longer accessible, this true and can be checked just by visiting the link.
However getData function should move-on to the next link which is accessable automatically but it is not doing that. Is there a way I can tell it to look for the other links.
I am trying to use a data set of .nc4 files downloaded from NASA.
The format NCDF4 is confirmed by this source.
I used download .file in R to get the database and then a simple nc_open (ncdf4 package) to test the file. Unfortunately the result is an "Unknown file format" error.
Here my replication file and my script:
download.file (url=http://hydro1.gesdisc.eosdis.nasa.gov/.../url, destfile=destination_folder/file.nc4)
All fine till this point, but when testing the files:
library(ncdf4)
setwd('destination_folder')
data <- nc_open('file.nc4')
Error in R_nc4_open: NetCDF: Unknown file format
Error in nc_open("file.nc4") :
Error in nc_open trying to open file file.nc4
Am I missing something?
Thank you.
I do not know what is wrong, but I can add the information that the problem resides in the Windows implementation of the ncdf4 package. With the following statement:
catlg<-nc_open("http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/waterbase/concentration_of_suspended_matter_in_water/catalog.nc")
I have the same problem as described in the question. However, it works perfectly in R under Linux
The file server is an OpenDAP server strictly following netcdf 4 conventions, but maybe some features are not correctly implemented in the ncdf4 package under Windows
for some reason I get the same error using [64-bit] C:\Program Files\R\R-3.4.2), but when using [64-bit] C:\Program Files\R\R-3.3.3 the ncdf4 package works fine.
not that this solves the problem, but it provides an easy work around for the time being.
For some reason I am suddenly not able to install packages in R (I have subsequently updated to the latest version of R and am running Windows 7). For example, if I type:
install.packages('beeswarm')
Installing package into ‘D:/Rlibs’ (as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip'
Content type 'text/html' length unknown opened URL downloaded 1859
bytes
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",
"Type")) : cannot open the connection In addition: Warning
messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting
from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"),
c("Package", "Type")) : cannot open compressed file
'beeswarm/DESCRIPTION', probable reason 'No such file or directory'
I have read that in Windows 7 there can be important restrictions on rights to writing to certain folders etc. so I've gone to some lengths to install R and library folders in non-default areas of my computer, and to allow myself rights to certain folders, but to no avail. Possibly also of importance is when I type:
.libPaths()
# [1] "D:/Rlibs"
# [2] "C:/Users/L.Halsey/Documents/R/win-library/3.0"
# [3] "C:/Users/L.Halsey/Documents/Documents/R-3.0.1/library"
I have created several folders in an attempt to create one that I could successfully install libraries into and set them up to be recognised by R using 'environment variables' from the start button. I don't know how to delete any of them though - not sure if this is relevant to my overall problem of not now being able to install/update packages for some reason.
The error being reported is inability to open a connection. In Windows that is often a firewall problem and is in the Windows R FAQ. The usual first attempt should be to run internet2.dll. From a console session you can use:
setInternet2(TRUE)
(You are correct in thinking this is not due to your library setup. The error says nothing about permissions.) I don't think just typing .libPaths should return that character vector since on my machine I would need to type .libPaths() to see something like that. If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values. This would pick the second and third of the existing paths
.libPaths( .libPaths()[2:3] )
The inner call retrieves the path vector and the outer call sets it to a reduced vector.
Running RStudio as administrator fixed it for me!
I will probably duplicate a lot of other answers on the stackoverflow, but I got exactly the same error as OP, namely:
Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'
Turned out, while I as a user had permissions to write in a certain directory, R did not. In order to be sure you don't have something similar, do following:
get a usb drive, let's name it E
download package source as a .zip file and store it onto usb-drive in some directory, let's name it E:/source
Create directory for libraries on the usb drive, let's name it E:/libs
Install packages calling R command install.package from the R console and setting all relevant directories to point to your usb drive:
(here I use package zoo as an example)
install.packages("E:/source/zoo_1.7-12.zip",
destdir = 'E:/source', # no "/" after the path
lib = 'E:/libs',
repos = NULL)
Load the package from the directory, where you installed it:
library('zoo', lib.loc = 'E:/libs')
After you are sure, it works this way on your usb drive, you can start resolving directories permissions, and try out by changing the paths in the code above.
update:
In some windows environments even your usb-stick might be protected from read-write by the R. Make sure you check the permissions using the machine you are working from.
The following worked for me (based on the answer above)
install.packages("clustvarsel", lib = "C:/Users/dnentchev/My Programs/R-3.2.2/library")
I had the same problem. I turned the windows firewall off, and Run RStudio as administrator. so, that error fixed.