[R-sig-Geo] execGRASS parsing problem
Roger Bivand
Roger.Bivand at nhh.no
Fri Apr 23 06:04:29 CEST 2010
On Thu, 22 Apr 2010, Paulo van Breugel wrote:
> Dear list,
>
> In my GRASS GIS database I have the vector map 'inmap', which is a
> vegetation map with different vegetation types defined in column 'VT'. I
> want to split the vector map according to the VT in different vector
> maps as part of a larger script. I wrote a small script following the
> steps described below:
There seems to be something odd about your use of Name= and VT=, perhaps?
Cross-platform quoting is always problematic. Had you considered using R
to subset the vector object if it isn't too large (example in spearfish):
library(spgrass6)
soils <- readVECT6("soils")
labs <- levels(soils$label)
clabs <- as.character(soils$label)
for (i in labs) {
cat(i, "\n")
writeVECT6(soils[clabs == i,], paste("soils", i, sep="_"))
}
or something similar. I have also added extra quote protection in doGRASS
- please check out the current CVS development source from sourceforge,
r-spatial, module spgrass6, with:
param <- list(input=inmap, output=namelist2[i],
where=paste("\"Name", "='", namelist1[i], "'\"", sep=""))
so that automatic quote protection of spaced strings is avoided by
providing the quotes manually, thus for all strings. This may not work
cross-platform - please test and report back.
Hope this helps,
Roger
>
> First I extract the values of the column VT into a character vector
> namelist1
>
> > namelist1:
> [1] "Acacia and allied vegetation"
> [2] "Alpine"
> [3] "Bamboo woodland and thicket"
> [4] "Bare land"
>
> Because I want to avoid spaces in the names of the resulting vector
> maps, I convert namelist1 into namelist2:
>
> > namelist2
> [1] "Acacia_and_allied_vegetation"
> [2] "Alpine"
> [3] "Bamboo_woodland_and_thicket"
> [4] "Bare_land"
>
> I am using these two as input for v.extract, using a loop (for this
> occassion using doGRASS instead of execGRASS):
>
> for(i in 1:length(namelist1){
> param <- list(input=inmap, output=namelist2[i],
> where=paste("Name","='",namelist1[i], "'",sep=""))
> flags <- c("d")
> doGRASS("v.extract", parameters=param, flags=flags)
> }
>
> For i=1, the following is send to GRASS:
> v.extract -d input=trapnel1 output=Acacia_and_allied_vegetation
> where=\"Name='Acacia and allied vegetation'\""
>
> For i=2, the following is send to GRASS:
> v.extract -d input=trapnel1 output=Alpine where=Name='Alpine'
>
> In the second example the argument for the second parameter 'where' is
> not surrounded by double quotation marks, resulting in an error in the
> execution of the command in GRASS. This always seems to happen when the
> argument consist of one string without spaces.
>
> For now I am running the same command via system call -
> system(paste("v.extract -d input='",inmap, "' output='", namelist3[i],
> "' where=\" VT='", namelist1[i], "'\"", sep="")) -, which works fine.
> However, I would like to know what/if I am doing something wrong here.
>
>
> Best regards
>
> Paulo
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list