Re: [GRASS-user] [R] Need help using GRASS within R - error when running the script for a second time

2020-07-07 Thread Helmut Kudrnovsky
>ERRORS WHEN I RUN THE SCRIPT FOR A SECOND TIME :
>
>  - FROM WINDOWS : g.region.exe : the procedure entry point
> GEOSMakeValid_r could not be located in the dynamic link library
> C:\Program Files\GRASS GIS 7.8\extrabin\gdal300.dll

this looks like a dll mismatch. more than one GDAL seems to be in %PATH%



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] [R] Need help using GRASS within R - error when running the script for a second time

2020-07-07 Thread Micha Silver

  
  
Hello Loïc


Let's keep the discussion on the list, so others can help and
  benefit from responses.


BTW, you might want to post to the r-sig-geo list also. If you
  come across questions specific to R and spatial functions, that's
  the best place to ask.


Below,inline, some guesses as to what is happening...



On 07/07/2020 0:03, Loïc Valéry wrote:


  Dear Micha,

As you expected, I should have kept a few thanks in stock ! ;-) because I have a new little problem with rgrass7 !
In fact, when I run the script that you kindly corrected me (as a reminder, our exchange of previous emails is below) , everything goes fine...the first time. If I run the script a second time, I get an error message from Windows and another one from R (see below).
For the script to work properly again I have to close and open R (or use the .rs.rstartR() command from RStudio) which is not very convenient because it stops the script.

I tried to fix this error but without success. That's why I'm contacting you, hoping you will have an idea on how to "reset" rgrass7 without having to restart a new session.

I thank you in advance for your answer and remain at your disposal if you need additional information to find the solution.
Kind regards,
Loïc


ERRORS WHEN I RUN THE SCRIPT FOR A SECOND TIME :

  - FROM WINDOWS : g.region.exe : the procedure entry point GEOSMakeValid_r could not be located in the dynamic link library C:\Program Files\GRASS GIS 7.8\extrabin\gdal300.dll

  - FROM R : 
# Link to GRASS GIS software v.7.8.3

  
initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 

  
  +   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+   remove_GISRC=T, override=T)
Error in if (is.na(projstr)) uprojargs <- projstr else uprojargs <- paste(unique(unlist(strsplit(projstr,  : 
  l'argument est de longueur nulle
De plus : There were 50 or more warnings (use warnings() to see the first 50)



I'm not sure, but I don't think you want to rerun initGRASS()
  a second time. In your script, you do initGRASS only once,
  then if you need to perform several analyses, do them in the same
  (running) GRASS session.



  

  

# Specifying the projection reference for the GRASS working environment
p4str<-sp::proj4string(seg_poly)

  
  Warning message:
In sp::proj4string(seg_poly) :
  CRS object has comment, which is lost in output

  

execGRASS("g.proj", flags = "c", proj4 = p4str)
rgrass7::use_sp()

# Converting the 'sp' object into a GRASS-readable file format (here, 'vec1.shp')
writeVECT(seg_poly,"vec1",v.in.ogr_flags=c("o", "overwrite"), 

  
  +   driver="ESRI Shapefile")



The driver name is "ESRI_Shapefile" (note the underscore).
  Perhaps that is the problem here?



  
Error in writeVECT(seg_poly, "vec1", v.in.ogr_flags = c("o", "overwrite"),  : 
  driver %in% candDrivers is not TRUE
De plus : Warning message:
In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'v.in.ogr.exe -f' renvoie un statut 313

  


# Run the 'v.generalize' function  
execGRASS("v.generalize",flag=c("overwrite"),

  
  +   parameters=list(input="vec1",
+   output="GRASS_smooth_seg_poly",
+   error="GRASS_smooth_seg_poly_error",
+   method="distance_weighting",
+   threshold=1))

  


# Converting the shapefile 'GRASS_smooth_seg_poly.shp' into a R-readable object 
# (here, a SpatialPolygonDataFrame named 'smooth_seg_poly')
smooth_seg_poly<-readVECT("GRASS_smooth_seg_poly", with_prj=T, 

  
  +   driver="ESRI Shapefile")



Same here, the driver name for shapefile is wrong.


I would also add that both R and GRASS have switched to the
  better Geopackage format for exchanging spatial data. You might
  want to try, the driver name is "GPKG"



See details about Geopackage here:
https://www.gis-blog.com/geopackage-vs-shapefile/
and in French here:
https://www.sigterritoires.fr/index.php/le-format-geopackage-et-qgis-3/


Best, Micha





  
Error in .read_vect_non_plugin(vname = vname, layer = layer, type = type,  : 
  driver %in% candDrivers is not TRUE
De plus : Warning message:
In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'v.in.ogr.exe -f' renvoie un statut 313






PREVIOUS EMAILS: 

De : Micha Silver 
Envoyé : mardi 9 juin 2020 23:08
À : Loïc Valéry