enzococca / movecostTOqgis

Rscipt for QGIS for Calculation of Slope-Dependant Accumulated Cost Surface, Least-Cost Paths, and Least-Cost Corridors Related to Human
GNU General Public License v3.0
1 stars 1 forks source link

Unable to find an inherited method for automatic conversion of "ddiMatrix" in "dgTMatrix" on QGIS #5

Open ThomasAndreArchgeo opened 1 week ago

ThomasAndreArchgeo commented 1 week ago

Hello,

First of all, thanks for your work and your library/package. The number of functions and ways of using them are really very practical, and have helped me on several occasions during the first year of my master's degree in archaeology.

The problem is that I haven't used it for several months, and when I try to test it again with data that worked last year, an error message appears, either with the QGIS extension or with the library on R. I suspect it has something to do with all the QGIS and R updates, but I wanted to know what I could do to use it again.

I'm sure my problem isn't a big one, and it's probably something I haven't thought of, but I confess I have no idea how to fix it. Can you tell me if my problem comes from my raster, from the way I call it in RStudio or from the version of one of the components I'm using (QGIS, R, etc...)?

Thank you in advance for your attention to my message and for your answer. I can send you further information or data if necessary. With my sincere appreciation,

Thomas ANDRE French master in a master's degree in archaeology


Information on my the setup : Running under : Windows 11 QGIS : 3.34.7 -Prizren Qt : 5.15.13 Python : 3.12.3 GDAL : 3.8.5 GEOS : 3.12.1-CAPI-1.18.1 Proj : Rel. 9.4.0, March 1st, 2024 PDAL : 2.6.3 (git-version: 816ce1) R : QGIS R Provider version 4.1.0


Error messages (translated from French, trying to retain the key words) : " R execution console output Please note that rgdal will be retired during 2023, plan transition to sf/stars/terra functions using GDAL and PROJ at your earliest convenience. See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution rgdal: version: 1.6-5, (SVN revision 1199) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02 Path to GDAL shared files: C:/Users/MyName/AppData/Roaming/QGIS/QGIS3/profiles/default/processing/rlibs/rgdal/gdal GDAL binary built with GEOS: TRUE Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821] Path to PROJ shared files: C:\PROGRA~1\QGIS 3.34.7\share\proj PROJ CDN enabled: FALSE Linking to sp version:1.6-0 To mute warnings of possible GDAL/OSR exportToProj4() degradation, use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal. Notification message : In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) : PROJ/GDAL PROJ string degradation in workflow repeated warnings suppressed Discarded datum Unknown based on GRS80 ellipsoid in Proj4 definition Warning : package 'movecost' is currently in use and will not be installed Error in as(x, "dgTMatrix") : Unable to find an inherited method for function for automatic conversion of "ddiMatrix" in "dgTMatrix" Calls : movecost ... geoCorrection -> .local -> adjacencyFromTransition -> as Execution stopped "

enzococca commented 1 week ago

Hi, I will take a look asap.

E

Il giorno lun 17 giu 2024 alle ore 13:20 ThomasAndreArchgeo < @.***> ha scritto:

Hello,

First of all, thanks for your work and your library/package. The number of functions and ways of using them are really very practical, and have helped me on several occasions during the first year of my master's degree in archaeology.

The problem is that I haven't used it for several months, and when I try to test it again with data that worked last year, an error message appears, either with the QGIS extension or with the library on R. I suspect it has something to do with all the QGIS and R updates, but I wanted to know what I could do to use it again. Just to be sure after several tests on QGIS, I also tried a test using RStudio directly, but a different error message appears, leaving me puzzled. With the error messages, I realized that it might be a problem linked to the DTM used, so I tried to use the studyplot parameter with a SpatialPolygonDataFrame of the area, as presented in the library documentation (section Acquiring online elevation data). However, the same error message was displayed...

I'm sure my problem isn't a big one, and it's probably something I haven't thought of, but I confess I have no idea how to fix it. Can you tell me if my problem comes from my raster, from the way I call it in RStudio or from the version of one of the components I'm using (QGIS, R, etc...)?

Thank you in advance for your attention to my message and for your answer. I can send you further information or data if necessary. With my sincere appreciation,

Thomas ANDRE French master in a master's degree in archaeology

Information on my the setup : Running under : Windows 11 QGIS : 3.34.7 -Prizren Qt : 5.15.13 Python : 3.12.3 GDAL : 3.8.5 GEOS : 3.12.1-CAPI-1.18.1 Proj : Rel. 9.4.0, March 1st, 2024 PDAL : 2.6.3 (git-version: 816ce1) R : QGIS R Provider version 4.1.0

Error messages (translated from French, trying to retain the key words) :

  1. QGIS " R execution console output Please note that rgdal will be retired during 2023, plan transition to sf/stars/terra functions using GDAL and PROJ at your earliest convenience. See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution rgdal: version: 1.6-5, (SVN revision 1199) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02 Path to GDAL shared files: C:/Users/MyName/AppData/Roaming/QGIS/QGIS3/profiles/default/processing/rlibs/rgdal/gdal GDAL binary built with GEOS: TRUE Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821] Path to PROJ shared files: C:\PROGRA~1\QGIS 3.34.7\share\proj PROJ CDN enabled: FALSE Linking to sp version:1.6-0 To mute warnings of possible GDAL/OSR exportToProj4() degradation, use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal. Notification message : In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) : PROJ/GDAL PROJ string degradation in workflow repeated warnings suppressed Discarded datum Unknown based on GRS80 ellipsoid in Proj4 definition Warning : package 'movecost' is currently in use and will not be installed Error in as(x, "dgTMatrix") : Unable to find an inherited method for function for automatic conversion of "ddiMatrix" in "dgTMatrix" Calls : movecost ... geoCorrection -> .local -> adjacencyFromTransition -> as Execution stopped "

  1. RStudio r = raster ("C:\Users\MyName\Desktop\Raster.tif") shp1 <- st_read(dsn = 'C:\Users\MyName\Desktop\Start.shp',layer = 'Start') shp2 <- st_read(dsn = 'C:\Users\MyName\Desktop\Goal.shp',layer = 'Goal') result <- movecost(origin=shp1, destin=shp2, studyplot=r,return.base=TRUE)

" Accessing raster elevation [=========================] 100% Mosaicing & Projecting Erreur in h(simpleError(msg, call)) : Erorr in argument 'fromCoords' evaluation when selecting a method for the function 'accCost' : unable to find an inherited method for function ‘coordinates’ for signature ‘obj = "sf"’ "

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KA2YVJP3LWMNUPLW7DZH3BAFAVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2TOMBYHE4TKNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Enzo Cocca PhD in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO International Association of Mediterranean and Oriental Studies

mail: @.*** cell: +393495087014

ThomasAndreArchgeo commented 1 week ago

Hi,

Thank you for your answer. I am sending this message after further tests on my side and a more in-depth rereading of the R library documentation. I finally saw that my error was not related to the raster used, but to the start and end points. I remembered using shapefiles last year without any issues, and didn't realize that SpatialPointDataFrame was now required with the new updates... By modifying my points in this format on RStudio, I managed to get the library to work on it. So it's likely that my problem with the module on QGIS is the same.

I'm sorry for the trouble, but wanted to know if you could help me with one point: I've tried to import my data transformed into SpatialPointDataFrame on QGIS, but it doesn't seems to work. Do you have any idea how to import them, or a tool/method to make my shapefiles compatible with the tool?

Thank you again for your attention to my problem, and sorry for the trouble for what is probably not a very complex issue. With my sincere appreciation,

Thomas ANDRE

enzococca commented 1 week ago

have you tried to upgrade the library, : sp, move cost (2.1) ?

ThomasAndreArchgeo commented 1 week ago

I think... RStudio indicates that the movecost library is updated to version 2.1 and the sp library to 2.1-4. But are the updates the same between RStudio and QGIS with the extension Processing R Provider ?

enzococca commented 1 week ago

Check in your log when try to use move cost which version you use.

Il giorno 19 giu 2024, alle ore 09:09, ThomasAndreArchgeo @.***> ha scritto:

I think... RStudio indicates that the movecost library is updated to version 2.1 and the sp library to 2.1-4. But are the updates the same between RStudio and QGIS with the extension Processing R Provider ?

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5#issuecomment-2177914583, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KDXEDAYG4BIMNTAWS3ZIEVBXAVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZXHEYTINJYGM. You are receiving this because you commented.

ThomasAndreArchgeo commented 1 week ago

It says "Linking to sp version:1.6-0", so it hasn't been updated (and I don't see movecost's version) (You have the full log in my first message) How can I update the library in QGIS ?

enzococca commented 1 week ago

Check i settings of the processing. In the section R you can set the path for the library. Generally it use the path of your R

Il mer 19 giu 2024, 09:41 ThomasAndreArchgeo @.***> ha scritto:

It says "Linking to sp version:1.6-0", so it hasn't been updated (and I don't see movecost's version) (You have the full log in my first message) How can I update the library in QGIS ?

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5#issuecomment-2177982233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KGHHLGFDVLL243BLY3ZIEY4DAVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZXHE4DEMRTGM . You are receiving this because you commented.Message ID: @.***>

ThomasAndreArchgeo commented 1 week ago

Ok, I have changed the access path... But I have a new error in the log :

"Notification message : the package 'rgdal' is not available for this version of R (I'm in 4.4.1...)

A version of this package for your version of R may be available elsewhere, See here : https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages Error in library("rgdal") : no package named 'rgdal' as been found Execution stopped"

But if I remember well, rgdal is no longer available in CRAN.... What can I do ?

enzococca commented 1 week ago

which version of movecost you use?

Il giorno mer 19 giu 2024 alle ore 10:07 ThomasAndreArchgeo < @.***> ha scritto:

Ok, I have changed the access path... But I have a new error in the log :

"Notification message : the package 'rgdal' is not available for this version of R (I'm in 4.4.1...)

A version of this package for your version of R may be available elsewhere, See here : https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages Error in library("rgdal") : no package named 'rgdal' as been found Execution stopped"

But if I remember well, rgdal is no longer available in CRAN.... What can I do ?

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5#issuecomment-2178034668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KEX3B7NATPTPCT732LZIE34LAVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGAZTINRWHA . You are receiving this because you commented.Message ID: @.***>

-- Enzo Cocca PhD in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO International Association of Mediterranean and Oriental Studies

mail: @.*** cell: +393495087014

ThomasAndreArchgeo commented 1 week ago

2.1 on RStudio

Movecost_version_QGIS

enzococca commented 1 week ago

maybe try to restart qgis

Il giorno mer 19 giu 2024 alle ore 10:13 ThomasAndreArchgeo < @.***> ha scritto:

2.1 on RStudio

Movecost_version_QGIS.png (view on web) https://github.com/enzococca/movecostTOqgis/assets/173052093/fdf80681-9092-444b-a0ff-3c1c10cf4691

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5#issuecomment-2178045310, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KGDRASL7TZCDH5WLMDZIE4SRAVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGA2DKMZRGA . You are receiving this because you commented.Message ID: @.***>

-- Enzo Cocca PhD in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO International Association of Mediterranean and Oriental Studies

mail: @.*** cell: +393495087014

ThomasAndreArchgeo commented 1 week ago

I have restarted GQIS, re-installed the plugin and I had the same message with rgdal

I also tried to copy the library from the QGIS repository to the R one, and here is the new error message in the log:

_"" R execution console output Please note that rgdal will be retired during 2023, plan transition to sf/stars/terra functions using GDAL and PROJ at your earliest convenience. See https://r-spatial.org/r/2022/04/12/evolution.html and https://github.com/r-spatial/evolution rgdal: version: 1.6-5, (SVN revision 1199) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02 Path to GDAL shared files: C:/Users/MyName/AppData/Roaming/QGIS/QGIS3/profiles/default/processing/rlibs/rgdal/gdal GDAL binary built with GEOS: TRUE Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821] Path to PROJ shared files: C:\PROGRA~1\QGIS 3.34.7\share\proj PROJ CDN enabled: FALSE Linking to sp version:1.6-0 To mute warnings of possible GDAL/OSR exportToProj4() degradation, use options("rgdal_show_exportToProj4warnings"="none") before loading sp or rgdal. Warning : package 'movecost' is currently in use and will not be installed Error in (function (cl, name, valueClass) : assignment of an object of class "logical" is not allowed for @'x' in an object of class "dgCMatrix"; is(value, "numeric") does not return TRUE Appels : movecost -> Anonymous Execution stopped"

is it normal that it tries to call rgdal ?

enzococca commented 1 week ago

I thin the script R are not updated. have you traied to push add script from the form of plugin move cost?

enzococca commented 1 week ago

the new form are like that : Screenshot 2024-06-19 alle 10 32 46

ThomasAndreArchgeo commented 1 week ago

When I press the button, nothing append (so I guess it's a sign that the version downloadable from the QGIS extensions library isn't working/updated...)

Here's what the form looks like with the version I have :

image

enzococca commented 1 week ago

So i think my R script are not updated. Try to do manually. In the folder r-script of qgis delete mu r-scripts and than push again the button to afd the r script from the form of plugin

Il mer 19 giu 2024, 10:39 ThomasAndreArchgeo @.***> ha scritto:

When I press the button, nothing append (so I guess it's a sign that the version downloadable from the QGIS extensions library isn't working/updated...)

Here's what the form looks like with the version I have :

image.png (view on web) https://github.com/enzococca/movecostTOqgis/assets/173052093/ffa2a959-d99a-4fad-acb1-2c2ebe400670

— Reply to this email directly, view it on GitHub https://github.com/enzococca/movecostTOqgis/issues/5#issuecomment-2178098849, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KBAEQCUJNKSZNQ57DTZIE7T5AVCNFSM6AAAAABJNZQZKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGA4TQOBUHE . You are receiving this because you commented.Message ID: @.***>

ThomasAndreArchgeo commented 1 week ago

Sorry for the delay of my answer, and once again, thank you for your help

So I tried to re-install the plugin with the zip version in the QGIS Python Plugins Repository I'm not sure I understood your message, but I've removed the scripts from the processing>rscripts folder, and then pushed the Add scripts (not sure if something append...)

I tried to run the movecost script, and saw that the log changed, but I still got an error.... : _" [1] "C:/Users/Thomas/AppData/Local/R/win-library/4.4/sf" Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE [1] "C:/Users/User/AppData/Local/R/win-library/4.4/raster" Loading required the package : sp [1] "C:/Users/User/AppData/Local/R/win-library/4.4/sp" [1] "C:/Users/User/AppData/Local/R/win-library/4.4/sf" [1] "C:/Users/User/AppData/Local/R/win-library/4.4/movecost" [1] "C:/Users/User/AppData/Local/R/win-library/4.4/progress" [1] "C:/Users/User/AppData/Local/R/win-library/4.4/raster" [[1]] [1] TRUE

[[2]] [1] TRUE

[[3]] [1] TRUE

[[4]] [1] TRUE

[[5]] [1] TRUE

layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA class : RasterLayer dimensions : 1261, 2136, 2693496 (nrow, ncol, ncell) resolution : 25, 25 (x, y) extent : 537762.5, 591162.5, 6430363, 6461888 (xmin, xmax, ymin, ymax) crs : +proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs source : memory names : layer values : 1, 1 (min, max)

Message d'avis : Dans any() : Nothing to summarize if you provide a single RasterLayer; see cellStats class : RasterLayer dimensions : 1261, 2136, 2693496 (nrow, ncol, ncell) resolution : 25, 25 (x, y) extent : 537762.5, 591162.5, 6430363, 6461888 (xmin, xmax, ymin, ymax) crs : +proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs source : memory names : layer values : NA, NA (min, max)

Message d'avis : Dans any() : Nothing to summarize if you provide a single RasterLayer; see cellStats Message d'avis : Dans max() : Nothing to summarize if you provide a single RasterLayer; see cellStats class : RasterLayer dimensions : 1261, 2136, 2693496 (nrow, ncol, ncell) resolution : 25, 25 (x, y) extent : 537762.5, 591162.5, 6430363, 6461888 (xmin, xmax, ymin, ymax) crs : +proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs source : memory names : layer values : 0, 0 (min, max)

[1] 16

Error in (function (cl, name, valueClass) : assignment of an object of class "logical" is not allowed for @'x' in an object of class "dgCMatrix"; is(value, "numeric") does not return TRUE Appels : movecost -> Anonymous Execution stopped"_

ThomasAndreArchgeo commented 1 week ago

Good evening,

After a few tries with the updated script, I think I've found the origin of the bug I've been experiencing (although I think it may have something to do with my computer). I tried to learn how to use R scripts on QGIS, and took the liberty of trying out different scenarios based on your code and what worked on RStudio. The problem was, in the end, linked to the raster, not the start and end points. There seemed to be a problem in accessing the file, or at least in transforming it. The Movecost module (the only one I tested) works again by modifying line 59 of the movecost.rsx file:

studyplot_sp <- raster(Area_of_interest) ==> studyplot_sp <- raster(Area_of_interest@file@name)

I don't really know what this changes in the call, but it seems to work once the modification has been made (again, only on Movecost as I haven't yet had time to test on the other functions).

Again, I don't know if it's specific to my computer, but I hope it can maybe help you. In any case, thank you again for your help and I'm sorry for the inconvenience. With my sincere appreciation,

Thomas ANDRE