mapme-initiative / mapme.vegetation

https://mapme-initiative.github.io/mapme.vegetation/
GNU General Public License v3.0
3 stars 2 forks source link

gdal_calc.py not executable on Windows #4

Open goergen95 opened 2 years ago

goergen95 commented 2 years ago
    I'm also stuck with the scl_buffer now. But I'm not sure if my error is related to GRASS or more to GDAL
scl_buffer(scl_files = scl_files, 
+            mask_values = c(1,2,3,7,8,9,10,11), # which values to mask?
+            mask_buffer = 100, 
+            grass_bin = "C:/OSGeo4W64/apps/grass/grass79", 
+            threads = 1, 
+            outdir = "C:/SOM-Togdheer/R-programs/CM_S2A")
  |                                                             |   0%Error in system(rcl_command, intern = T) : 
  'CreateProcess' failed to run 'C:\OSGEO4~1\apps\gdal2\pymod3\scripts\GDAL_C~1.PY -A C:/SOM-Togdheer/R-programs/S2A/S2A_38PMR_20220904_0_L2A_SCL.tif --outfile=C:\Users\stp.CES\AppData\Local\Temp\Rtmpy2M6cL\file4db4395f70c8.tif --calc="1*(A==1)+1*(A==2)+1*(A==3)+1*(A==7)+1*(A==8)+1*(A==9)+1*(A==10)+1*(A==11)"'

I already updated my PATH to include the path to the gdal scripts but now it fails to run

Originally posted by @stpCES in https://github.com/mapme-initiative/mapme.vegetation/issues/2#issuecomment-1257929218

goergen95 commented 2 years ago

This seems to be related to an osgeo4w installation not properly set up. Could you please verify if you are able to run gdal_calc.py routine, e.g. in the OSGEO4W shell? You can consider this site to set up the proper environment settings system wide or this gist to set it up for your R session.

stpCES commented 2 years ago

Thanks for the those instructions, but that has not solved the problem yet. Here is what I did in the mean time:

I can not run gdal_calc.py , neither in R nor under the OSGeo4W shell. In the shell it recognises the command but it always gives the same error. gdal_calc.py: error: the following arguments are required: --calc, --outfile Even if you type gdal_calc.py --help. I tried the calculation from the scl_buffer command in R in various ways: gdal_calc.py --calc="1*(A==1)+1*(A==2)+1*(A==3)+1*(A==7)+1*(A==8)+1*(A==9)+1*(A==10)+1*(A==11)" -A C:/SOM-Togdheer/R-programs/S2A/S2A_38PMR_20220904_0_L2A_SCL.tif --outfile=C:/Users/stp/AppData/Local/Temp/Rtmp4S8UcC/file40c0454764b.tif

EDITION Finally got it running under OSGEO4W shell, the ".py" was to much: gdal_calc --calc="1*(A==1)+1*(A==2)+1*(A==3)+1*(A==7)+1*(A==8)+1*(A==9)+1*(A==10)+1*(A==11)" -A C:/SOM-Togdheer/R-programs/S2A/S2A_38PMR_20220904_0_L2A_SCL.tif --outfile="C:\Users\stp\Desktop\file4.tif" No matter the direction of the slashes. But it is still not running from your R package

stpCES commented 1 year ago

Any more ideas?

goergen95 commented 1 year ago

Can't really tell why it should not work... Maybe it is the direction of the slashes. Similar to my answer at #5 I don't have the resource to fix this any time soon. You could think about switching the OS, though.

goergen95 commented 1 year ago

Could you please install with remotes::install_github(repo = "mapme-initiative/mapme.vegetation", ref = "4-gdal_calcpy-not-executable-on-windows")and check if that fixes the issue?

stpCES commented 1 year ago

I will try it out on monday. Thanks for the support

stpCES commented 1 year ago

image After installing the changed package, it ends the process without any error but it also does not do anything.

goergen95 commented 1 year ago

Please do a quick reinstalltion with the command supplied above to make sure you have Installed the latest reference?

stpCES commented 1 year ago

remotes::install_github(repo = "mapme-initiative/mapme.vegetation", ref = "4-gdal_calcpy-not-executable-on-windows") Skipping install of 'mapme.vegetation' from a github remote, the SHA1 (1030f180) has not changed since last install. Use force = TRUE to force installation

stpCES commented 1 year ago

Good morning Darius, I followed your advise and switched to Linux/Ubuntu 22.04 using a VMBox. It took me 2,5 days to get the VM with all the programs running. But now it looks that there is some issue with the Grass installation.

>grass_bin = "/usr/bin/grass78"
> rundir <- "./s2"
> s2_files = list.files(rundir, full.names = T)
> scl_files = s2_files[grep("SCL", s2_files)]
> rundir = "./scl"
> scl_buffer(scl_files = scl_files,     mask_values = c(1,2,3,7,8,9,10,11), mask_buffer = 200, grass_bin = grass_bin, threads = 1, outdir = rundir)
  |                                                                                       |   0%Error in linkGRASS7(tmpname, gisdbase = gisdb, location = location, default_GRASS7 = grass) : 
  unused argument (default_GRASS7 = grass)

Moreover I realized that I could start GRASS from the terminal but not over the GUI shortcut. When starting on the terminal I get the following warnings:

Starting GRASS GIS...

WARNING: Invalid line in RC file (/tmp/grass7-vboxuser-10622/gisrc): ' GISDBASE
' (not enough values to unpack (expected 2, got 1))
WARNING: Empty RC file (/tmp/grass7-vboxuser-10622/gisrc)
WARNING: Invalid line in RC file (/tmp/grass7-vboxuser-10622/gisrc): ' GISDBASE
' (not enough values to unpack (expected 2, got 1))
WARNING: Empty RC file (/tmp/grass7-vboxuser-10622/gisrc)

I added the following lines into the /etc/environment file without any impact GISBASE="/usr/lib/grass78" GISDBASE=/home/vboxuser/grassdb"

I tried one more thing by adding the rgrass package in R:

> library(rgrass)
Loading required package: XML
Registered S3 methods overwritten by 'rgrass':
  method                     from   
  print.gmeta                rgrass7
  print.GRASS_interface_desc rgrass7
GRASS GIS interface loaded with GRASS version: (GRASS not running)

Conclusion: Something is still wrongly configured. Could you help me out with the configuration of your system