[GRASS-dev] [grass-code R][506] v.what.rast should be able to
use other methods like bilinear
William A. Perkins
william.perkins at pnl.gov
Mon Oct 8 17:59:02 EDT 2007
Maciej,
>>>>> "Maciej" == Maciej Sieczka <tutey at o2.pl> writes:
Maciej> grass-dev at grass.itc.it wrote:
>> v.what.rast does what I need, but only with nearest
>> neighbor sampling. I could use v.sample, but that
>> creates a new map/table, and the only way to get the
>> attribute back to the original map is to use an SQL join,
Maciej> William,
Maciej> For a workaround, you can also link the output vector's
Maciej> datatable to another layer in the input vector; sth like:
Maciej> $ v.sample -b input=pts_in col=value out=pts_out rast=xxx
Maciej> $ v.db.connect map=pts_in driver=dbf table=pts_out layer=2
This is a very good idea. I will start doing this.
Maciej> BTW - anybody knows how to just copy a column from table to
Maciej> table? Or update an existing column in one column with the
Maciej> content of a column in another table? That's be the easiest
Maciej> workaround.
What I usually end up doing is temporarily connecting to a Postgres
database, for which this statement works (in your example):
UPDATE pts_in SET value = pts_out.rast_val
FROM pts_out
WHERE pts_in.cat = pts_out.cat;
However, I try to avoid keeping attributes in Postgres because I
access by GRASS databases from a variety of computers, some of which
do not have access to the Postgres server.
>> which is unsupported in dbf and sqlite databases.
Maciej> SQLite supports JOIN AFAICT. Does it fail in GRASS? Can you
Maciej> provide a test case?
The documentation says it's supported, and I have only been able to do
joins with SELECT, but not UPDATE. The way I read the SQLite
documentation, I should be able to do this:
UPDATE pts_in SET value = pts_out.rast_val WHERE pts_in.cat = pts_out.cat;
(sqlite does not allow a FROM clause in UPDATE). But I've never
gotten that to work. I worked up a little example for which I've
attached the output. I was working with today's CVS and on Mac OS X.
>> Furthermore, IMHO, v.rast.what should,
>> through options, do whatever v.sample does and v.sample
>> should be be eliminated.
Maciej> I have added the suggestion to GRASS 7 ideas on WIKI.
Thanks.
Maciej> Maciek
Bill
--
Bill Perkins
Pacific Northwest National Laboratory
Environmental Technologies Division, Hydrology Group
P.O. Box 999 MSIN K9-36
Richland, Washington, USA 99352
voice: (509) 372-6131 fax: (509) 372-6089 email: william.perkins at pnl.gov
-------------- next part --------------
GRASS 6.3.cvs > db.connect -p
driver:sqlite
database:$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db
schema:
group:
GRASS 6.3.cvs > cat junk.sql
drop table tmp1;
drop table tmp2;
create table tmp1 ( cat integer, num integer );
insert into tmp1 ( cat, num) values (1,1);
insert into tmp1 ( cat, num) values (2,2);
insert into tmp1 ( cat, num) values (3,3);
insert into tmp1 ( cat, num) values (4,4);
create table tmp2 ( cat integer, num integer );
insert into tmp2 ( cat, num) values (1,5);
insert into tmp2 ( cat, num) values (2,6);
insert into tmp2 ( cat, num) values (3,7);
insert into tmp2 ( cat, num) values (4,8);
GRASS 6.3.cvs > db.execute -i --v < ~/tmp/junk.sql
GRASS 6.3.cvs > echo 'select tmp1.cat, tmp1.num, tmp2.num from tmp1, tmp2 where tmp1.cat = tmp2.cat' | db.select output=',' vs=''
cat,num,num
1,1,5
2,2,6
3,3,7
4,4,8
GRASS 6.3.cvs > echo 'update tmp1 set num = tmp2.num where tmp1.cat = tmp2.cat' | db.execute
DBMI-SQLite driver error:
Error in sqlite3_prepare():
no such column: tmp2.num
ERROR: Error while executing: 'update tmp1 set num = tmp2.num where
tmp1.cat = tmp2.cat
'
GRASS 6.3.cvs > db.connect driver=pg database=template1
GRASS 6.3.cvs > db.connect -p
driver:pg
database:template1
schema:
group:
GRASS 6.3.cvs > db.execute -i --v < ~/tmp/junk.sql
DBMI-Postgres driver error:
Cannot execute:
drop table tmp1
ERROR: table "tmp1" does not exist
WARNING: Error while executing: 'drop table tmp1'
DBMI-Postgres driver error:
Cannot execute:
drop table tmp2
ERROR: table "tmp2" does not exist
WARNING: Error while executing: 'drop table tmp2'
GRASS 6.3.cvs > echo 'select tmp1.cat, tmp1.num, tmp2.num from tmp1, tmp2 where tmp1.cat = tmp2.cat' | db.select output=',' vs=''
cat,num,num
1,1,5
2,2,6
3,3,7
4,4,8
GRASS 6.3.cvs > echo 'update tmp1 set num = tmp2.num from tmp2 where tmp1.cat = tmp2.cat' | db.execute
GRASS 6.3.cvs > echo 'select tmp1.cat, tmp1.num, tmp2.num from tmp1, tmp2 where tmp1.cat = tmp2.cat' | db.select output=',' vs=''
cat,num,num
1,5,5
2,6,6
3,7,7
4,8,8
More information about the grass-dev
mailing list