[GRASS-dev] OGR SQLite question

The db.out.ogr manual states for the input argument:

input=name [required]
GRASS table name
Or data source for direct OGR access

How do you specify the name of a table in the GRASS sqlite.db that is not linked to vector objects? I’d like to export the distance matrix table created with v.distance -a.

Thanks in advance
Michael


C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Head, Graduate Faculty in Complex Adaptive Systems Science
Arizona State University

voice: 480-965-6262 (SHESC), 480-965-8130/727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)

www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

On Sat, Jul 29, 2017 at 5:59 PM, Michael Barton <Michael.Barton@asu.edu> wrote:
[ ...]

I'd like to export the distance matrix table
created with v.distance -a.

You could redirect it to a file (of course a "file=" parameter would
be more elegant):

# test case, NC dataset
v.extract input=hospitals output=hospitals_test where="COUNTY='Swayne'
OR COUNTY = 'Watauga' OR COUNTY = 'Mecklenburg'"

# reduced dataset for test purpose
v.db.select hospitals_test -c | wc -l
13

# distance matrix, incl direct export to file
v.distance -pa from=hospitals_test to=hospitals_test upload=dist
separator=comma > matrix.csv

# verification:
cat matrix.csv
from_cat,to_cat,dist
,3,30,31,32,33,34,35,36,112,113,144,153,158
3,0,133276.42086464912,133041.35107619612,141872.64495940649,132555.12137443203,146710.29481383949,132452.46169504456,132808.38654187109,132674.02650356843,135717.81027315429,128054.31107769182,133073.02636643461,8321.7239556961049
30,133276.42086464912,0,566.10649525099063,14086.796281187319,938.12265075535947,13680.491183464996,1228.7359334346045,810.6623841657422,2198.585588861451,2465.1333840697835,13866.283103129103,1122.5705627816278,128211.04370485671
[...]

Best
Markus

On 29/07/17 17:59, Michael Barton wrote:

The db.out.ogr manual states for the input argument:

input=name [required]
GRASS table name
Or data source for direct OGR access

How do you specify the name of a table in the GRASS sqlite.db that is not linked to vector objects?

Probably the manual could do with an update to reflect the fact that it only works for existing maps. Maybe the input parameter should be renamed to 'map' ?

I'd like to export the distance matrix table created with v.distance -a.

Either do as Markus suggests (i.e. directly output the v.distance results to a file), or you can use db.select to extract the info you need:

db.select "select col1, col2, col3 from NameOfTable" output=YourDesiredOutputFile

Moritz

On Fri, Aug 4, 2017 at 11:51 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 29/07/17 17:59, Michael Barton wrote:

The db.out.ogr manual states for the input argument:

input=name [required]
GRASS table name
Or data source for direct OGR access

How do you specify the name of a table in the GRASS sqlite.db that is not
linked to vector objects?

Probably the manual could do with an update to reflect the fact that it only
works for existing maps. Maybe the input parameter should be renamed to
'map' ?

IMHO no - it refers to a *table*, not a map (the db.* commands have
generally no idea about maps but only about tables).

Markus

On 04/08/17 11:56, Markus Neteler wrote:

On Fri, Aug 4, 2017 at 11:51 AM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 29/07/17 17:59, Michael Barton wrote:

The db.out.ogr manual states for the input argument:

input=name [required]
GRASS table name
Or data source for direct OGR access

How do you specify the name of a table in the GRASS sqlite.db that is not
linked to vector objects?

Probably the manual could do with an update to reflect the fact that it only
works for existing maps. Maybe the input parameter should be renamed to
'map' ?

IMHO no - it refers to a *table*, not a map (the db.* commands have
generally no idea about maps but only about tables).

But internally, it uses v.out.ogr with input=input, and input in v.out.ogr is defined as

options->input = G_define_standard_option(G_OPT_V_INPUT);

So it is a map. This is why you get:

g.copy vect=schools_wake,schools
v.distance -a from=schools to=schools table=distances_between_schools up=cat,dist col=tocat,dist output=lines
db.out.ogr distances_between_schools output=distances_between_schools.csv
ERROR: Vector map <distances_between_schools> not found
ERROR: Module <v.out.ogr> failed

If we want to make db.out.ogr into a module to export any table to any ogr compatible formats, we would probably have to use ogr2ogr within the script (or the gdal python API).

I don't know how often people really need to transform tables into something else than csv files. Personally, I find db.select more than enough to move data from one database to another:

db.select table=distances_between_schools sep=, out=distances_between_schools.csv

(or with the sql parameter if you want to select specific columns only).

Moritz