spTransform() in R warnings with PROJ - r

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.

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.

r [sf] How to enable GEOS support?

I'm trying to transform the CRS of polygons that cross the dateline using the sf package following the example here, but get the warning
Warning message:
In CPL_wrap_dateline(x, options, quiet) :
GDAL Error 6: GEOS support not enabled.
which causes the final part of the code to fail:
library(sf)
#Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
point1 <- st_point(c(-179.5, -50))
point2 <- st_point(c(0, -30))
points <- st_sfc(point1, point2, crs = 4236)
points_trans <- st_transform(points, 32621)
circles <- st_buffer(points_trans, 100000)
circles_latlon <- st_transform(circles, 4326)
circles_latlon2 <- st_wrap_dateline(circles_latlon, options = c("WRAPDATELINE=YES"))
I've looked online on how to enable GEOS support (or perhaps just updating GDAL), but can't find a simple explanation. Any suggestions?
I'm running MACOS 10.13.6; R 3.5.0 (checked also with 3.5.1, but same issue).
I finally solved this by
downloading and installing the updated GDAL and GEOS libraries from here
downloading the source file of sf from cran
(re)installing sf using R CMD INSTALL sf_0.6-3.tar.gz --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/Versions/2.2/unix/bin/gdal-config -with-geos-config=/Library/Frameworks/GEOS.framework/Versions/3B/unix/bin/geos-config'. Note that I needed to (re)add the .gz extension as apple conveniently hides it.

Error: isTRUE(gpclibPermitStatus()) is not TRUE

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.

Creating wordcloud and I got this 'dataptr' not provided by package 'Rcpp'

New to R and have the following question. I got the error below when I was trying to create wordcloud in R. Could anyone tell me what the error means and is there a workaround?
Error in .overlap(x1, y1, sw1, sh1, boxes) :
function 'dataptr' not provided by package 'Rcpp'
That is an error we are getting with the newest Rcpp (which uses a different initialization scheme and no user-facing library). Make sure you have
the current version of Rcpp
and a current / rebuilt version of wordcloud.
On my system, with a fresh install of wordcloud, it all works fine:
R> library(wordcloud)
Loading required package: Rcpp
Loading required package: RColorBrewer
R> example(wordcloud)
wrdcldR> wordcloud(c(letters, LETTERS, 0:9), seq(1, 1000, len = 62))
wrdcldR> if(require(tm)){
wrdcld+
wrdcld+ ##### from character #####
wrdcld+ wordcloud(
wrdcld+ "Many years ago the great British explorer George Mallory, who
wrdcld+ was to die on Mount Everest, was asked why did he want to climb
wrdcld+ it. He said, \"Because it is there.\"
[.... more omitted ...]
After a while, I got it.
1) As stated, reinstall the latest version of Rcpp is the solution.
2) On top of that, if you use a library other than wordcloud that do not load automatically RCPP, do not forget to include
library(Rcpp)
or
require(Rcpp)
on your code before
dyn.load("your_shared_lib.so")
Source:
building_shared_libs_with_Rcpp

Error with importShapefile with PBSmapping package in R

I am receiving a sporadic error message with importShapefile in PBSmapping (version 2.63.37) in RStudio (0.97.318), running R version 2.15.2, platform: i386-w64-mingw32/i386 (32-bit). I also received the error while running previous versions of R and RStudio.
> ST6 = importShapefile("Data/pvi_stat_2002_utm.shp", projection="UTM", readDBF = TRUE)
Error in 1:nrow(dbf) : argument of length 0
> traceback()
2: cbind(1:nrow(dbf), dbf)
1: importShapefile("Data/pvi_stat_2002_utm.shp", projection = "UTM",readDBF = TRUE)
I only receive this error occasionally - perhaps 1 in every 10 times that I run the code. But once the error occurs in a session, it occurs repeatedly and will not successfully implement the command until I have closed R completely and reopened it. On one occasion I had to reboot the computer for it to work, as successive reopening of R did not help.
I thought it might be a memory issue but sometimes I will get the error when no objects are in the workspace. And usually the code runs fine even if I have large objects loaded. In response to the error I have removed all objects from the workspace and even followed with gc(), but to no avail.
This is the only shapefile with which I have received the error but as it is the only one that I use with regularity and since I can not predict when the error will occur, my efforts with other shapefiles are inconclusive. Not sure about uploading a shapefile to Stack Overflow. The zipped file is about 9MB.
Have a look in the folder where your shapefile is. Is there actually a .dbf file? If there is, it sounds like it is empty or corrupted, or misnamed. Are you expecting your shapefile to have polygons with attributes. Can you try importShapefile(... readDBF = FALSE )? Maybe you can make our data available through a dropbox link or something?
Alternatively have you tried rgdal:::readOGR or, my personal favourite, maptools:::readShapePoly(). I personally find readShapePoly() to be extremely robust and there are methods for coercing a SpatialPolygonsDataFrame from sp to a PolySet from PBS.
If you really must use PBS have you tried...
require( maptools )
require( sp )
myshp <- readShapePoly("Data/pvi_stat_2002_utm")
myshpPBS <- SpatialPolygons2PolySet( myshp )
I am assuming that there is a .prj file with your shapefile, describing the projection information?
I'm using R-3.0.1 and PBS Mapping 2.66.53 with the NAVO Divisions shapefile from http://www.nafo.int/about/overview/gis/Divisions.zip. On Windows 7 x86_64 and OS X Snow Leopard (using macports R built for x86_64), the .dbf is being read properly, but it
sometimes fails using RHEL 5.9:
> library("PBSmapping", lib.loc="/home/gwhite/R/x86_64-unknown-linux-gnu-library/3.0")
-----------------------------------------------------------
PBS Mapping 2.66.53 -- Copyright (C) 2003-2013 Fisheries and Oceans Canada
[...]
-----------------------------------------------------------
> library("rgeos", lib.loc="/home/gwhite/R/x86_64-unknown-linux-gnu-library/3.0")
rgeos version: 0.2-19, (SVN revision 394)
GEOS runtime version: 3.3.8-CAPI-1.7.8
Polygon checking: TRUE
> layer='Divisions'
> divs = importShapefile(layer, projection='LL')
Error in 1:nrow(dbf) : argument of length 0
Using readDBF=F does allow the shapefile data to be read:
> divs = importShapefile(layer, projection='LL', readDBF=F)
So far, importShapefile() has been working in a freshly started R session.

Resources