[R-sig-Geo] RPyGeo Query -- probably easy
brenning at uwaterloo.ca
Fri Dec 18 19:45:38 CET 2009
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:
' "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 )
list( "nfroads.shp", "paved.shp",
" ' \"ROAD_CLASS\" = \\\'PAVED\\\' ' "),
clean.up = FALSE, quote.args = c(T,T,F),
env = env)
env = env, clean.up = FALSE)
I hope this helps...
Maarten van Strien wrote:
> Andrew, thanks for your reply!
> I tried exactly your command, but still the resulting rpygeo.py file
> contains the following line:
> gp.select_analysis( "nfroads.shp", "paved.shp", "\"ROAD_CLASS\" = 'PAVED' "
> So the \"ROAD_CLASS\" = 'PAVED' is still surrounded by double quotes ("). I
> have tried many different Python commands, but the only one working for me
> gp.select_analysis( "nfroads.shp", "paved.shp", ' "ROAD_CLASS" = \'PAVED\' '
> Somehow I need to instruct RPyGeo to leave away the double quotes and
> replace them by single quotes.
> Kind regards, Maarten
> I'm not sure about the single quotes but possibly you could add an extra
> special character break (the \ ) to indicate to python that the double
> quotes surrounding your field name are not the end of a string. You could
> try the following code:
> rpygeo.geoprocessor("select_analysis", c("nfroads.shp", "paved.shp", '
> \\"ROAD_CLASS\\" = \'PAVED\' '), py.file= "rpygeo.py", working.directory =
> wrkspc, env = myenv, clean.up = FALSE)
> Best Regards
> Dr Andrew Crowe
> Lancaster Environment Centre
> Lancaster University
> Lancaster LA1 4YQ
brenning at uwaterloo.ca - T +1-519-888-4567 ext 35783
Department of Geography and Environmental Management
University of Waterloo
200 University Ave. W - Waterloo, ON - Canada N2L 3G1
More information about the R-sig-Geo