[R-sig-Geo] rgrass7 : Error in parseGRASS

Chris Reudenbach reudenbach at uni-marburg.de
Thu Nov 24 11:38:02 CET 2016


@Michael fine!

@Roger

this is  pretty dirty "hack" I did not cross check if I got all 
variables dealing with GRASS. I would like to do it more systematically. 
Nevertheless as far as I understand the osgeo4w concept, we have only 
two changing names. 1) the installation root directory   2) the GRASS 
version name, that is used as a part of the internal  path structure.  I 
would like to check this and if so it might be easy to integrate this in 
initGRASS.

cheers Chris

Am 24.11.2016 um 10:48 schrieb Roger Bivand:
> On Thu, 24 Nov 2016, Michael DELORME wrote:
>
>> That's great Chris, it works fine as is !
>> Thank you, I don't have to keep another GRASS install aside then.
>
> Thanks for confirming this. I'll try to set up a test rig to allow 
> initGRASS to set up the environment variables when using GRASS in 
> OSGeo4W for a later release.
>
> Roger
>
>>
>> I'm sure it will be helpful to other people also.
>> Thanks again
>>
>> Le 24/11/2016 09:17, Chris Reudenbach a écrit :
>>> Michael,
>>>
>>> Using a fresh OSGEO4W64 standard quick desktop installation (i.e.
>>> installation of the default desktop GIS software packages with the
>>> installer and using C:\OSGeo4W64 as path)  I suggest the below 
>>> solution.
>>>
>>> You have to set all necessary eniromental and system variables
>>> manually. I am not quit sure if I got them but actually it seems to
>>> work for your question. As a conclusion I think your Python and all of
>>> the rest is installed correct.
>>>
>>>
>>> cheers Chris
>>>
>>>
>>> ############### librarys, data etc
>>> ---------------------------------------------
>>> library(rgrass7)
>>> library(sp)
>>>
>>> # setup a temp workingdir
>>> working.dir<- "~/tmp/"
>>>
>>> # get meuse data
>>>
>>> data(meuse)
>>> data(meuse.grid)
>>>
>>> # georeference the meuse grid data
>>> coordinates(meuse.grid) <- ~x+y
>>> proj4string(meuse.grid) <- CRS("+init=epsg:28992")
>>> gridded(meuse.grid) <- TRUE
>>>
>>> # get a first cellsize/pixel resolution for GRASS
>>> resolution <- meuse.grid at grid@cellsize[1]
>>>
>>> # georeference the meuse data
>>> coordinates(meuse) <- ~x+y
>>> proj4string(meuse) <- CRS("+init=epsg:28992")
>>>
>>> # get projection, proj4 string and extent for GRASS
>>> projection<-(strsplit(meuse at proj4string@projargs,split = " "))
>>> proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse
>>> = ' ')
>>> xmax<-meuse at bbox[3]
>>> xmin<-meuse at bbox[1]
>>> ymax<-meuse at bbox[4]
>>> ymin<-meuse at bbox[2]
>>>
>>> # create and set working directory
>>> if (!file.exists(file.path(working.dir,"run"))){
>>>   dir.create(file.path(working.dir,"run"),recursive = TRUE)
>>> }
>>> setwd(file.path( working.dir,"run"))
>>>
>>>
>>> ########### SETUP OSGEO4W enviroment settings manually
>>> -------------------------
>>> # setup the OSGEO4W environ manually
>>> # assuming a osgeow4w default "deskop fastinstall
>>> # using the default installation directory "C:\OSGeo4W64"
>>>
>>> # set OSGE4W base directory
>>> osgeo4w.root<-"C:\\OSGEO4~1"
>>> Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
>>> # define GISBASE
>>> grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
>>> Sys.setenv(GISBASE=grass.gis.base)
>>>
>>> Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe")) 
>>>
>>>
>>> Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27")) 
>>>
>>>
>>> Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python")) 
>>>
>>>
>>> Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj")) 
>>>
>>>
>>> Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>>> Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal")) 
>>>
>>> Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv")) 
>>>
>>>
>>> Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf")) 
>>>
>>>
>>>
>>> # call all OSGEO4W settings
>>> system("C:/OSGeo4W64/bin/o-help.bat")
>>>
>>>
>>> # create PATH variable
>>> Sys.setenv(PATH=paste0(grass.gis.base,";",
>>> "C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
>>> "C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
>>>                        "C:\\OSGeo4W64\\bin",";",
>>>                        "c:\\OSGeo4W64\\apps",";",
>>>                        "C:\\OSGEO4~1\\apps\\saga",";",
>>> paste0(Sys.getenv("WINDIR"),"/WBem"),";",
>>>                        Sys.getenv("PATH")))
>>>
>>>
>>> #################### start with GRASS setup
>>> ------------------------------------
>>> rgrass7::initGRASS(gisBase=grass.gis.base,
>>>                    home=tempdir(),
>>>                    mapset='PERMANENT',
>>>                    override=TRUE
>>> )
>>>
>>> # assign GRASS projection according to data set
>>> rgrass7::execGRASS('g.proj',
>>>                    flags=c('c','quiet'),
>>>                    proj4=proj4
>>> )
>>>
>>> # assign GRASS extent and resolution
>>> rgrass7::execGRASS('g.region',
>>>                    flags=c('quiet'),
>>>                    n=as.character(ymax),
>>>                    s=as.character(ymin),
>>>                    e=as.character(xmax),
>>>                    w=as.character(xmin),
>>>                    res=as.character(resolution)
>>> )
>>>
>>>
>>> #############   now do GRASS STUFF
>>> ---------------------------------------------
>>>
>>> rgrass7::writeVECT(meuse,"meuse")
>>> rgrass7::execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2
>>> double
>>>                    precision")
>>> #############  do other command line stuff
>>> -------------------------------------
>>>
>>> ## call gdal
>>> system("gdal_merge")
>>>
>>> # call saga cli
>>> system("saga_cmd")
>>>
>>>
>>> Am 23.11.2016 um 07:38 schrieb Michael DELORME:
>>>> Thanks for your insight.
>>>> I'll use a stand-alone GRASS install.
>>>>
>>>> Cordially
>>>>
>>>> Le 22/11/2016 15:13, Roger Bivand a écrit :
>>>>> On Tue, 22 Nov 2016, Michael DELORME wrote:
>>>>>
>>>>>> Thanks for investigating.
>>>>>>
>>>>>> I'll try a standalone version of GRASS if needed.
>>>>>>
>>>>>> Here is the traceback
>>>>>>
>>>>>>> traceback()
>>>>>> 4: stop(paste(cmd, "not parsed"))
>>>>>> 3: parseGRASS(cmd, legacyExec = legacyExec)
>>>>>> 2: doGRASS(cmd, flags = flags, ..., parameters = parameters, 
>>>>>> echoCmd =
>>>>>> echoCmd, legacyExec = legacyExec)
>>>>>> 1: execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2
>>>>>> double
>>>>>> precision")
>>>>>>
>>>>>> My C:\OSGeo4W64\apps\grass\grass-7.0.5\bin lists *.exe or *.bat and
>>>>>> indeed the *.bat command are those which don't work (r.mask.bat,
>>>>>> v.db.addcolumn.bat,...). The batch calls Python scripts ; for 
>>>>>> example
>>>>>> v.db.addcolumn.bat is :
>>>>>>
>>>>>> @"%GRASS_PYTHON%" "%GISBASE%/scripts/v.db.addcolumn.py" %*
>>>>>>
>>>>>> So I guess something must be wrong in my Python installation... (it
>>>>>> works however from within a GRASS shell)
>>>>> No, the logic for Windows and initGRASS has only ever been tested 
>>>>> with
>>>>> stand-alone GRASS. I would guess that in OSGeo4W the path variables
>>>>> are wrong. I cannot even find out how to run initGRASS in R but
>>>>> outside the OSGeo4W shell (doesn't find iconv.dll) or inside the
>>>>> OSGeo4W shell (cannot create a temporary GRASS location). Unless you
>>>>> or others really need OSGeo4W, I suggest asking others to implement
>>>>> that - very bulky and fragile.
>>>>>
>>>>> Roger
>>>>>
>>>>>> Cordially
>>>>>>
>>>>>>
>>>>>> Le 22/11/2016 14:30, Roger Bivand a écrit :
>>>>>>> On Tue, 22 Nov 2016, Michael DELORME wrote:
>>>>>>>
>>>>>>>> Thanks for replying
>>>>>>>>
>>>>>>>> Here is a reproducible example (change your GRASS directory of
>>>>>>>> course) :
>>>>>>>>
>>>>>>>> library(rgrass7)
>>>>>>>> library(sp)
>>>>>>>> initGRASS("C:/OSGeo4W64/apps/grass/grass-7.0.5", home = tempdir(),
>>>>>>>> override = TRUE)
>>>>>>>> data(meuse)
>>>>>>>> coordinates(meuse) <- ~x+y
>>>>>>>> writeVECT(meuse, "meuse")
>>>>>>>> execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2 
>>>>>>>> double
>>>>>>>> precision")
>>>>>>> This appears to run correctly on Windows 7 with GRASS 7.0.5 Windows
>>>>>>> stand-alone. Do you need to use OSGeo4W - the internal logic 
>>>>>>> used for
>>>>>>> finding out where the different versions keep their executables and
>>>>>>> batch files varies?
>>>>>>>
>>>>>>> What does traceback() say after the error? The error comes from
>>>>>>> parseGRASS("v.db.addcolumn") - the XML error comes from not being
>>>>>>> able
>>>>>>> to read the output of v.db.addcolumn<.ext> --interface-description
>>>>>>> where <.ext> may be .exe or .bat I think.
>>>>>>>
>>>>>>> Roger
>>>>>>>
>>>>>>>> I get :
>>>>>>>> Error : XML content does not seem to be XML: 'The specified path
>>>>>>>> was not
>>>>>>>> found.'
>>>>>>>> In addition: Warning message:
>>>>>>>> running command 'v.db.addcolumn.bat --interface-description' had
>>>>>>>> status 1
>>>>>>>> Error in parseGRASS(cmd, legacyExec = legacyExec) :
>>>>>>>>   v.db.addcolumn not parsed
>>>>>>>>
>>>>>>>> Other execGRASS commands (like r.neighbors, r.mapcalc,..)  work
>>>>>>>> fine,
>>>>>>>> but some other (r.mask) fail with a similar XML error.
>>>>>>>>
>>>>>>>> All commands work fine when used from the GRASS shell...
>>>>>>>>
>>>>>>>> What is this XML error ?
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> Le 22/11/2016 09:34, Roger Bivand a écrit :
>>>>>>>>> On Tue, 22 Nov 2016, Michael DELORME wrote:
>>>>>>>>>
>>>>>>>>>> Dear list,
>>>>>>>>>>
>>>>>>>>>> Using rgrass7 on Windows7 with GRASS 7.0.5 (OSGeo distribution),
>>>>>>>>>> I get
>>>>>>>>>> the following error :
>>>>>>>>> Please always try to provide a reproducible example using a
>>>>>>>>> standard
>>>>>>>>> data set. In addition, the output of traceback() following the
>>>>>>>>> error
>>>>>>>>> would be helpful. Are you running R inside GRASS, or using R to
>>>>>>>>> initiate GRASS?
>>>>>>>>>
>>>>>>>>> Consider using the grass-stats list:
>>>>>>>>>
>>>>>>>>> https://lists.osgeo.org/mailman/listinfo/grass-stats
>>>>>>>>>
>>>>>>>>> as it is more likely to yield results, but there also provide an
>>>>>>>>> example that anyone can reproduce. The example should avoid 
>>>>>>>>> loading
>>>>>>>>> other packages, and should be run from the R console (not, say,
>>>>>>>>> RStudio).
>>>>>>>>>
>>>>>>>>> Roger
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>> execGRASS("v.db.addcolumn", map = "result_v", columns = 
>>>>>>>>>>> "area_m2
>>>>>>>>>>> double precision")
>>>>>>>>>> Error : XML content does not seem to be XML: 'Le chemin d'accés
>>>>>>>>>> spécifié est introuvable.' In addition: Warning message: running
>>>>>>>>>> command 'v.db.addcolumn.bat --interface-description' had 
>>>>>>>>>> status 1
>>>>>>>>>> Error in parseGRASS(cmd, legacyExec = legacyExec) :
>>>>>>>>>>   v.db.addcolumn not parsed
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> and a similar one for r.mask :
>>>>>>>>>>
>>>>>>>>>>> execGRASS("r.mask", raster = "map")
>>>>>>>>>> Error : XML content does not seem to be XML: 'Le chemin d'accés
>>>>>>>>>> spécifié est introuvable.'
>>>>>>>>>> In addition: Warning message:
>>>>>>>>>> running command 'r.mask.bat --interface-description' had 
>>>>>>>>>> status 1
>>>>>>>>>> Error in parseGRASS(cmd, legacyExec = legacyExec) : r.mask not
>>>>>>>>>> parsed
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> whereas most other execGRASS command I tried work as expected.
>>>>>>>>>> Any idea ?
>>>>>>>>>> Thanks in advance
>>>>>>>>>>
>>>>>>>>>> Here is my session info :
>>>>>>>>>>
>>>>>>>>>>> sessionInfo()
>>>>>>>>>> R version 3.3.1 (2016-06-21)
>>>>>>>>>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>>>>>>>>> Running under: Windows 7 x64 (build 7601) Service Pack 1
>>>>>>>>>>
>>>>>>>>>> locale:
>>>>>>>>>> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
>>>>>>>>>> LC_MONETARY=French_France.1252 LC_NUMERIC=C [5]
>>>>>>>>>> LC_TIME=French_France.1252
>>>>>>>>>> attached base packages:
>>>>>>>>>> [1] parallel  stats     graphics  grDevices utils     datasets
>>>>>>>>>> methods   base
>>>>>>>>>> other attached packages: [1] rgrass7_0.1-9 XML_3.98-1.4 
>>>>>>>>>> beepr_1.2
>>>>>>>>>> raster_2.5-8 sp_1.2-3 RPostgreSQL_0.4-1 DBI_0.5-1
>>>>>>>>>>
>>>>>>>>>> loaded via a namespace (and not attached): [1] magrittr_1.5
>>>>>>>>>> tools_3.3.1 audio_0.1-5 Rcpp_0.12.7 stringi_1.1.2 grid_3.3.1
>>>>>>>>>> stringr_1.1.0 lattice_0.20-34 [9] fortunes_1.5-3
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>      [[alternative HTML version deleted]]
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> R-sig-Geo mailing list
>>>>>>>>>> R-sig-Geo at r-project.org
>>>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>>>> -- 
>>>>>>>> *Michaël DELORME*
>>>>>>>> Administrateur de données, chargé de projet en géomatique
>>>>>>>> Service régional de l'information statistique, économique et
>>>>>>>> territoriale
>>>>>>>> Direction régionale de l'alimentation, de l'agriculture et de la
>>>>>>>> forêt
>>>>>>>> Auvergne-Rhône-Alpes
>>>>>>>> Site de Lyon
>>>>>>>> 165 rue Garibaldi – BP 3202 – 69401 LYON cedex 03
>>>>>>>> 04 78 63 34 21
>>>>>>>>
>>>>>>>> Pour écrire au service :
>>>>>>>> DRAAF Auvergne-Rhône-Alpes – SRISET
>>>>>>>> 16B rue Aimé Rudel – BP 45 – 63370 LEMPDES
>>>>>>>>
>>>>>>>> http://www.draaf.auvergne-rhone-alpes.agriculture.gouv.fr/
>>>>>>>>
>>>>>>>>      [[alternative HTML version deleted]]
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> R-sig-Geo mailing list
>>>>>>>> R-sig-Geo at r-project.org
>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>>
>>>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at r-project.org
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>> -- 
>> *Michaël DELORME*
>> Administrateur de données, chargé de projet en géomatique
>> Service régional de l'information statistique, économique et 
>> territoriale
>> Direction régionale de l'alimentation, de l'agriculture et de la forêt
>> Auvergne-Rhône-Alpes
>> Site de Lyon
>> 165 rue Garibaldi – BP 3202 – 69401 LYON cedex 03
>> 04 78 63 34 21
>>
>> Pour écrire au service :
>> DRAAF Auvergne-Rhône-Alpes – SRISET
>> 16B rue Aimé Rudel – BP 45 – 63370 LEMPDES
>>
>> http://www.draaf.auvergne-rhone-alpes.agriculture.gouv.fr/
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list