<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem reading raster layer from custom R script tool in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/problem-reading-raster-layer-from-custom-r-script/m-p/1185803#M56490</link>
    <description>&lt;P&gt;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:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error in sample_lsm : no applicable method for 'landscape_as_list' applied to an object of class "character"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;I can run the script successfully hardcoded outside of Pro using an exported raster as .img format.&lt;/P&gt;&lt;P&gt;I've attached a screenshot of the parameters I have set in the script tool and included my R script here.&lt;/P&gt;&lt;P&gt;tool_exec &amp;lt;- function(in_params, out_params){&lt;BR /&gt;&lt;BR /&gt;library(raster)&lt;BR /&gt;library(landscapemetrics)&lt;BR /&gt;library(arcgisbinding)&lt;BR /&gt;library(gdalUtils)&lt;BR /&gt;library(sp)&lt;BR /&gt;library(sf)&lt;BR /&gt;library(dplyr)&lt;BR /&gt;&lt;BR /&gt;arc.check_product()&lt;BR /&gt;arc.check_portal()&lt;BR /&gt;&lt;BR /&gt;R1 &amp;lt;- in_params[[1]]&lt;BR /&gt;survey &amp;lt;- in_params[[2]]&lt;BR /&gt;csv &amp;lt;- out_params[[1]]&lt;BR /&gt;&lt;BR /&gt;B&amp;lt;-arc.select(arc.open(survey))&lt;BR /&gt;x &amp;lt;-arc.shape(B)&lt;BR /&gt;geom &amp;lt;- arc.shape2sp(x)&lt;BR /&gt;points_sp &amp;lt;-geom&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;samples = dplyr ::bind_rows(&lt;BR /&gt;sample_lsm(R1, y= points_sp,&lt;BR /&gt;size = 150, #Set radius in meters&lt;BR /&gt;what =c("lsm_l_iji"),&lt;BR /&gt;shape = "circle"))&lt;/P&gt;&lt;P&gt;metrics &amp;lt;- rbind(samples)&lt;BR /&gt;print("csv appended")&lt;BR /&gt;write.csv(metrics, paste0("Interspersion.csv"))&lt;BR /&gt;print("Done")&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 22:07:24 GMT</pubDate>
    <dc:creator>TannerChapman</dc:creator>
    <dc:date>2022-06-23T22:07:24Z</dc:date>
    <item>
      <title>Problem reading raster layer from custom R script tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/problem-reading-raster-layer-from-custom-r-script/m-p/1185803#M56490</link>
      <description>&lt;P&gt;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:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error in sample_lsm : no applicable method for 'landscape_as_list' applied to an object of class "character"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;I can run the script successfully hardcoded outside of Pro using an exported raster as .img format.&lt;/P&gt;&lt;P&gt;I've attached a screenshot of the parameters I have set in the script tool and included my R script here.&lt;/P&gt;&lt;P&gt;tool_exec &amp;lt;- function(in_params, out_params){&lt;BR /&gt;&lt;BR /&gt;library(raster)&lt;BR /&gt;library(landscapemetrics)&lt;BR /&gt;library(arcgisbinding)&lt;BR /&gt;library(gdalUtils)&lt;BR /&gt;library(sp)&lt;BR /&gt;library(sf)&lt;BR /&gt;library(dplyr)&lt;BR /&gt;&lt;BR /&gt;arc.check_product()&lt;BR /&gt;arc.check_portal()&lt;BR /&gt;&lt;BR /&gt;R1 &amp;lt;- in_params[[1]]&lt;BR /&gt;survey &amp;lt;- in_params[[2]]&lt;BR /&gt;csv &amp;lt;- out_params[[1]]&lt;BR /&gt;&lt;BR /&gt;B&amp;lt;-arc.select(arc.open(survey))&lt;BR /&gt;x &amp;lt;-arc.shape(B)&lt;BR /&gt;geom &amp;lt;- arc.shape2sp(x)&lt;BR /&gt;points_sp &amp;lt;-geom&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;samples = dplyr ::bind_rows(&lt;BR /&gt;sample_lsm(R1, y= points_sp,&lt;BR /&gt;size = 150, #Set radius in meters&lt;BR /&gt;what =c("lsm_l_iji"),&lt;BR /&gt;shape = "circle"))&lt;/P&gt;&lt;P&gt;metrics &amp;lt;- rbind(samples)&lt;BR /&gt;print("csv appended")&lt;BR /&gt;write.csv(metrics, paste0("Interspersion.csv"))&lt;BR /&gt;print("Done")&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 22:07:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/problem-reading-raster-layer-from-custom-r-script/m-p/1185803#M56490</guid>
      <dc:creator>TannerChapman</dc:creator>
      <dc:date>2022-06-23T22:07:24Z</dc:date>
    </item>
  </channel>
</rss>

