[GRASS-CVS] markus: grass6/scripts/db.out.ogr description.html, NONE, 1.1 db.out.ogr, NONE, 1.1 Makefile, NONE, 1.1

grass at intevation.de grass at intevation.de
Tue Dec 4 08:54:12 EST 2007


Author: markus

Update of /grassrepository/grass6/scripts/db.out.ogr
In directory doto:/tmp/cvs-serv30820

Added Files:
	description.html db.out.ogr Makefile 
Log Message:
new table exporter

--- NEW FILE: description.html ---
<h2>DESCRIPTION</h2>

<em>db.out.ogr</em> exports GRASS attribute tables into various formats as
supported by the OGR driver on the local system (CSV, DBF,
PostgreSQL, SQLite, MySQL, ODBC, etc.).

<h2>EXAMPLES</h2>

Export of GRASS table to a DBF table (default format):
<p>
<div class="code"><pre>
db.out.ogr points_tab dsn=/tmp/points_tab.dbf
</pre></div>

<p>
Export of GRASS table to a CSV table file:<br>
<p>
<div class="code"><pre>
db.out.ogr points_tab dsn=points.csv format=CSV
</pre></div>

<p>
Export of GRASS table into a PostgreSQL table:
<p>
<div class="code"><pre>
db.out.ogr points_tab dsn="PG:host=localhost dbname=postgres user=neteler" format=PostgreSQL
echo "SELECT * FROM points_tab" | psql postgres
</pre></div>


<h2>SEE ALSO</h2>

<em><a href="sql.html">GRASS SQL interface</a></em>

<h2>AUTHOR</h2>

Markus Neteler

<p><i>Last changed: $Date: 2007/12/04 13:54:09 $</i>

--- NEW FILE: db.out.ogr ---
#!/bin/sh -x

############################################################################
#
# MODULE:       db.out.ogr
# AUTHOR(S):   	Markus Neteler
# PURPOSE:      exports attribute tables into various formats
# COPYRIGHT:    (C) 2007 by Markus Neteler and the GRASS Development Team
#
#               This program is free software under the GNU General Public
#               License (>=v2). Read the file COPYING that comes with GRASS
#               for details.
#
#############################################################################

#%Module
#%  description: Exports attribute tables into various formats.
#%  keywords: database, attribute table
#%End

#%option
#% key: input
#% type: string
#% key_desc : name
#% description: GRASS table name
#% required : yes
#%end

#%option
#% key: dsn
#% type: string
#% key_desc : name
#% gisprompt: new_file,file,input
#% description: Table file to be exported or DB connection string
#% required : yes
#%end

#%option
#% key: format
#% type: string
#% description: Table format
#% required : yes
#% options: CSV,DBF,GML,MySQL,PostgreSQL,SQLite
#% answer: DBF
#%end

#%option
#% key: db_table
#% type: string
#% key_desc : name
#% description: Name for output table
#% required : no
#%end


if  [ -z "$GISBASE" ] ; then
    echo "You must be in GRASS GIS to run this program." >&2
 exit 1
fi

if [ "$1" != "@ARGS_PARSED@" ] ; then
  exec g.parser "$0" "$@"
fi

PROG=`basename $0`

# setting environment, so that awk works properly in all languages
unset LC_ALL
LC_NUMERIC=C
export LC_NUMERIC


# what to do in case of user break:
exitprocedure()
{
 g.message -e 'User break!'
 exit 1
}
# shell check for user break (signal list: trap -l)
trap "exitprocedure" 2 3 15

### setup enviro vars ###
eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}

if [ "$GIS_OPT_FORMAT" = "DBF" -o  "$GIS_OPT_FORMAT" = "dbf" ] ; then
  GIS_OPT_FORMAT="ESRI_Shapefile"
fi

if [ "$GIS_OPT_FORMAT" = "CSV" ] ; then
  OLAYER="olayer=`basename $GIS_OPT_DSN .csv`"
fi

#is there a simpler way of testing for --overwrite?
if [ -e "$GIS_OPT_INPUT.dbf" ] ; then
   if [ -z "$GRASS_OVERWRITE" ] || [ "$GRASS_OVERWRITE" -ne 1 ] ; then
      g.message -e "File <$GIS_OPT_INPUT.dbf> already exists"
      exit 1
   fi
fi
  
v.out.ogr --q $GIS_OPT_INPUT dsn="$GIS_OPT_DSN" $OLAYER format=$GIS_OPT_FORMAT type=point
if [ $? -ne 0 ] ;  then
   exit 1
fi

if [ "$GIS_OPT_FORMAT" = "ESRI_Shapefile" ] ; then
  echo "$GIS_OPT_DSN" | grep '\.dbf$' > /dev/null
  if [ $? -eq 0 ] ; then
    OUTNAME="`basename $GIS_OPT_DSN .dbf`"
    rm -f $OUTNAME.shp
    rm -f $OUTNAME.shx
    rm -f $OUTNAME.prj
    OUTNAME="$OUTNAME.dbf"
  else
    rm -f $GIS_OPT_DSN/$GIS_OPT_INPUT.shp
    rm -f $GIS_OPT_DSN/$GIS_OPT_INPUT.shx
    rm -f $GIS_OPT_DSN/$GIS_OPT_INPUT.prj
    OUTNAME="$GIS_OPT_DSN/$GIS_OPT_INPUT.dbf"
  fi
else
  if [ "$GIS_OPT_FORMAT" = "CSV" ] ; then
     OUTNAME="$GIS_OPT_DSN".csv
  else
     OUTNAME="$GIS_OPT_INPUT"
  fi
fi

g.message "Exported table <$OUTNAME>"
exit 0


--- NEW FILE: Makefile ---
MODULE_TOPDIR = ../..

PGM = db.out.ogr

include $(MODULE_TOPDIR)/include/Make/Script.make

default: script




More information about the grass-commit mailing list