[GRASS-SVN] r66050 - grass-addons/grass7/vector/v.in.gbif
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 28 05:17:47 PDT 2015
Author: hellik
Date: 2015-08-28 05:17:47 -0700 (Fri, 28 Aug 2015)
New Revision: 66050
Modified:
grass-addons/grass7/vector/v.in.gbif/v.in.gbif.html
grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py
Log:
v.in.gbif: update addon to a more user friendly interface
Modified: grass-addons/grass7/vector/v.in.gbif/v.in.gbif.html
===================================================================
--- grass-addons/grass7/vector/v.in.gbif/v.in.gbif.html 2015-08-28 07:41:24 UTC (rev 66049)
+++ grass-addons/grass7/vector/v.in.gbif/v.in.gbif.html 2015-08-28 12:17:47 UTC (rev 66050)
@@ -9,10 +9,10 @@
</p>
<p>
-<em>v.in.gbif</em> saves the data to a <a href="http://www.gdal.org">GDAL</a>
+<em>v.in.gbif</em> saves the data to an intermediate <a href="http://www.gdal.org">GDAL</a>
<a href="http://www.gdal.org/drv_vrt.html">VRT - Virtual Datasource</a>
which will be imported by <a href="v.in.ogr.html">v.in.ogr</a>. The VRT data set
-can be used in any GDAL aware software.
+can be copied to a user defined directory by <i>-c</i> flag and used in any GDAL aware software.
As some column names in the original data set are similar to <a
href="http://www.postgresql.org/docs/devel/static/sql-keywords-appendix.html">SQL reserverd key words</a>,
@@ -23,8 +23,10 @@
<div class="code">
<pre>
- v.in.gbif vector= cat=40102 dir=C:\tmp distance=25
- v.in.gbif input=C:\data\0004248-150811131857512\0004248-150811131857512.csv output_vrt=chondrilla.vrt dir=C:\data\0004248-150811131857512\ output=chondrilla
+ v.in.gbif input=C:\data\0004248-150811131857512\0004248-150811131857512.csv output=chondrilla_12
+
+ # create GDAL VRT files based upon GBIF data in user defined directory by -c flag
+ v.in.gbif -c input=input=C:\data\0004248-150811131857512\0004248-150811131857512.csv output=chondrilla_13 dir=C:\data\0004248-150811131857512\
</pre>
</div>
Modified: grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py
===================================================================
--- grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py 2015-08-28 07:41:24 UTC (rev 66049)
+++ grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py 2015-08-28 12:17:47 UTC (rev 66050)
@@ -26,28 +26,32 @@
#% required: yes
#%end
-#%option G_OPT_F_OUTPUT
-#% key: output_vrt
-#% description: VRT file (with vrt extension)
-#% required: yes
+#%option G_OPT_V_OUTPUT
+#% key: output
+#% description: name of imported GBIF data set
+#% required : yes
#%end
+#%flag
+#% key: c
+#% description: Create GDAL VRT data set of GBIF data
+#% guisection: vrt
+#%end
+
#%option G_OPT_M_DIR
#% key: dir
#% description: Directory where the output will be found
-#% required : yes
+#% required : no
+#% guisection: vrt
#%end
-#%option G_OPT_V_OUTPUT
-#% key: output
-#% description: name of imported GBIF data set
-#% required : yes
-#%end
import sys
import os
import csv
import math
+import shutil
+import tempfile
import grass.script as grass
if not os.environ.has_key("GISBASE"):
@@ -66,11 +70,12 @@
grass.fatal(_("xy-locations are not supported"))
gbifraw = options['input']
+ gbifimported = options['output']
directory = options['dir']
- gbifvrt = options['output_vrt']
- gbifimported = options['output']
- gbif_vrt_layer = options['output_vrt'].split('.')[0]
- gbifcsv = gbif_vrt_layer+'.csv'
+ move_vrt_gbif_to_dir = flags['c']
+ gbifvrt = gbifimported+'.vrt'
+ gbif_vrt_layer = gbifimported
+ gbifcsv = gbifimported+'.csv'
global tmp
# Extract vector line
@@ -78,7 +83,8 @@
grass.message( "preparing data for vrt ..." )
# new quoted GBIF csv file
- new_gbif_csv = os.path.join( directory, gbifcsv )
+ gbiftempdir = tempfile.gettempdir()
+ new_gbif_csv = os.path.join( gbiftempdir, gbifcsv )
# quote raw data
with open('%s' % (gbifraw), 'rb') as csvinfile:
@@ -91,7 +97,7 @@
# write vrt
grass.message( "writing vrt ..." )
- new_gbif_vrt = os.path.join( directory, gbifvrt )
+ new_gbif_vrt = os.path.join( gbiftempdir, gbifvrt )
f = open('%s' % (new_gbif_vrt), 'wt')
f.write("""<OGRVRTDataSource>
@@ -153,8 +159,6 @@
grass.message( gbifvrt )
grass.message( "-" )
grass.message( gbifcsv )
- grass.message( "are saved in:" )
- grass.message( directory )
grass.message( "----" )
# import GBIF vrt
@@ -165,9 +169,31 @@
output = gbifimported,
quiet = True)
+
grass.message( "..." )
# v.in.gbif done!
- grass.message( "importing GBIF data done!" )
+ grass.message( "importing GBIF data done!" )
+ # move vrt and csv to user defined directory
+
+ if move_vrt_gbif_to_dir :
+
+ grass.message( "----" )
+ grass.message( "Create GBIF vrt data files ..." )
+ shutil.move(new_gbif_vrt, directory)
+ shutil.move(new_gbif_csv, directory)
+ grass.message( "in following user defined directory:" )
+ grass.message( directory )
+ grass.message( "----" )
+
+ else:
+
+ grass.message( "----")
+ grass.message("Some clean up ...")
+ os.remove("%s" % new_gbif_vrt)
+ os.remove("%s" % new_gbif_csv)
+ grass.message("Clean up done.")
+ grass.message( "----")
+
if __name__ == "__main__":
options, flags = grass.parser()
More information about the grass-commit
mailing list