[GRASS-SVN] r29618 - grass/branches/releasebranch_6_3/scripts/db.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 8 09:00:16 EST 2008


Author: neteler
Date: 2008-01-08 09:00:16 -0500 (Tue, 08 Jan 2008)
New Revision: 29618

Modified:
   grass/branches/releasebranch_6_3/scripts/db.in.ogr/db.in.ogr
Log:
various bugfixes backported

Modified: grass/branches/releasebranch_6_3/scripts/db.in.ogr/db.in.ogr
===================================================================
--- grass/branches/releasebranch_6_3/scripts/db.in.ogr/db.in.ogr	2008-01-08 13:53:43 UTC (rev 29617)
+++ grass/branches/releasebranch_6_3/scripts/db.in.ogr/db.in.ogr	2008-01-08 14:00:16 UTC (rev 29618)
@@ -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,10 @@
   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
+# check ERRORs and cat and cat_ issues (maybe problem with translated messages)
+WARNING="`v.in.ogr --q dsn=\"$GIS_OPT_DSN\" $LAYER out=$GIS_OPT_OUTPUT -o 2>&1 | grep 'ERROR\|cat' | grep -v 'truncated'`"
+#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 +119,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 +136,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
 



More information about the grass-commit mailing list