[R-sig-Geo] RPyGeo Importing and running user generated Toolboxes

Alexander Brenning brenning at uwaterloo.ca
Wed May 23 15:50:56 CEST 2012


Hello,

the problem seems to be that each rpygeo.geoprocessor call starts from scratch, i.e. each call has to set its environment (Extent, OverwriteOutput etc), check out any required extensions (e.g., Spatial Analyst, if needed), and apparently also import any required user-defined toolboxes.

This means that in your case the following line of Python code would have to be added to the Python script generated by your second rpygeo.geoprocessor call:

gp.ImportToolbox( "C:/landscape_genetics/Landscape_genetics.tbx", "landgen" )

I'm afraid you will have to tweak rpygeo.geoprocessor to accomplish this, i.e. define a function my.rpygeo.geoprocessor with additional argument
   custom.code = NULL
and add the following additional R code right before expr = paste(expr, "rpygeoresult = \"\"", "\n", sep = "")

  if (!is.null(custom.code))
    expr = paste(expr, custom.code, "\n", sep = "")

Then call this modified function with your custom.code argument:

my.rpygeo.geoprocessor("EucDistanceMatrix_landgen", c("sites", "FID",
"C:/data/output/", "euclidean.txt"), env=rpygeo.env, 
 custom.code = "gp.ImportToolbox( "C:/landscape_genetics/Landscape_genetics.tbx", "landgen" )")

I'm not sure about the forward slashes in custom.code, I believe both forward slashes and double backslashes may work.
Additional modifications would be needed to handle possible error messages from the custom.code call...

I haven't tested this proposed solution but I hope this will help.

Best,
  Alex



Date: Tue, 22 May 2012 17:00:59 -0400
From: Robby Marrotte <robbymarrotte at gmail.com>
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] RPyGeo Importing and running user generated
        Toolboxes

Hello everyone,

I spend the day learning how to use rpygeo and I learned how to use most
ArcGIS 10 function in R via the "rpygeo.processor" command. However, I
wanted to run a toolbox that I use almost constantly called landscape
genetic, you can find it
here<http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=CD84455E-1422-2418-348A-13F051488BD3>,
I used the following command to import the toolbox:

# Set wd
rpygeo.env<-rpygeo.build.env(python.path="C:/Python26/ArcGIS10.0",python.command="python.exe",
                             workspace="C:/data/input/", extent =
"C:/data/input/bound.shp", overwriteoutput = 1, cellsize=100)

# Import landgen toolbox
rpygeo.geoprocessor("ImportToolbox",
c("C:/landscape_genetics/Landscape_genetics.tbx", "landgen"),
env=rpygeo.env)

All it tells me now is Null, meaning that nothing bad or good happen I
guess... Now if I run one of the modules called Euclidean Distance Matrix:

rpygeo.geoprocessor("EucDistanceMatrix_landgen", c("sites", "FID",
"C:/data/output/", "euclidean.txt"), env=rpygeo.env)

It seems like it tries to run but I dont get any error message or anything
in my output folder. Has anybody tried importing a toolbox yet?

Thanks


_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo




More information about the R-sig-Geo mailing list