[GRASS-SVN] r54580 - grass/trunk/scripts/db.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 8 07:58:00 PST 2013


Author: martinl
Date: 2013-01-08 07:57:56 -0800 (Tue, 08 Jan 2013)
New Revision: 54580

Modified:
   grass/trunk/scripts/db.in.ogr/db.in.ogr.html
   grass/trunk/scripts/db.in.ogr/db.in.ogr.py
Log:
db.in.ogr: update manual
	   add example for XLS file


Modified: grass/trunk/scripts/db.in.ogr/db.in.ogr.html
===================================================================
--- grass/trunk/scripts/db.in.ogr/db.in.ogr.html	2013-01-08 15:35:40 UTC (rev 54579)
+++ grass/trunk/scripts/db.in.ogr/db.in.ogr.html	2013-01-08 15:57:56 UTC (rev 54580)
@@ -1,52 +1,73 @@
 <h2>DESCRIPTION</h2>
 
 <em>db.in.ogr</em> imports attribute tables in various formats as
-supported by the OGR driver on the local system (DBF, CSV,
-PostgreSQL, SQLite, MySQL, ODBC, etc.). Optionally a unique key (ID)
-column can be added to the table.
+supported by the <a href="http://gdal.org/ogr">OGR library</a> on the local system (DBF, CSV, PostgreSQL,
+SQLite, MySQL, ODBC, etc.). Optionally a unique <b>key</b> (ID) column can be
+added to the table.
 
-<h2>NOTES</h2>
+<h2>EXAMPLES</h2>
 
+<h3>Import CSV file</h3>
 
-<h2>EXAMPLES</h2>
-
-Import of a CSV table file:<br>
 Limited type recognition can be done for Integer, Real, String, Date, Time and DateTime
 columns through a descriptive file with same name as the CSV file, but .csvt extension
 (see details <a href="http://www.gdal.org/ogr/drv_csv.html">here</a>).
-<p><div class="code"><pre>
+
+<div class="code"><pre>
 # NOTE: create koeppen_gridcode.csvt first for type recognition
 db.in.ogr dsn=koeppen_gridcode.csv output=koeppen_gridcode
 db.select koeppen_gridcode
 </pre></div>
 
-<p>Import of a DBF table with additional unique key column (e.g., needed for <em>v.in.db</em>):
-<p><div class="code"><pre>
-db.in.ogr dsn=$HOME/mydata.dbf output=census_raleigh key=myid
+<h3>Import DBF table</h3>
+
+Import of a DBF table with additional unique key column (e.g., needed
+for <em><a href="v.in.db.html">v.in.db</a></em>).
+
+<div class="code"><pre>
+db.in.ogr dsn=/path/to/mydata.dbf output=census_raleigh key=myid
 db.describe -c census_raleigh
 </pre></div>
 
-<p>Import of a SQLite table:
-<p><div class="code"><pre>
-db.in.ogr dsn=$HOME/sqlite/sqlite.db db_table=census_raleigh output=census_raleigh
+<h3>Import of a SQLite table</h3>
+
+<div class="code"><pre>
+db.in.ogr dsn=/path/to/sqlite.db db_table=census_raleigh output=census_raleigh
 </pre></div>
 
-<p>Import of a PostgreSQL table:
-<p><div class="code"><pre>
+<h3>Import of a PostgreSQL table</h3>
+
+<div class="code"><pre>
 db.in.ogr dsn="PG:host=localhost dbname=ecad user=neteler" \
           db_table=ecad_verona_tmean output=ecad_verona_tmean
 db.select ecad_verona_tmean
 db.describe -c ecad_verona_tmean
 </pre></div>
 
+<h3>Import XLS file</h3>
 
+To force reading headers, define environmental
+variable <tt>OGR_XLS_HEADERS='FORCE'</tt>. Parameter <b>db_table</b>
+refers to the list within XLS file.
+
+<div class="code"><pre>
+export OGR_XLS_HEADERS='FORCE'
+db.in.ogr dsn=address.xls db_table=address_data
+</pre></div>
+
 <h2>SEE ALSO</h2>
 
-<em><a href="v.in.ogr.html">v.in.ogr</a></em><br>
-<em><a href="sql.html">GRASS SQL interface</a></em>
+<em>
+  <a href="v.in.ogr.html">v.in.ogr</a>,
+  <a href="v.in.db.html">v.in.db</a>
+</em>
 
+<p>
+<a href="sql.html">GRASS SQL interface</a>
+
 <h2>AUTHOR</h2>
 
 Markus Neteler
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/db.in.ogr/db.in.ogr.py
===================================================================
--- grass/trunk/scripts/db.in.ogr/db.in.ogr.py	2013-01-08 15:35:40 UTC (rev 54579)
+++ grass/trunk/scripts/db.in.ogr/db.in.ogr.py	2013-01-08 15:57:56 UTC (rev 54580)
@@ -33,13 +33,14 @@
 #% key: db_table
 #% type: string
 #% key_desc : name
-#% description: Table name of SQL DB table
+#% description: Name of table from given DB to be imported
 #% required : no
 #%end
 
 #%option 
 #% key: output
 #% type: string
+#% key_desc : name
 #% description: Name for output table
 #% required : no
 #%end
@@ -92,9 +93,7 @@
 	    grass.fatal(_("Input table <%s> not found or not readable") % input)
 	else:
 	    grass.fatal(_("Input DSN <%s> not found or not readable") % input)
-
-    nuldev = file(os.devnull, 'w')
-
+    
     # rename ID col if requested from cat to new name
     if key:
 	grass.write_command('db.execute', quiet = True,
@@ -114,9 +113,11 @@
 	grass.run_command('g.remove', quiet = True, vect = output)
 
     # get rid of superfluous auto-added cat column (and cat_ if present)
+    nuldev = file(os.devnull, 'w+')
     grass.run_command('db.dropcolumn', quiet = True, flags = 'f', table = output,
 		      column = 'cat', stdout = nuldev, stderr = nuldev)
-
+    nuldev.close()
+    
     records = grass.db_describe(output)['nrows']
     grass.message(_("Imported table <%s> with %d rows") % (output, records))
 



More information about the grass-commit mailing list