[GRASS-SVN] r66310 - grass-addons/grass7/vector/v.in.redlist
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 23 12:16:53 PDT 2015
Author: hellik
Date: 2015-09-23 12:16:53 -0700 (Wed, 23 Sep 2015)
New Revision: 66310
Added:
grass-addons/grass7/vector/v.in.redlist/Makefile
grass-addons/grass7/vector/v.in.redlist/v.in.redlist.html
grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py
Log:
v.in.redlist: new addon script
Added: grass-addons/grass7/vector/v.in.redlist/Makefile
===================================================================
--- grass-addons/grass7/vector/v.in.redlist/Makefile (rev 0)
+++ grass-addons/grass7/vector/v.in.redlist/Makefile 2015-09-23 19:16:53 UTC (rev 66310)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.in.redlist
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass-addons/grass7/vector/v.in.redlist/v.in.redlist.html
===================================================================
--- grass-addons/grass7/vector/v.in.redlist/v.in.redlist.html (rev 0)
+++ grass-addons/grass7/vector/v.in.redlist/v.in.redlist.html 2015-09-23 19:16:53 UTC (rev 66310)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.in.redlist</em> imports <a href="http://www.iucn.org/">IUCN</a> <a href="http://www.iucnredlist.org/">Red List</a>
+<a href="http://www.iucnredlist.org/technical-documents/spatial-data">Spatial Data</a>.
+
+This data is by definition in WGS84 geographic coordinates.
+
+<p>
+ By the <i>-l</i> flag species in column 'binomial' of the attribute
+table are listed. The species in column 'binomial' can be exported to a
+text file by the <i>-s</i> flag.
+</p>
+
+<p>
+One of the species mentioned by <i>-l</i> or <i>-s</i> flag has to be specified for importing.
+</p>
+
+<h2>EXAMPLE</h2>
+
+<div class="code">
+ <pre>
+ # list species in column 'binomial' of the attribute table by -l flag
+ v.in.redlist -l input=C:\dl\iucn\GYMNOPHIONA\GYMNOPHIONA.shp
+
+ # export species in column 'binomial' of the attribute table into a text file by -s flag
+ v.in.redlist -s input=C:\dl\iucn\GYMNOPHIONA\GYMNOPHIONA.shp dir=C:\dl\iucn\GYMNOPHIONA
+
+ # import spatial data for a user defined species
+ v.in.redlist input=C:\dl\iucn\GYMNOPHIONA\GYMNOPHIONA.shp /
+ output=Scolecomorphus_vittatus species_name=Scolecomorphus vittatus
+ </pre>
+</div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.in.ogr.html">v.in.ogr</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Helmut Kudrnovsky
+
+<p>
+<i>Last changed: $Date: 2015-08-28 18:13:57 +0200 (Fr, 28 Aug 2015) $</i>
+</p>
\ No newline at end of file
Added: grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py
===================================================================
--- grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py (rev 0)
+++ grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py 2015-09-23 19:16:53 UTC (rev 66310)
@@ -0,0 +1,133 @@
+#!/usr/bin/env python
+
+"""
+MODULE: v.in.redlist
+
+AUTHOR(S): Helmut Kudrnovsky <alectoria AT gmx at>
+
+PURPOSE: Imports IUCN Red List Spatial Data
+
+COPYRIGHT: (C) 2015 by 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: importing of IUCN Red List Spatial Data
+#% keyword: vector
+#% keyword: geometry
+#%end
+
+#%option G_OPT_F_BIN_INPUT
+#% key: input
+#% description: name of the IUCN Red List Spatial Data shapefile
+#% required : yes
+#% guisection: GIS data
+#%end
+
+#%option G_OPT_V_OUTPUT
+#% key: output
+#% description: name of the imported IUCN Red List Spatial Data
+#% required : no
+#% guisection: GIS data
+#%end
+
+#%option
+#% key: species_name
+#% description: name of species which should be imported
+#% required : no
+#% guisection: GIS data
+#%end
+
+#%flag
+#% key: l
+#% description: list species in IUCN Red List Spatial Data
+#% guisection: listing
+#%end
+
+#%flag
+#% key: s
+#% description: save species list to a text file
+#% guisection: listing
+#%end
+
+#%option G_OPT_M_DIR
+#% key: dir
+#% description: Directory where the species list will be found
+#% required : no
+#% guisection: listing
+#%end
+
+import sys
+import os
+import grass.script as grass
+from osgeo import ogr
+
+if not os.environ.has_key("GISBASE"):
+ grass.message( "You must be in GRASS GIS to run this program." )
+ sys.exit(1)
+
+def main():
+
+
+ redlist_shapefile_long = options['input']
+ imported_species = options['species_name']
+ species_to_import = options['output']
+ imported_species_quoted = "'"+imported_species+"'"
+ directory = options['dir']
+ list_species = flags['l']
+ save_species = flags['s']
+ redlist_shapefile_short = os.path.basename(redlist_shapefile_long)
+ species_filename = redlist_shapefile_short.split('.')[0]
+ species_file = species_filename+'.txt'
+ global tmp
+
+ # save species list to a user defined directory
+
+ if save_species :
+
+ grass.message( "saving species list to a text file ..." )
+ output_species_file = os.path.join( directory, species_file )
+ # define ogr driver
+ driver = ogr.GetDriverByName("ESRI Shapefile")
+ # open data source
+ dataSource = driver.Open(redlist_shapefile_long, 0)
+ # get layer
+ layer = dataSource.GetLayer()
+ # open export file
+ f = open('%s' % (output_species_file), 'wb')
+ # write content of the attribute table column binomial
+ for feature in layer:
+ f.write('%s\n' % (feature.GetField("binomial")))
+ f.close()
+ grass.message( "%s" % (output_species_file) )
+
+ # print species list of the shapefile
+
+ elif list_species :
+
+ grass.message( "list species IUCN Red List Spatial Data ..." )
+ # define ogr driver
+ driver = ogr.GetDriverByName("ESRI Shapefile")
+ # open data source
+ dataSource = driver.Open(redlist_shapefile_long, 0)
+ # get layer
+ layer = dataSource.GetLayer()
+ for feature in layer:
+ grass.message( '%s' % (feature.GetField("binomial")))
+
+ # import spatial data for a user defined species in the Red List
+
+ else :
+
+ grass.message( " importing spatial data for %s ..." % (imported_species_quoted) )
+ grass.run_command( "v.in.ogr", input = redlist_shapefile_long,
+ output = species_to_import,
+ where = "binomial = %s" % (imported_species_quoted),
+ quiet = True)
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ sys.exit(main())
More information about the grass-commit
mailing list