Error: isTRUE(gpclibPermitStatus()) is not TRUE - r

This question may be a duplicate of an earlier unanswered one. I still have the problem.
I am trying to use a zipcode shapefile and coming up with the following error:
tract <- readOGR(dsn = ".", layer = "cb_2013_us_zcta510_500k")
tract<-fortify(tract, region="GEOID10")
Error: isTRUE(gpclibPermitStatus()) is not TRUE
I have tried installing gpclib to fix this but then I get the following error:
install.packages("gpclib")
Installing package into ‘C:/Users/Nick/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘gpclib’
These will not be installed
Help?

You can look at Hadley's master file for ggplot2/R/fortify-spatial.r. Based on this outside link, my understanding is that lines 31–34 (in it's current form) used to read something like
# Union together all polygons that make up a region
try_require(c("gpclib", "maptools"))
unioned <- unionSpatialPolygons(cp, invert(polys))
So back then one way to attack the problem was to turn on the license
library(rgdal)
library(maptools)
if (!require(gpclib)) install.packages("gpclib", type="source")
gpclibPermit()
As #rcs, #Edzer Pebesma, and this answer mention, rgeos should resolve the issue for more recent installations.

I ran into the same problem but the solution was slightly different than those listed above.
As mentioned by others, the issue is the dependency on gpclib, which is required by maptools.
However, after loading maptools, it provided the following message ...
> library('maptools')
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
So rgeos can be used instead of gpclib. To resolve, I did the following ...
install.packages('rgeos', type='source')
install.packages('rgdal', type='source')
The reinstallation of rgdal removes the dependency on gpclib and points to rgeos.
Hope this is helpful.

I learned this answer elsewhere: I had to type
install.packages("gpclib", type="source")
and it worked just fine.

Related

Unable to read shapefiles with st_read() in R

I am trying to read a shapefile
library(sf)
wards <- read_sf("Shape_files/benguluru_ward_boundaries_reprojected.shp")
and I am getting this error
Error in CPL_get_z_range(obj, 3) : z error - expecting three columns;
I googled it and it seems it has to do with z-dimension but I couldn't find a solution. How to solve this? Thanks in advance.
Edit:
This is what I am getting when I load the sf package
> library(sf)
Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
you can get the files here
Edit2: I was able to solve this by running extract z values as mentioned here and there dropping it while exporting the layer. I am able to read that new layer without any issues.

Error in library(sp) : there is no package called 'sp'

The sp package was installed using RStudio (through CRAN) but when R evaluates the code:
library(sp)
It throws an error
Error in library(sp) : there is no package called 'sp'
I noticed that it works for R versions 4.* but does not work for versions 3.*. What could be causing this?
If you first time to use 'sp', install.... :)
install.packages("sp")
library(sp)

spTransform() in R warnings with PROJ

I'm in R v 4.0.4 - sp v 1.4-5, and rgdal 1.5-23. I'm loading a shapefile using the rgdal package and then trying to simply apply spTransform() but I'm getting a ridiculous set of warnings that I can't get rid of. Anyone have any insight on this?
options("rgdal_show_exportToProj4_warnings"="none")
library(rgdal)
library(sp)
## Shapefile has a projection of WGS84
X <- readOGR(dsn=".", layer="myshapefile.shp")
UTM30 <- sf::st_crs(32630)$proj4string
transf <- spTransform(X,UTM30)
############################################################
### This warning gets repeated tens to hundreds of times ###
proj_as_proj_string: C:\PostgreSQL\13\share\contrib\postgis-3.1\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
proj_as_wkt: C:\PostgreSQL\13\share\contrib\postgis-3.1\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
proj_create: C:\PostgreSQL\13\share\contrib\postgis-3.1\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
Anyone come across this yet and managed to squash it?
Cheers
Found this explanation from rgdal:
The 'GDAL' and 'PROJ' libraries are external to the package, and, when installing the package from source, must be correctly installed first; it is important that 'GDAL' < 3 be matched with 'PROJ' < 6. From 'rgdal' 1.5-8, installed with to 'GDAL' >=3, 'PROJ' >=6 and 'sp' >= 1.4, coordinate reference systems use 'WKT2_2019' strings, not 'PROJ' strings.

how to read.jpeg in R 2.15

It seems very trivial but I can't read in jpeg, or any type of image into R 2.15. In R 2.10 I could do it using rimage library or ReadImage library - with read.jpeg for example - but there seems to be no way to do it in R 2.15 and later versions. Any thoughts on this?
library('ReadImages')
Error in library("ReadImages") : there is no package called ‘ReadImages’ >
install.packages('ReadImages') Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified)
Warning in install.packages : package ‘ReadImages’ is not available (for R version 2.15.1)
As pointed out in comments, try the jpeg package.
install.packages("jpeg") ## if necessary
library(jpeg)
## get help
library(help = jpeg)
## get more help
?readJPEG
Example, from the help:
# read a sample file (R logo)
img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
Another option is rgdal, which can read from a massive bestiary of formats. Plotting and manipulation are handled differently.
install.packages("rgdal") ## if necessary
library(rgdal)
img <- readGDAL(file.path(R.home(), "doc", "html", "logo.jpg"))
There is also the readbitmap package on CRAN, it's always worth a basic search of the packages list for what you are looking for.
also:
## if not already installed
install.packages("jpeg")
library(jpeg)
?readJPEG()
img <- readJPEG("/Users/name/locationInFileDirectory/image.jpg", native = TRUE)
#this will display your image to test you read it correctly
if(exists("rasterImage")){
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
}

dependent packages not loading in R on Debian

I'm having trouble loading the sde package on a clean Debian install running R 2.11.1. I've seen this behavior with some other packages, however, so I don't think it's specific to only this one package. Here's an example of the conundrum:
>install.packages("sde", lib.loc=libPath)
... installs sde, and the packages it's dependent on: zoo, fda
> library(sde, lib=libPath)
Loading required package: fda
Error: package 'fda' could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) :
there is no package called 'fda'
ok, that's odd. I saw fda being installed. So I manually load the dependencies:
> library(zoo, lib=libPath)
> library(fda, lib=libPath)
Loading required package: splines
ok, that worked. Now let's try sde:
> library(sde, lib=libPath)
To check the errata corrige of the book, type vignette("sde.errata")
WTF? it loaded fine?!?
So why can I manually load the packages but R is not picking them up automagically?
Adding to my confusion, I discovered during debugging that if I don't use the lib=libPath then everything works just fine. So it looks like the use of a custom path for packages is screwing this all up... but why?
You confirmed my suspicions in the comments. You need to do one of two things:
.libPaths(libPath)
or
library(sde, lib=c(libPath,.libPaths()))
I prefer the first method because the second requires you do that for all calls to library.

Resources