[GRASS-user] Import sqlite table using db.in.ogr

Hi,

I am trying to import a sqlite table to my current mapset database (sqlite). In a further step I want to join the imported table to an already existing attribute table in my mapset-specific sqlite database.

However I get an error that when I want to import the table. Here an example where I want to import the “streams” table from the PERMANENT mapset of the NC location (GRASS7):

db.in.ogr input=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db db_table=streams output=my_test
ERROR: Unable to open data source
ERROR: Input table not found or not readable

Here my setup:

GRASS version: 7.1.svn
GRASS SVN revision: 66919M
Build date: 2015-11-25
Build platform: i686-pc-linux-gnu
GDAL: 1.10.0
PROJ.4: 4.8.0
GEOS: 3.4.2
SQLite: 3.7.9
Python: 2.7.3
wxPython: 3.0.1.0
Platform: Linux-3.2.0-106-generic-pae-i686-with-Ubuntu-12.04-precise

Maybe I am missing something, or is that problem known and reproducible also for others?
Is there another recommended way to import (an join) a database table from an external sqlite database.

Best regards,
Johannes

On 03/08/16 12:35, Johannes Radinger wrote:

Hi,

I am trying to import a sqlite table to my current mapset database
(sqlite). In a further step I want to join the imported table to an
already existing attribute table in my mapset-specific sqlite database.

However I get an error that when I want to import the table. Here an
example where I want to import the "streams" table from the PERMANENT
mapset of the NC location (GRASS7):

db.in.ogr
input=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db
db_table=streams output=my_test
ERROR: Unable to open data source <streams>
ERROR: Input table <streams> not found or not readable

Are you sure that the database used is sqlite ?

I get:

v.db.connect -p streams
Vector map <streams> is connected by:
layer <1/streams> table <streams> in database </data/GRASS/DATA7/nc_spm_08/PERMANENT/dbf/> through driver <dbf> with key <cat>

Moritz

Hi,

note the differences:

On Wed, Aug 3, 2016 at 3:52 PM, Moritz Lennert <mlennert@club.worldonline.be

wrote:

On 03/08/16 12:35, Johannes Radinger wrote:

...
db.in.ogr

input=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db

--> nc_spm_08_grass7

v.db.connect -p streams
Vector map <streams> is connected by:
layer <1/streams> table <streams> in database
</data/GRASS/DATA7/nc_spm_08/PERMANENT/dbf/> through driver <dbf> with key
<cat>

--> nc_spm_08

The latter is for G6, not G7... just to avoid confusion.

Cheers
Markus

On 03/08/16 17:31, Markus Neteler wrote:

Hi,

note the differences:

On Wed, Aug 3, 2016 at 3:52 PM, Moritz Lennert
<mlennert@club.worldonline.be <mailto:mlennert@club.worldonline.be>> wrote:

    On 03/08/16 12:35, Johannes Radinger wrote:

        ...
        db.in.ogr
        input=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db

--> nc_spm_08_grass7

    v.db.connect -p streams
    Vector map <streams> is connected by:
    layer <1/streams> table <streams> in database
    </data/GRASS/DATA7/nc_spm_08/PERMANENT/dbf/> through driver <dbf>
    with key <cat>

--> nc_spm_08

The latter is for G6, not G7... just to avoid confusion.

Well, it's my set for GRASS7, but I guess somewhen way back in time I must have taken the GRASS6 version and run v.build.all in it to use it in GRASS7... :wink:

Anyhow, Johannes: what does 'v.db.connect -p streams' give you ?

Moritz

On Wed, Aug 3, 2016 at 5:42 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...

Well, it's my set for GRASS7, but I guess somewhen way back in time I must
have taken the GRASS6 version and run v.build.all in it to use it in
GRASS7... :wink:

(Yeah, but you also need to run
db.connect -d
and
v.db.reconnect.all -cd

see
https://grasswiki.osgeo.org/wiki/Convert_all_GRASS_6_vector_maps_to_GRASS_7 )

Anyway, let's wait for Johannes' answer.

Markus

Hi all,

the database is the original sqlite database the ships with the the NC grass7 location (nc_spm_08_grass7). I want to import a single table (e.g ‘streams’) from that NC grass7 database (source, sqlite) into my new location (target) using db.in.ogr. As far as I understand, for the module db.in.ogr the database scheme of the target location should not be of relevance?! Interestingly, the database scheme (either sqlite, dbf etc) of the source db/table is not explicitly specified in db.in.ogr?!

Have you tried to import e.g. the ‘streams’ table of the PERMANENT mapset of any NC grass7 sample location from within any other location?

Here the example from the manual:

db.in.ogr input=/path/to/sqlite.db db_table=census_raleigh output=census_raleigh

/Johannes

···

On Wed, Aug 3, 2016 at 5:51 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Wed, Aug 3, 2016 at 5:42 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

Well, it’s my set for GRASS7, but I guess somewhen way back in time I must
have taken the GRASS6 version and run v.build.all in it to use it in
GRASS7… :wink:

(Yeah, but you also need to run
db.connect -d
and
v.db.reconnect.all -cd

see
https://grasswiki.osgeo.org/wiki/Convert_all_GRASS_6_vector_maps_to_GRASS_7 )

Anyway, let’s wait for Johannes’ answer.

Markus

On Wed, Aug 3, 2016 at 11:04 PM, Johannes Radinger
<johannesradinger@gmail.com> wrote:

Hi all,

the database is the original sqlite database the ships with the the NC
grass7 location (nc_spm_08_grass7). I want to import a single table (e.g
'streams') from that NC grass7 database (source, sqlite) into my new
location (target) using db.in.ogr. As far as I understand, for the module
db.in.ogr the database scheme of the target location should not be of
relevance?! Interestingly, the database scheme (either sqlite, dbf etc) of
the source db/table is not explicitly specified in db.in.ogr?!

OGR recognizes the driver automatically.

Have you tried to import e.g. the 'streams' table of the PERMANENT mapset of
any NC grass7 sample location from within any other location?

Here the example from the manual:

db.in.ogr input=/path/to/sqlite.db db_table=census_raleigh
output=census_raleigh

this example can not work because input is replaced by db_table if
db_table is given. It seems that db.in.ogr works only with dbf and
only if input is the full path to the dbf file, db_table must not be
set. The fix would be easy: delete lines 74, 75 from db.in.ogr.py.

HTH,

Markus M

/Johannes

On Wed, Aug 3, 2016 at 5:51 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Wed, Aug 3, 2016 at 5:42 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...
> Well, it's my set for GRASS7, but I guess somewhen way back in time I
> must
> have taken the GRASS6 version and run v.build.all in it to use it in
> GRASS7... :wink:

(Yeah, but you also need to run
db.connect -d
and
v.db.reconnect.all -cd

see

https://grasswiki.osgeo.org/wiki/Convert_all_GRASS_6_vector_maps_to_GRASS_7
)

Anyway, let's wait for Johannes' answer.

Markus

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

On 03/08/16 23:04, Johannes Radinger wrote:

Hi all,

the database is the original sqlite database the ships with the the NC
grass7 location (nc_spm_08_grass7). I want to import a single table (e.g
'streams') from that NC grass7 database (source, sqlite) into my new
location (target) using db.in.ogr. As far as I understand, for the
module db.in.ogr the database scheme of the target location should not
be of relevance?! Interestingly, the database scheme (either sqlite, dbf
etc) of the source db/table is not explicitly specified in db.in.ogr?!

Well, it is specified implicitely in the input= parameter, and ogr automagically identifies the file type on its own.

The issue is not really with file type. In your original message you had this error:

db.in.ogr
input=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db
db_table=streams output=my_test
ERROR: Unable to open data source <streams>
ERROR: Input table <streams> not found or not readable

So, apparently there is no table streams in the sqlite.db you give in the input parameter. So I suggest to run

v.db.connect -p streams@PERMANENT to see which table this map is connected to.

You can also run

db.tables -p driver=sqlite database=/media/grassgis_data/GRASS_locations/nc_spm_08_grass7/PERMANENT/sqlite/sqlite.db

to see which tables are in that database.

Moritz

On 04/08/16 09:46, Markus Metz wrote:

On Wed, Aug 3, 2016 at 11:04 PM, Johannes Radinger
<johannesradinger@gmail.com> wrote:

Hi all,

the database is the original sqlite database the ships with the the NC
grass7 location (nc_spm_08_grass7). I want to import a single table (e.g
'streams') from that NC grass7 database (source, sqlite) into my new
location (target) using db.in.ogr. As far as I understand, for the module
db.in.ogr the database scheme of the target location should not be of
relevance?! Interestingly, the database scheme (either sqlite, dbf etc) of
the source db/table is not explicitly specified in db.in.ogr?!

OGR recognizes the driver automatically.

Have you tried to import e.g. the 'streams' table of the PERMANENT mapset of
any NC grass7 sample location from within any other location?

Here the example from the manual:

db.in.ogr input=/path/to/sqlite.db db_table=census_raleigh
output=census_raleigh

this example can not work because input is replaced by db_table if
db_table is given. It seems that db.in.ogr works only with dbf and
only if input is the full path to the dbf file, db_table must not be
set. The fix would be easy: delete lines 74, 75 from db.in.ogr.py.

Right (sorry, saw this message after sending the other).

Maybe the best would be to rename these parameters to:

database=
and
table=

where database could be a directory for file-based tables (e.g. dbf) ?

Just like the input/layer parameters in v.in.ogr.

Moritz