Skip to content
Prev 7229 / 29559 Next

RPyGeo Query -- probably easy

Hi,

yes, the quotes are indeed tricky... The challenge is to provide the 
correct mix of escaped and un-escaped single and double quotes to Python 
/ ArcGIS as in this Python example:

gp.select_analysis("nfroads.shp", "paved.shp",
     ' "ROAD_CLASS" = \'PAVED\' ')

In order to achieve this, the backslashes in \' have to be escaped 
themselves, otherwise R will interpret them as escape symbols. After 
all, \' ends up being coded as \\\' in R. Also, double double-quotes 
have to be avoided; the quote.args argument of rpygeo.geoprocessor can 
be used to suppress the outermost double quotes, single quotes can be 
used explicitly instead: " ' sqlquery ' "

So here are two solutions:


env = rpygeo.build.env( workspace = "C:/TEMP",
               overwriteoutput = TRUE )

rpygeo.geoprocessor("select_analysis",
     list( "nfroads.shp", "paved.shp",
           " ' \"ROAD_CLASS\" = \\\'PAVED\\\' ' "),
     clean.up = FALSE, quote.args = c(T,T,F),
     env = env)


# alternative:

rpygeo.geoprocessor("select_analysis('nfroads.shp','paved.shp','\"ROAD_CLASS\"=\\\'PAVED\\\'')",
      env = env, clean.up = FALSE)


I hope this helps...

Cheers
  Alex
Maarten van Strien wrote: