[GRASS-stats] Mapset and layer names in readVECT using GRASS GDAL plugin

Ahmadou Dicko dicko.ahmadou at gmail.com
Thu Jun 18 04:18:47 PDT 2015


Hi,

I'm trying to use the direct OGR access to GRASS vector using plugin
through the rgrass7 package in R but I have some issues with the
mapset argument.

Here are the steps to reproduce the bug using the nc_basic_spm_grass7
GRASS location and user1 mapset.

Within the GRASS session, we launch R
library(rgrass7)
v <- readVECT("geonames", plugin = TRUE)
Error in .read_vect_plugin(vname = vname, layer = layer, type = type,  :
  object 'mapset' not found

One way to fix this, is to add a mapset argument to .read_vect_plugin
and set it by default to the same argument in the readVECT function.

### Example of fix
readVECT <- function(..., mapset = NULL, ...) {
 ....
         if (plugin) {
            res <- .read_vect_plugin(..., mapset = mapset, ...)
 ....
}

But once this problem solved, another one appears. This one, need
confirmation though. Using the GRASS GDAL plugin, I can't open a GRASS
vector without using the layer name. I am aware that we can use the
layer number using other driver (Shapefiles, GML, etc) but I looks
like (at least in my setup) that I can't open it without giving the
layer name.

I modified rgrass7:::.read_vect_plugin and named it .read_vect_plugin2
and added a mapset argument (to correct the first bug).

### Reproducing the error
sss <- strsplit(packageDescription("rgdal")$Version, "-")[[1]]

class(
.read_vect_plugin2("geonames",
                    mapset = NULL,
                    layer = 1L,
                    sss = sss,
                    ignore.stderr = TRUE,
                    pointDropZ = TRUE)
)
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
use_iconv = use_iconv,  :
  Cannot open layer


class(
 .read_vect_plugin2("geonames",
                     mapset = NULL,
                     layer = "geonames",
                     sss = sss,
                     ignore.stderr = TRUE,
                     pointDropZ = TRUE)
)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"

Please can you confirm that it is a feature of the plugin to have the
real name instead of the layer number ?

Nonetheless, one way to fix this is to add a call to
rgdal::ogrListLayers in the rgrass7:::.read_vect_plugin

    dsn <- paste(gg$GISDBASE, gg$LOCATION_NAME, mapset, "vector",
                 vname[1], "head", sep = "/")
    layers <- rgdal::ogrListLayers(dsn = dsn)

Using this approach we can have the layer names and use it in readOGR.
I hope that I described it clearly.

Best regards,

Info and spec
Linux:
Linux dickoa 4.0.5-1-ARCH #1 SMP PREEMPT Sat Jun 6 18:37:49 CEST 2015
x86_64 GNU/Linux

GRASS:
version=7.1.svn
date=2015
revision=65487
build_date=2015-06-16
build_platform=x86_64-unknown-linux-gnu

GDAL:
GDAL 1.11.2, released 2015/02/10


R:
sessionInfo()
R version 3.2.1 RC (2015-06-14 r68519)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Arch Linux

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
[7] base

other attached packages:
[1] rgdal_0.9-3   rgrass7_0.1-0 XML_3.98-1.2  sp_1.1-1

loaded via a namespace (and not attached):
[1] tools_3.2.1     grid_3.2.1      lattice_0.20-31



-- 
Ahmadou H. DICKO
statistician economist (Ingénieur Statisticien Économiste)
PhD candidate in Climate change economics
Faculty of economics and managment - Cheikh Anta Diop University
West African Science Service Center on Climate Change and Adaptated
Land Use (WASCAL)
Center for Development Research (ZEF) - University of Bonn
email : ahmadou.dicko at ucad.edu.sn
twitter : @dickoah
github : github/dickoa
tel : +221 33 827 55 16
portable: +221 77 123 81 69


More information about the grass-stats mailing list