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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 30 06:47:47 EST 2007


Author: neteler
Date: 2007-12-30 06:47:46 -0500 (Sun, 30 Dec 2007)
New Revision: 29537

Modified:
   grass/trunk/scripts/db.in.ogr/db.in.ogr
   grass/trunk/scripts/db.in.ogr/description.html
Log:
new key parameter

Modified: grass/trunk/scripts/db.in.ogr/db.in.ogr
===================================================================
--- grass/trunk/scripts/db.in.ogr/db.in.ogr	2007-12-30 11:46:34 UTC (rev 29536)
+++ grass/trunk/scripts/db.in.ogr/db.in.ogr	2007-12-30 11:47:46 UTC (rev 29537)
@@ -42,7 +42,14 @@
 #% required : no
 #%end
 
+#%option
+#% key: key
+#% type: string
+#% description: Name for auto-generated unique key column
+#% required : no
+#%end
 
+
 if  [ -z "$GISBASE" ] ; then
     echo "You must be in GRASS GIS to run this program." >&2
  exit 1
@@ -101,8 +108,9 @@
   LAYER="layer=$GIS_OPT_DB_TABLE"
 fi
 
-WARNING=`v.in.ogr --q dsn="$GIS_OPT_DSN" $LAYER out=$GIS_OPT_OUTPUT -o 2>&1 | grep cat`
-if [ $? -ne 0 ] ;  then
+WARNING="`v.in.ogr --q dsn=\"$GIS_OPT_DSN\" $LAYER out=$GIS_OPT_OUTPUT -o 2>&1 | grep cat`"
+#if [ $? -ne 0 ] ;  then
+if [ ! -z "$WARNING" ] ; then
    if [ ! -z "$GIS_OPT_DB_TABLE" ] ; then
       g.message -e "Input DSN <$INPUT> not found or not readable"
    else
@@ -110,6 +118,12 @@
    fi
    exit 1
 fi
+
+# rename ID col if requested from cat to new name
+if [ ! -z ${GIS_OPT_KEY} ] ; then
+   v.db.renamecol --q $GIS_OPT_OUTPUT layer=1 column=cat,${GIS_OPT_KEY} 2> /dev/null > /dev/null
+fi
+
 # ... and immediately drop the empty geometry
 eval `g.findfile element=vector file=$GIS_OPT_OUTPUT mapset=$MAPSET`
 if [ ! "$file" ] ; then
@@ -121,11 +135,12 @@
 fi
 
 # get rid of superfluous auto-added cat column (and cat_ if present)
-db.dropcol --q -f $GIS_OPT_OUTPUT colum=cat >/dev/null 2>/dev/null 
+db.dropcol --q -f $GIS_OPT_OUTPUT colum=cat >/dev/null 2>/dev/null
 if [ ! -z "$WARNING" ] ; then
    db.dropcol --q -f $GIS_OPT_OUTPUT colum=cat_ >/dev/null 2>/dev/null
 fi
 
-g.message "Imported table <$GIS_OPT_OUTPUT>"
+RECORDS=`db.describe -c $GIS_OPT_OUTPUT | grep '^nrows' | sed 's+ ++g' | cut -d':' -f2`
+g.message "Imported table <$GIS_OPT_OUTPUT> with $RECORDS rows"
 exit 0
 

Modified: grass/trunk/scripts/db.in.ogr/description.html
===================================================================
--- grass/trunk/scripts/db.in.ogr/description.html	2007-12-30 11:46:34 UTC (rev 29536)
+++ grass/trunk/scripts/db.in.ogr/description.html	2007-12-30 11:47:46 UTC (rev 29537)
@@ -2,7 +2,8 @@
 
 <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.).
+PostgreSQL, SQLite, MySQL, ODBC, etc.). Optionally a unique key (ID)
+column can be added to the table.
 
 <h2>NOTES</h2>
 
@@ -16,15 +17,23 @@
 <p>
 <div class="code"><pre>
 # NOTE: create koeppen_gridcode.csvt first for type recognition
-db.in.ogr dsn=koeppen_gridcode.csv out=koeppen_gridcode
+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
+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 out=census_raleigh
+db.in.ogr dsn=$HOME/sqlite/sqlite.db db_table=census_raleigh output=census_raleigh
 </pre></div>
 
 <p>
@@ -32,7 +41,7 @@
 <p>
 <div class="code"><pre>
 db.in.ogr dsn="PG:host=localhost dbname=ecad user=neteler" \
-          db_table=ecad_verona_tmean out=ecad_verona_tmean
+          db_table=ecad_verona_tmean output=ecad_verona_tmean
 db.select ecad_verona_tmean
 db.describe -c ecad_verona_tmean
 </pre></div>



More information about the grass-commit mailing list