Kaynağa Gözat

db.in.ogr: update manual
add example for XLS file


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54580 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 12 yıl önce
ebeveyn
işleme
99fef36dc4
2 değiştirilmiş dosya ile 46 ekleme ve 24 silme
  1. 40 19
      scripts/db.in.ogr/db.in.ogr.html
  2. 6 5
      scripts/db.in.ogr/db.in.ogr.py

+ 40 - 19
scripts/db.in.ogr/db.in.ogr.html

@@ -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.
-
-<h2>NOTES</h2>
-
+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>EXAMPLES</h2>
 
-Import of a CSV table file:<br>
+<h3>Import CSV file</h3>
+
 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>

+ 6 - 5
scripts/db.in.ogr/db.in.ogr.py

@@ -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 @@ def main():
 	    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 @@ def main():
 	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))