[QGIS-Developer] Rscript load output into qgis from folder

Enzo Cocca enzo.ccc at gmail.com
Thu Jul 1 13:00:13 PDT 2021


hi,
just to inform you I solved the problem:

this works for me

......

r<-movecost(dtm=DTM, origin=Origin, destin=Destination, funct=Function,
time=Time, outp=Outp, move=Move, breaks=Breaks, return.base=TRUE,
cogn.slp=TRUE, sl.crit=Critical_Slope, W=Walker_Body_Weight,
L=Carried_Load_Weight, N=N, V=Speed, z=Zoom_Level, rb.lty=RL,
cont.lab=TRUE, destin.lab=TRUE, cex.breaks=CB, cex.lcp.lab=CLL,
oneplot=FALSE, export=FALSE)

raster.sp <- as(r$accumulated.cost.raster, "SpatialPixelsDataFrame")
Output_Accum_Cost_Surface=raster.sp

a1.sp<-as(r$isolines, "SpatialLinesDataFrame")
Output_Isoline=a1.sp

b1.sp<-as(r$LCPs, "SpatialLinesDataFrame")
Output_LCP=b1.sp

lback.sp<-as(r$LCPs.back, "SpatialLinesDataFrame")
Output_LCP_Back=lback.sp

dd.sp<-as(r$dest.loc.w.cost, "SpatialPointsDataFrame")
Output_W_Cost=dd.sp

Il giorno gio 1 lug 2021 alle ore 13:48 Enzo Cocca <enzo.ccc at gmail.com> ha
scritto:

> Hi again,
> At moment the solution I found it is this but is not very great.
>
> So I add two R packages more (GmAMisc to import raster and vector, and
> tkcl to print a message box)
>
> below the code:
>
> ##load_vector_using_rgdal
> ##load_raster_using_rgdal
> ##movecost script=group
> ##DTM=raster
> ##Origin=vector point
> ##Destination=vector point
> ##Movecost=name
> ##Move=number 8
> ##Breaks=number 0.5
> ##Function=selection
> t;tofp;mp;icmonp;icmoffp;icfonp;ug;alb;gkrs;r;ree;hrz;wcs;p;vl;ls;b;icfoffp
> ;
> ##Time=selection h;m ;
> ##Outp=selection r;c ;
> ##Return_Base=selection TRUE;FALSE ;
> ##Cognitive_Slope=selection FALSE;TRUE ;
> ##Critical_Slope=number 1
> ##Walker_Body_Weight=number 70
> ##Carried_Load_Weight=number 0
> ##N=number 1
> ##Speed=number 1
> ##Zoom_Level=number 9
> ##RL=number 2
> ##CL=selection  TRUE;FALSE ;
> ##DL=selection  TRUE;FALSE ;
> ##CB=number 0.6
> ##CLL=number 0.6
> ##Output=output folder
> ##Output_Isoline=output vector
> ##Output_LCP=output vector
> ##Output_Isoline=output vector
> ##Output_Cost_Surface=output raster
> ##Output_Accum_Cost_Surface=output raster
> ##showplots
> setwd(Output)
>
> library(tcltk)
> library(sp)
> library(movecost)
> library(GmAMisc)
> library(raster)
> library(rgdal)
> DTM<-raster(DTM)
> if(Function==0)
> Function=c("t")
> if(Function==1)
> Function=c("tofp")
> if(Function==2)
> Function=c("mp")
> if(Function==3)
> Function=c("icmonp")
> if(Function==4)
> Function=c("icmoffp")
> if(Function==5)
> Function=c("icfonp")
> if(Function==6)
> Function=c("ug")
> if(Function==7)
> Function=c("alb")
> if(Function==8)
> Function=c("gkrs")
> if(Function==9)
> Function=c("r")
> if(Function==10)
> Function=c("ree")
> if(Function==11)
> Function=c("hrz")
> if(Function==12)
> Function=c("wcs")
> if(Function==13)
> Function=c("p")
> if(Function==14)
> Function=c("vl")
> if(Function==15)
> Function=c("ls")
> if(Function==16)
> Function=c("b")
> if(Function==17)
> Function=c("icfoffp")
> if(Time==0)
> Time=c("h")
> if(Time==1)
> Time=c("m")
> if(Outp==0)
> Outp=c("r")
> if(Outp==1)
> Outp=c("c")
> if(Return_Base==0)
> Return_Base=c(TRUE)
> if(Return_Base==1)
> Return_Base=c(FALSE)
> if(Cognitive_Slope==0)
> Cognitive_Slopee=c(TRUE)
> if(Cognitive_Slope==1)
> Cognitive_Slope=c(FALSE)
>
> if(CL==0)
> CL=c(TRUE)
> if(CL==1)
> CL=c(FALSE)
>
> if(DL==0)
> DL=c(TRUE)
> if(DL==1)
> DL=c(FALSE)
> result<-movecost(dtm=DTM, origin=Origin, destin=Destination,
> funct=Function, time=Time, outp=Outp, move=Move,
> breaks=Breaks,return.base=Return_Base, cogn.slp=Cognitive_Slope,
> sl.crit=Critical_Slope,W=Walker_Body_Weight,L=Carried_Load_Weight,N=N,V=Speed,z=Zoom_Level,rb.lty=RL,cont.lab=CL,destin.lab=DL,cex.breaks=CB,cex.lcp.lab=CLL,
> export=TRUE)
>
> msgBox <- tkmessageBox(title = "Import Vector",
>                        message = "Import vector isolines .shp!", icon =
> "info", type = "ok")
> Output_Isoline=impShp()
> msgBox2 <- tkmessageBox(title = "Import Vector",
>                        message = "Import vector LCPs .shp!", icon =
> "info", type = "ok")
> Output_LCP=impShp()
> msgBox3 <- tkmessageBox(title = "Import Raster",
>                        message = "Import raster cost surface!", icon =
> "info", type = "ok")
> raster1<-impRst()
> raster1.sp <- as(raster1, "SpatialPixelsDataFrame") # Converting the
> RasterLayer object to a SpatialPixelsDataFrame object
> Output_Cost_Surface=raster1.sp
> msgBox4 <- tkmessageBox(title = "Import Raster",
>                        message = "Import raster accum cost surface !",
> icon = "info", type = "ok")
>
> raster2<-impRst()
> raster2.sp <- as(raster2, "SpatialPixelsDataFrame") # Converting the
> RasterLayer object to a SpatialPixelsDataFrame object
> Output_Accum_Cost_Surface=raster2.sp
>
> If some one has some tricks better, should very approciate.
>
> thanks
> E
>
> Il giorno gio 1 lug 2021 alle ore 11:07 Enzo Cocca <enzo.ccc at gmail.com>
> ha scritto:
>
>> Hi peoples,
>> I have a question:
>> In my r script I save (some raster and some vector file) in an a folder.
>> Is it a method to load my output into qgis?
>> I can't use output vector and output raster for some reason regarding the
>> R packages that I use.
>>
>> so this one is my script:
>>
>> ##load_vector_using_rgdal
>> ##load_raster_using_rgdal
>> ##movecost script=group
>> ##Movecost=name
>> ##DTM=raster
>> ##Origin=vector point
>> ##Destination=vector point
>> ##Move=number 8
>> ##Breaks=number 0.5
>> ##Function=selection
>> t;tofp;mp;icmonp;icmoffp;icfonp;ug;alb;gkrs;r;ree;hrz;wcs;p;vl;ls;b;icfoffp
>> ##Time=selection h;m
>> ##Outp=selection r;c
>> ##Return_Base=selection TRUE;FALSE
>> ##Cognitive_Slope=selection TRUE;FALSE
>> ##Critical_Slope=number 1
>> ##Walker_Body_Weight=number 70
>> ##Carried_Load_Weight=number 0
>> ##N=number 1
>> ##Speed=number 1
>> ##Zoom_Level=number 9
>> ##RL=number 2
>> ##CL=selection TRUE;FALSE
>> ##DL=selection TRUE;FALSE
>> ##CB=number 0.6
>> ##CLL=number 0.6
>> ##Output=output folder
>> ##showplots
>> setwd(Output)
>> library(sp)
>> library(movecost)
>> library(raster)
>> library(rgdal)
>> DTM<-raster(DTM)
>> if(Function==0)
>> Function=c("t")
>> if(Function==1)
>> Function=c("tofp")
>> if(Function==2)
>> Function=c("mp")
>> if(Function==3)
>> Function=c("icmonp")
>> if(Function==4)
>> Function=c("icmoffp")
>> if(Function==5)
>> Function=c("icfonp")
>> if(Function==6)
>> Function=c("ug")
>> if(Function==7)
>> Function=c("alb")
>> if(Function==8)
>> Function=c("gkrs")
>> if(Function==9)
>> Function=c("r")
>> if(Function==10)
>> Function=c("ree")
>> if(Function==11)
>> Function=c("hrz")
>> if(Function==12)
>> Function=c("wcs")
>> if(Function==13)
>> Function=c("p")
>> if(Function==14)
>> Function=c("vl")
>> if(Function==15)
>> Function=c("ls")
>> if(Function==16)
>> Function=c("b")
>> if(Function==17)
>> Function=c("icfoffp")
>> if(Time==0)
>> Time=c("h")
>> if(Time==1)
>> Time=c("m")
>> if(Outp==0)
>> Outp=c("r")
>> if(Outp==1)
>> Outp=c("c")
>> if(Return_Base==0)
>> Return_Base=c(TRUE)
>> if(Return_Base==1)
>> Return_Base=c(FALSE)
>> if(Cognitive_Slope==0)
>> Cognitive_Slopee=c(TRUE)
>> if(Cognitive_Slope==1)
>> Cognitive_Slope=c(FALSE)
>>
>> if(CL==0)
>> CL=c(TRUE)
>> if(CL==1)
>> CL=c(FALSE)
>>
>> if(DL==0)
>> DL=c(TRUE)
>> if(DL==1)
>> DL=c(FALSE)
>> result<-movecost(dtm=DTM, origin=Origin, destin=Destination,
>> funct=Function, time=Time, outp=Outp, move=Move,
>> breaks=Breaks,return.base=Return_Base, cogn.slp=Cognitive_Slope,
>> sl.crit=Critical_Slope,W=Walker_Body_Weight,L=Carried_Load_Weight,N=N,V=Speed,z=Zoom_Level,rb.lty=RL,cont.lab=CL,destin.lab=DL,cex.breaks=CB,cex.lcp.lab=CLL,
>> export=TRUE)
>>
>> thanks in advance
>>
>> E
>>
>>
>>
>> --
>> Enzo Cocca PhD
>> in "Science and Technology for Archaeology and Cultural Heritage"
>>
>> ISMEO
>> International Association of Mediterranean and Oriental Studies
>>
>>
>> mail: enzo.ccc at gmail.com
>> cell: +393495087014
>>
>>
>
> --
> Enzo Cocca PhD
> in "Science and Technology for Archaeology and Cultural Heritage"
>
> ISMEO
> International Association of Mediterranean and Oriental Studies
>
>
> mail: enzo.ccc at gmail.com
> cell: +393495087014
>
>

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

ISMEO
International Association of Mediterranean and Oriental Studies


mail: enzo.ccc at gmail.com
cell: +393495087014
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210701/039b4133/attachment-0001.html>


More information about the QGIS-Developer mailing list