[GRASS-user] Using db.out.ogr to export attributes to a csv file

Hi all,

I’m trying to use db.out.ogr to export an attributes table to a csv format for excel. I am using GRASS 7, but not sure what to put in the “dsn=” syntax.

This is the command I have used and the error that has appeared. Further when the file will be created, where can I find it?

db.out.ogr input=distance1 dsn=/home/dof1985/Grass_projects/Waste/Israel/CD-waste/sqlite/sqlite.db format=CSV table=shortest_distance
WARNING: 4695 line(s) found, but not requested to be exported. Verify ‘type’ parameter.
ERROR 1: It seems a file system object called
‘/home/dof1985/Grass_projects/Waste/Israel/CD-
waste/sqlite/sqlite.db’ already exists.
ERROR: Unable to open OGR data source ‘/home/dof1985/Grass_projects/Waste/Israel/CD-waste/sqlite/sqlite.db’
(Mon Apr 1 18:06:48 2013) Command finished (0 sec)

Thanks a lot

Dor

On Mon, Apr 1, 2013 at 5:08 PM, דור פרידמן <dof1985@gmail.com> wrote:

Hi all,

I'm trying to use db.out.ogr to export an attributes table to a csv format
for excel. I am using GRASS 7, but not sure what to put in the "dsn="
syntax.

The dsn parameter is the path + filename to the *output* file.

This is the command I have used and the error that has appeared. Further
when the file will be created, where can I find it?

db.out.ogr input=distance1
dsn=/home/dof1985/Grass_projects/Waste/Israel/CD-waste/sqlite/sqlite.db
format=CSV table=shortest_distance

Apparently you try to overwrite the internal GRASS database... better don't :slight_smile:

See the second example in the manual:
http://grass.osgeo.org/grass64/manuals/db.out.ogr.html

The dsn parameter should point to the output CSV file:

db.out.ogr input=distance1 dsn=/home/dof1985/shortest_distance.csv format=CSV

I agree that it is a bit confusing, since the db_table parameter should not
be used in this case (only if you write the output to a database system).

Essentially we follow the logic of GDAL/OGR here.

Since we are in GRASS 7 (where we may change parameters), I would not
mind to see a more intuitive solution here.

Dor, others: meanwhile manual improvements would be welcome (text
snippets to add to the manual).

Markus

Thanks Markus.

I’ve corrected my syntax, but have received a new error (it actually export an empty file: ‘nothing to export’), and the csv file is not being created.

That is my syntax:

GRASS 7.0.svn (Israel):~ > db.out.ogr input=allpairs1 dsn=/home/dof1985/Grass_projects/allpairs.csv format=CSV
WARNING: 20167 line(s) found, but not requested to be exported. Verify
‘type’ parameter.
Exported table </home/dof1985/Grass_projects/allpairs.csv.csv>

I have tried to export a map with two tables connected to it. Running v.db.tables -p, I can see that there names are: allpairs1_1 and allpairs_set10k. I would like to export both to either one or two csv files.

I have also attempted to export one table (allpairs1_1) to a distinct map and exporting it, yet have received the same error and there was no file creation.

Hope you could aid me with it,

Best,

Dor

···

2013/4/1 Markus Neteler <neteler@osgeo.org>

On Mon, Apr 1, 2013 at 5:08 PM, דור פרידמן <dof1985@gmail.com> wrote:

Hi all,

I’m trying to use db.out.ogr to export an attributes table to a csv format
for excel. I am using GRASS 7, but not sure what to put in the “dsn=”
syntax.

The dsn parameter is the path + filename to the output file.

This is the command I have used and the error that has appeared. Further
when the file will be created, where can I find it?

db.out.ogr input=distance1
dsn=/home/dof1985/Grass_projects/Waste/Israel/CD-waste/sqlite/sqlite.db
format=CSV table=shortest_distance

Apparently you try to overwrite the internal GRASS database… better don’t :slight_smile:

See the second example in the manual:
http://grass.osgeo.org/grass64/manuals/db.out.ogr.html

The dsn parameter should point to the output CSV file:

db.out.ogr input=distance1 dsn=/home/dof1985/shortest_distance.csv format=CSV

I agree that it is a bit confusing, since the db_table parameter should not
be used in this case (only if you write the output to a database system).

Essentially we follow the logic of GDAL/OGR here.

Since we are in GRASS 7 (where we may change parameters), I would not
mind to see a more intuitive solution here.

Dor, others: meanwhile manual improvements would be welcome (text
snippets to add to the manual).

Markus

WARNING: 20167 line(s) found, but not requested to be exported. Verify
        'type' parameter.

confirmed here, only the attributes of a point vector are exported by
db.out.ogr, but not the attributes of lines or areas.

please open a bug/enhancement in http://trac.osgeo.org/grass/

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Using-db-out-ogr-to-export-attributes-to-a-csv-file-tp5043917p5043951.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On Mon, Apr 1, 2013 at 6:10 PM, דור פרידמן <dof1985@gmail.com> wrote:

Thanks Markus.

I've corrected my syntax, but have received a new error (it actually export
an empty file: 'nothing to export'), and the csv file is not being created.

That is my syntax:

GRASS 7.0.svn (Israel):~ > db.out.ogr input=allpairs1
dsn=/home/dof1985/Grass_projects/allpairs.csv format=CSV
WARNING: 20167 line(s) found, but not requested to be exported. Verify
         'type' parameter.
Exported table </home/dof1985/Grass_projects/allpairs.csv.csv>

I have applied a fix in 6.4/6.5/7 SVN to db.out.ogr to also support attribute
export in case of line and area vectors.

I have tried to export a map with two tables connected to it. Running
v.db.tables -p, I can see that there names are: allpairs1_1 and
allpairs_set10k. I would like to export both to either one or two csv files.

In SVN (r55589) I have added support for multilayers. Please try. Hence it
would be now:

# to export table connected to vector map as layer 2:
db.out.ogr input=allpairs1 layer=2
dsn=/home/dof1985/Grass_projects/allpairs.csv format=CSV

Markus

On 01/04/13 17:38, Markus Neteler wrote:

Since we are in GRASS 7 (where we may change parameters), I would not
mind to see a more intuitive solution here.

For simple attribute export to csv, v.db.select with the file= parameter is a nice and simple solution.

Moritz

Hi Markus and Moritz,

I tried again to run db.out.ogr as follows, but it seems that it doesn’t support lines. Should I add something to the command? or update something in GRASS? I’ve also tried in another query to use layer in my syntax, yet it didn’t recognize it as a valid one. I apply the same question to this problem as well.

GRASS 7.0.svn (Israel):~ > db.out.ogr input=allpairs dsn=/home/dof1985/Grass_projects/allpairs format=CSV
WARNING: 11277 line(s) found, but not requested to be exported. Verify
‘type’ parameter.
Exported table </home/dof1985/Grass_projects/allpairs.csv>

I have also tried two other methods:

First, I tried using v.out.ogr to a csv format, but it snapped the roads in my map to several segments creating duplicates, thus total of 216,445 entries in the csv file, which is too many in any scale and hard to filter.

I have also tried Moritz suggestion with v.db.select. It was much convenient with only 1428 entries, though they were formed in one cell separated with |. Can I use that command to define for each column to be in a separated column of the csv?

Further more can you recommend of any function that will allow me to filter the exported attributes to the csv file, instead of using excel to do so?

Best,

Dor

···

2013/4/2 Moritz Lennert <mlennert@club.worldonline.be>

On 01/04/13 17:38, Markus Neteler wrote:

Since we are in GRASS 7 (where we may change parameters), I would not
mind to see a more intuitive solution here.

For simple attribute export to csv, v.db.select with the file= parameter is a nice and simple solution.

Moritz

Hi Dor,

On Tue, Apr 2, 2013 at 10:58 PM, דור פרידמן <dof1985@gmail.com> wrote:

Hi Markus and Moritz,

I tried again to run db.out.ogr as follows, but it seems that it doesn't
support lines. Should I add something to the command? or update something in
GRASS?

Yes, of course :slight_smile:
Since I updated it in SVN, you have to either fetch a precompiled binary (e.g.
an updated winGRASS is available by tomorrow) or update from SVN and
recompile (using "svn update"). I don't remember how you installed GRASS 7
at your end...

Markus

On 02/04/13 22:58, דור פרידמן wrote:

I have also tried Moritz suggestion with v.db.select. It was much
convenient with only 1428 entries, though they were formed in one cell
separated with |.

The | is the cell separator by default. So, it is not one "cell", but as many "cells" as there are columns in your attribute table. Just indicate | as the separator to the software you use to treat the data afterwards.

Can I use that command to define for each column to be
in a separated column of the csv?

Use the fs= parameter to define a different column separator than |.

Moritz