[GRASS-user] v.to.db

Hi all

I cannot understand why v.to.db needs a connected table on layer 1 to
upload values on table linked to layer 2; e.g.:

# # # spearfish60
g.copy vect=archsites,mypoints --o
v.category in=mypoints out=mypoints2 layer=2 opt=add --o
# # # remove connection from layer 1
v.db.connect -d mypoints2 layer=1
# # # remove table from layer 1
db.droptable mypoints2 -f
# # # create a table
echo "CREATE TABLE mypoints2_2 (cat integer, x double precision, y
double precision)" | db.execute
# # # connect table to layer 2
v.db.connect map=mypoints2 layer=2 key=cat table=mypoints2_2
# # # try v.to.db to upload some values to table on layer 2 without
table on layer 1
v.to.db mypoints2 layer=2 opt=cat col=cat
v.to.db mypoints2 layer=2 opt=coor col=x,y
# # # get an error:
# # # ERROR: Database connection not defined for layer 1. Use
v.db.connect first.

# # # no error if layer 1 is connected to table
# # # create a foo table on layer 1
v.db.addtable mypoints2 layer=1
# # # v.to.db upload correctly values to table on layer 2
v.to.db mypoints2 layer=2 opt=cat col=cat
v.to.db mypoints2 layer=2 opt=coor col=x,y

Are there any particular reasons for that?

ciao

--
--
Paolo C.
Lat. 44° 39' 11.08'' N Long. 7° 23' 25.26'' E

Hi Paolo,

I have tried your script:

On Tue, Jan 20, 2009 at 1:17 PM, Paolo Craveri <pcraveri@gmail.com> wrote:

Hi all

I cannot understand why v.to.db needs a connected table on layer 1 to
upload values on table linked to layer 2; e.g.:

# # # spearfish60
g.copy vect=archsites,mypoints --o
v.category in=mypoints out=mypoints2 layer=2 opt=add --o
# # # remove connection from layer 1
v.db.connect -d mypoints2 layer=1
# # # remove table from layer 1
db.droptable mypoints2 -f
# # # create a table
echo "CREATE TABLE mypoints2_2 (cat integer, x double precision, y double precision)" | db.execute

(note that there is v.db.addtable)

# # # connect table to layer 2
v.db.connect map=mypoints2 layer=2 key=cat table=mypoints2_2
# # # try v.to.db to upload some values to table on layer 2 without
table on layer 1
v.to.db mypoints2 layer=2 opt=cat col=cat
v.to.db mypoints2 layer=2 opt=coor col=x,y
# # # get an error:
# # # ERROR: Database connection not defined for layer 1. Use v.db.connect first.

Yes, I also get this and don't think that it is correct.

Looking at the code I see
http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/vector/v.to.db/main.c#L44
    Fi = Vect_get_field(&Map, options.field);

I added a local debug statement and found options.field==2 as you
defined via "layer=2".

Subsequently nothing is found since AFAIK the fields internally start
with 0, not one. I may be wrong though.

Anyone here having an idea?

The function is:
http://download.osgeo.org/grass/grass6_progman/field_8c-source.html#l00400
struct field_info *Vect_get_field(struct Map_info *Map, int field)

Markus

# # # no error if layer 1 is connected to table
# # # create a foo table on layer 1
v.db.addtable mypoints2 layer=1
# # # v.to.db upload correctly values to table on layer 2
v.to.db mypoints2 layer=2 opt=cat col=cat
v.to.db mypoints2 layer=2 opt=coor col=x,y

Are there any particular reasons for that?

ciao

--
--
Paolo C.
Lat. 44° 39' 11.08'' N Long. 7° 23' 25.26'' E

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
Open Source Geospatial Foundation
http://www.osgeo.org/
http://www.grassbook.org/

Hi,

2009/1/20 Markus Neteler <neteler@osgeo.org>:

[...]

Looking at the code I see
http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/vector/v.to.db/main.c#L44
   Fi = Vect_get_field(&Map, options.field);

I added a local debug statement and found options.field==2 as you
defined via "layer=2".

Subsequently nothing is found since AFAIK the fields internally start
with 0, not one. I may be wrong though.

no,

that's right for Vect_get_dblink() not for Vect_get_field() which
takes as argument layer number not layer index.

Anyone here having an idea?

The function is:
http://download.osgeo.org/grass/grass6_progman/field_8c-source.html#l00400
struct field_info *Vect_get_field(struct Map_info *Map, int field)

should be fixed in r35515.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi

2009/1/20 Martin Landa <landa.martin@gmail.com>:

Hi,

should be fixed in r35515.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

I have just updated grass6.4 from svn but error remains.

ciao

--
--
Paolo C.
Lat. 44° 39' 11.08'' N Long. 7° 23' 25.26'' E

(attachments)

vtodberror.txt (2.91 KB)

On Sun, Jan 25, 2009 at 3:07 PM, Paolo Craveri <pcraveri@gmail.com> wrote:

Hi

2009/1/20 Martin Landa <landa.martin@gmail.com>:

Hi,

should be fixed in r35515.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

I have just updated grass6.4 from svn but error remains.

Did you also recompile?

here it works now...:

... commands as in initial email.
...
db.droptable mypoints2 -f
Forcing ...
# # # create a table
echo "CREATE TABLE mypoints2_2 (cat integer, x double precision, y
double precision)" | db.execute
# # # connect table to layer 2

v.db.connect map=mypoints2 layer=2 key=cat table=mypoints2_2
The table <mypoints2_2> is now part of vector map <mypoints2> and may be
deleted or overwritten by GRASS modules
Select privileges were granted on the table

v.to.db mypoints2 layer=2 opt=cat col=cat
Reading features...
100%
Updating database...
100%
25 categories read from vector map (layer 2)
25 categories read from vector map don't exist in selection from table
25 records updated/inserted (layer 2)

v.to.db mypoints2 layer=2 opt=coor col=x,y
Reading features...
100%
Updating database...
100%
25 categories read from vector map (layer 2)
25 records selected from table (layer 1)
25 categories read from vector map exist in selection from table
25 records updated/inserted (layer 2)

No more error!

Markus

Hi

2009/1/25 Markus Neteler <neteler@osgeo.org>:

On Sun, Jan 25, 2009 at 3:07 PM, Paolo Craveri <pcraveri@gmail.com> wrote:

Hi

2009/1/20 Martin Landa <landa.martin@gmail.com>:

Hi,

should be fixed in r35515.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

I have just updated grass6.4 from svn but error remains.

Did you also recompile?

here it works now...:

I'm to blame. It works. Sorry, I was running an old version!

ciao
--
--
Paolo C.
Lat. 44° 39' 11.08'' N Long. 7° 23' 25.26'' E