[GRASS-user] v.extract features based on multiple SQL statements in one go

Nikos Alexandris nik at nikosalexandris.net
Tue Jun 4 14:31:25 PDT 2013


(not sure if this hit the list, my mailserver got stuck for a few 
hours... re-sending)

On Tuesday 04 of June 2013 15:06:47 Nikos Alexandris wrote:
> Nikos Alexandris wrote:
> > > # what is requested?
> > > cat 
/geo/geodata/mangroves/geolocations/sources/ascii/wrspr_of_interest2
> > > 
> > > SELECT * FROM wrs2_descending WHERE WRSPR = 160043 or WRSPR = 
161043 or
> > > WRSPR = 193056
> > > 
> > > # select it
> > > cat 
/geo/geodata/mangroves/geolocations/sources/ascii/wrspr_of_interest2
> > > |
> > > db.select input=-
> > > 
> > > cat|AREA|PERIMETER|PR_|PR_ID|RINGS_OK|RINGS_NOK|WRSPR|PR|PATH|
ROW|MODE|
> > > DAYCLASS|SEQUENCE
> > > 12071|2.82726|6.76119|2523|2523|1|0|160043|160043|160|43|D|7|
22611
> > > 24719|2.82726|6.76119|2523|2523|1|0|161043|161043|161|43|D|14|
47907
> > > 24980|2.59335|6.45272|3032|3032|1|0|193056|193056|193|56|D|14|
48416
> > > 
> > > Even so, I can't feed this to "v.extract" directly.
> 
> Moritz Lennert wrote:
> > How about a select that gets you all the cat values of the 
features your
> > interested in, then v.extract with list= (or put the cat values 
into a
> > file and use the file= parameter) ?

O-Κ, I ended up using the following

# get WRS2 pieces that contain points of interest
v.select --o ainput=wrs2_descending atype=area 
binput=points_of_interest 
btype=point output=wrs2_tiles_of_interest_testing operator=contains

# WRS2 tiles overlap, hence they are "split" in pieces in a 
topological format
# to get all pieces that compose a WRS2 tile, again
v.extract --o in=wrs2_descending output=wrs2_tiles_of_interest_testing 
cats=`v.db.select -c wrs2_tiles_of_interest_testing col=cat | sed 
':a;N;
$!ba;s/\n/,/g'`


Idea 1

Wouldn't it be useful for "v.select" and/or "v.overlay" and/or 
"v.extract" to, 
optionally, only return cat values of requested features (and not 
produce an 
output map at all)?  Meaybe there is something like that feasible with 
db.* 
modules (I didn't check yet).

Idea 2

What about having an option to produce the format that

	sed ':a;N;$!ba;s/\n/,/g'

does above, i.e., get the result of

	v.db.select -c wrs2_tiles_of_interest_testing col=cat | head

1167
1179
2782
2789
8240
8241
8242
8243
12071
15422

immediately formatted as

	v.db.select -c wrs2_tiles_of_interest_testing col=cat | head | sed 
':a;N;
$!ba;s/\n/,/g'

1167,1179,2782,2789,8240,8241,8242,8243,12071,15422

(
Maybe the "-v" flag in "v.db.select vs=comma" does exactly that, but 
it's 
broken currently.  Re-compiling tonight to test Martin's latest fix in 
r56593.
)

Thanks to all, Nikos


More information about the grass-user mailing list