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

Ahmadou Dicko dicko.ahmadou at gmail.com
Thu Jun 18 11:07:38 PDT 2015


I just tested the last version commited and it works now, thank you.
Although we still need to give the layer name in order to read a
vector using the plugin.
But this is another issue and I think we can solve this using
rgdal::ogrListLayers but it will require more change in the code base.

I will think about an alternative design of the readVECT using
ogrListLayers that will pass all the tests and I will let you know.

Thanks again



On Thu, Jun 18, 2015 at 4:35 PM, Rainer M Krug <Rainer at krugs.de> wrote:
> Roger Bivand <Roger.Bivand at nhh.no> writes:
>
>> Hi,
>>
>> Thanks for your interest. I do not use the plugins at all, as they
>> have historically led to great difficulty in managing and maintaining
>> rgdal (I sometimes rebuild GDAL more than once a day). If you would
>> like commit rights on R-Forge, please file a request there, and we can
>> try to find ways of automating checking (or testing) the
>> functionality, but without my contribution.
>
> Roger - I think you can release the bug fix I just commited after
> Ahmadou tried it out as it was an oversight.
>
> Cheers,
>
> Rainer
>
>>
>> Best wishes,
>>
>> Roger
>>
>> On Thu, 18 Jun 2015, Ahmadou Dicko wrote:
>>
>>> 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
>>> _______________________________________________
>>> grass-stats mailing list
>>> grass-stats at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/grass-stats
>
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer at krugs.de
>
> Skype:      RMkrug
>
> PGP: 0x0F52F982



-- 
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