Dear Roger

I hadn't thought about subsetting using R, good suggestion that will 
work for some of my maps. Unfortunately I am also working with vector 
maps that make my R choke. But your suggestion makes me wonder if it is 
not possible to do the subsetting directly in the attribute table in the 
SQLite database. I'll try that out and if it works I'll report back.

I'll test the new version in current CVS development source (probably 
after the weekend) and will report back.

Many thanks,

Paulo

p.s. the use of Name="VT='type1'" indeed seems odd, but it is the 
required syntax for v.extract (it is the WHERE part of a SQL statement).



On 04/23/2010 07:04 AM, Roger Bivand wrote:
> 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@stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to