Select to view content in your preferred language

Problem reading raster layer from custom R script tool

240
0
06-23-2022 03:07 PM
TannerChapman
New Contributor

I am using an R script to calculate an ecological metric known as interspersion and juxtaposition. I am creating this as a tool in Pro but when the input parameter that is a classified image is run from Pro in the script I am getting this error: 

Error in sample_lsm : no applicable method for 'landscape_as_list' applied to an object of class "character"


It seems for some reason the input layer of the classified image is being read as a character and not a raster when coming from Pro.

I can run the script successfully hardcoded outside of Pro using an exported raster as .img format.

I've attached a screenshot of the parameters I have set in the script tool and included my R script here.

tool_exec <- function(in_params, out_params){

library(raster)
library(landscapemetrics)
library(arcgisbinding)
library(gdalUtils)
library(sp)
library(sf)
library(dplyr)

arc.check_product()
arc.check_portal()

R1 <- in_params[[1]]
survey <- in_params[[2]]
csv <- out_params[[1]]

B<-arc.select(arc.open(survey))
x <-arc.shape(B)
geom <- arc.shape2sp(x)
points_sp <-geom


samples = dplyr ::bind_rows(
sample_lsm(R1, y= points_sp,
size = 150, #Set radius in meters
what =c("lsm_l_iji"),
shape = "circle"))

metrics <- rbind(samples)
print("csv appended")
write.csv(metrics, paste0("Interspersion.csv"))
print("Done")

0 Kudos
0 Replies