Last active
August 10, 2022 13:35
-
-
Save toebR/d0a4ad4ae7d793e2ed9d6252997707f3 to your computer and use it in GitHub Desktop.
Work with arcpy in Rmarkdown using reticulate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# work with arcpy in Rmarkdown or Rscript using reticulate | |
#set up python version in R | |
```{r} | |
library(reticulate) | |
use_python("C:/Python27/ArcGIS10.7/python.exe", required = TRUE) | |
``` | |
#check Sysinfo | |
```{python engine.path="C:/Python27/ArcGIS10.7/python.exe"} | |
import sys | |
print(sys.version) | |
``` | |
#example output of sys.version: | |
#Python 2.7.15 (C:/Python27/ArcGIS10.7/python.exe) | |
#Reticulate 1.18 REPL -- A Python interpreter in R. | |
#2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)] | |
# import arcpy and execute arcpy function --------------------------------- | |
```[python] | |
import arcpy | |
from arcpy import env | |
#set env settings | |
env.workspace = r"path\to\workspace" | |
#set local variables | |
inRaster = r"path\to\image.tif" | |
outPoint = r"path\to\result.shp" | |
field = "VALUE" | |
#execute RasterToPoint function from arcpymd | |
arcpy.RasterToPoint_conversion(inRaster, outPoint, field) | |
``` | |
# Sessioninfo ------------------------------------------------------------- | |
# R Version 4.0.4 (2021-02-15) | |
# Platform: i386-w64-mingw32/i386 (32-bit) | |
# Running under: Windows 10 x64 (build 19042) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment