[GRASS-SVN] r73969 - in grass-addons/grass7/vector: v.area.weigh v.class.ml v.colors2 v.concave.hull v.convert.all v.faultdirections v.in.gbif v.in.gps v.in.natura2000 v.in.pygbif v.in.redlist v.median v.out.gps v.ply.rectify v.sort.points
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 17 13:46:42 PST 2019
Author: neteler
Date: 2019-01-17 13:46:42 -0800 (Thu, 17 Jan 2019)
New Revision: 73969
Modified:
grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py
grass-addons/grass7/vector/v.class.ml/v.class.ml.py
grass-addons/grass7/vector/v.colors2/v.colors2.py
grass-addons/grass7/vector/v.concave.hull/v.concave.hull.py
grass-addons/grass7/vector/v.convert.all/v.convert.all.py
grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py
grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py
grass-addons/grass7/vector/v.in.gps/v.in.gps.py
grass-addons/grass7/vector/v.in.natura2000/v.in.natura2000.py
grass-addons/grass7/vector/v.in.pygbif/v.in.pygbif.py
grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py
grass-addons/grass7/vector/v.median/v.median.py
grass-addons/grass7/vector/v.out.gps/v.out.gps.py
grass-addons/grass7/vector/v.ply.rectify/v.ply.rectify.py
grass-addons/grass7/vector/v.sort.points/v.sort.points.py
Log:
vector addons: fix tab/space indentation mess; tabs are to be avoided, see https://trac.osgeo.org/grass/wiki/Submitting/Python?version=19#Editorsettingsfor4-spaceindentation
Modified: grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py
===================================================================
--- grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -2,14 +2,14 @@
############################################################################
#
-# MODULE: v.area.weigh
-# AUTHOR(S): Markus Metz
-# PURPOSE: Rasterize vector areas using cell weights
-# COPYRIGHT: (C) 2013 by the GRASS Development Team
+# MODULE: v.area.weigh
+# AUTHOR(S): Markus Metz
+# PURPOSE: Rasterize vector areas using cell weights
+# COPYRIGHT: (C) 2013 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.
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
#
#############################################################################
@@ -43,11 +43,11 @@
def cleanup():
if rastertmp1:
- grass.run_command('g.remove', flags='f', type='raster', name= rastertmp1, quiet = True)
+ grass.run_command('g.remove', flags='f', type='raster', name= rastertmp1, quiet = True)
if rastertmp2:
- grass.run_command('g.remove', flags='f', type='raster', name= rastertmp2, quiet = True)
+ grass.run_command('g.remove', flags='f', type='raster', name= rastertmp2, quiet = True)
if rastertmp3:
- grass.run_command('g.remove', flags='f', type='raster', name= rastertmp3, quiet = True)
+ grass.run_command('g.remove', flags='f', type='raster', name= rastertmp3, quiet = True)
def main():
global tmp, tmpname, rastertmp1, rastertmp2, rastertmp3
@@ -69,22 +69,22 @@
# vector exists?
result = grass.find_file(vector, element='vector')
if len(result['name']) == 0:
- grass.fatal(_("Input vector <%s> not found") % vector)
+ grass.fatal(_("Input vector <%s> not found") % vector)
# raster exists?
result = grass.find_file(weight, element='cell')
if len(result['name']) == 0:
- grass.fatal(_("Input weight raster <%s> not found") % weight)
+ grass.fatal(_("Input weight raster <%s> not found") % weight)
# column exists ?
if column not in grass.vector_columns(vector, layer).keys():
- grass.fatal(_("Column does not exist for vector <%s>, layer %s") % (vector, layer))
+ grass.fatal(_("Column does not exist for vector <%s>, layer %s") % (vector, layer))
# is column numeric?
coltype = grass.vector_columns(vector, layer)[column]['type']
if coltype not in ('INTEGER', 'DOUBLE PRECISION'):
- grass.fatal(_("Column must be numeric"))
+ grass.fatal(_("Column must be numeric"))
# rasterize with cats (will be base layer)
# strip off mapset for tmp output
@@ -118,9 +118,9 @@
grass.mapcalc(exp,
output = output,
- sumweight = rastertmp3,
- area_val = rastertmp2,
- weight = weight)
+ sumweight = rastertmp3,
+ area_val = rastertmp2,
+ weight = weight)
sys.exit(0)
Modified: grass-addons/grass7/vector/v.class.ml/v.class.ml.py
===================================================================
--- grass-addons/grass7/vector/v.class.ml/v.class.ml.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.class.ml/v.class.ml.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -3,15 +3,15 @@
#
############################################################################
#
-# MODULE: v.class.ml
+# MODULE: v.class.ml
#
# AUTHOR(S): Pietro Zambelli (University of Trento)
#
-# COPYRIGHT: (C) 2013 by the GRASS Development Team
+# COPYRIGHT: (C) 2013 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.
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
#
#############################################################################
@@ -705,7 +705,7 @@
import pickle
with open('classification_results.pkl', 'w') as res:
- pickle.dump(classifiers, res)
+ pickle.dump(classifiers, res)
#classifiers = pickle.load(res)
msgr.message("Export the results to layer: <%s>" % str(rlayer))
export_results(vect, classifiers, cats, rlayer, vtraining, tcols,
Modified: grass-addons/grass7/vector/v.colors2/v.colors2.py
===================================================================
--- grass-addons/grass7/vector/v.colors2/v.colors2.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.colors2/v.colors2.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -6,7 +6,7 @@
# New Zealand
# Converted to Python by Glynn Clements
# PURPOSE: Populate a GRASSRGB column with a color map and data column
-# Helper script for thematic mapping tasks
+# Helper script for thematic mapping tasks
#
# COPYRIGHT: (c) 2008, 2010-2011 Hamish Bowman, and the GRASS Development Team
# This program is free software under the GNU General Public
@@ -90,11 +90,11 @@
def cleanup():
if tmp:
- grass.try_remove(tmp)
+ grass.try_remove(tmp)
if tmp_vcol:
- grass.try_remove(tmp_vcol)
+ grass.try_remove(tmp_vcol)
if tmp_colr:
- grass.run_command('g.remove', flags='f', type='raster', name= tmp_colr, quiet = True)
+ grass.run_command('g.remove', flags='f', type='raster', name= tmp_colr, quiet = True)
def main():
color = options['color']
@@ -117,36 +117,36 @@
# does map exist in CURRENT mapset?
kv = grass.find_file(map, element = 'vector', mapset = mapset)
if not kv['file']:
- grass.fatal(_("Vector map <%s> not found in current mapset") % map)
+ grass.fatal(_("Vector map <%s> not found in current mapset") % map)
vector = map.split('@', 1)
# sanity check mutually exclusive color options
if not options['color'] and not options['raster'] and not options['rules']:
- grass.fatal(_("Pick one of color, rules, or raster options"))
+ grass.fatal(_("Pick one of color, rules, or raster options"))
if color:
- #### check the color rule is valid
- color_opts = os.listdir(os.path.join(gisbase, 'etc', 'colors'))
- color_opts += ['random', 'grey.eq', 'grey.log', 'rules']
- if color not in color_opts:
- grass.fatal(_("Invalid color rule <%s>\n") % color +
- _("Valid options are: %s") % ' '.join(color_opts))
+ #### check the color rule is valid
+ color_opts = os.listdir(os.path.join(gisbase, 'etc', 'colors'))
+ color_opts += ['random', 'grey.eq', 'grey.log', 'rules']
+ if color not in color_opts:
+ grass.fatal(_("Invalid color rule <%s>\n") % color +
+ _("Valid options are: %s") % ' '.join(color_opts))
elif raster:
- if not grass.find_file(raster)['name']:
- grass.fatal(_("Raster raster map <%s> not found") % raster)
+ if not grass.find_file(raster)['name']:
+ grass.fatal(_("Raster raster map <%s> not found") % raster)
elif rules:
- if not os.access(rules, os.R_OK):
- grass.fatal(_("Unable to read color rules file <%s>") % rules)
+ if not os.access(rules, os.R_OK):
+ grass.fatal(_("Unable to read color rules file <%s>") % rules)
# column checks
# check input data column
cols = grass.vector_columns(map, layer = layer)
if column not in cols:
- grass.fatal(_("Column <%s> not found") % column)
+ grass.fatal(_("Column <%s> not found") % column)
ncolumn_type = cols[column]['type']
if ncolumn_type not in ["INTEGER", "DOUBLE PRECISION"]:
- grass.fatal(_("Column <%s> is not numeric but %s") % (column, ncolumn_type))
+ grass.fatal(_("Column <%s> is not numeric but %s") % (column, ncolumn_type))
# check if GRASSRGB column exists, make it if it doesn't
table = grass.vector_db(map)[int(layer)]['table']
@@ -158,23 +158,23 @@
except CalledModuleError:
grass.fatal(_("Creating color column"))
else:
- column_type = cols[rgb_column]['type']
- if column_type not in ["CHARACTER", "TEXT"]:
- grass.fatal(_("Column <%s> is not of compatible type (found %s)") % (rgb_column, column_type))
- else:
- num_chars = dict([(v[0], int(v[2])) for v in grass.db_describe(table)['cols']])[rgb_column]
- if num_chars < 11:
- grass.fatal(_("Color column <%s> is not wide enough (needs 11 characters)"), rgb_column)
+ column_type = cols[rgb_column]['type']
+ if column_type not in ["CHARACTER", "TEXT"]:
+ grass.fatal(_("Column <%s> is not of compatible type (found %s)") % (rgb_column, column_type))
+ else:
+ num_chars = dict([(v[0], int(v[2])) for v in grass.db_describe(table)['cols']])[rgb_column]
+ if num_chars < 11:
+ grass.fatal(_("Color column <%s> is not wide enough (needs 11 characters)"), rgb_column)
cvals = grass.vector_db_select(map, layer = int(layer), columns = column)['values'].values()
# find data range
if range:
- # order doesn't matter
- vals = range.split(',')
+ # order doesn't matter
+ vals = range.split(',')
else:
- grass.message(_("Scanning values..."))
- vals = [float(x[0]) for x in cvals]
+ grass.message(_("Scanning values..."))
+ vals = [float(x[0]) for x in cvals]
minval = min(vals)
maxval = max(vals)
@@ -181,7 +181,7 @@
grass.verbose(_("Range: [%s, %s]") % (minval, maxval))
if minval is None or maxval is None:
- grass.fatal(_("Scanning data range"))
+ grass.fatal(_("Scanning data range"))
# setup internal region
grass.use_temp_region()
@@ -191,23 +191,23 @@
# create dummy raster map
if ncolumn_type == "INTEGER":
- grass.mapcalc("$tmp_colr = int(if(row() == 1, $minval, $maxval))",
- tmp_colr = tmp_colr, minval = minval, maxval = maxval)
+ grass.mapcalc("$tmp_colr = int(if(row() == 1, $minval, $maxval))",
+ tmp_colr = tmp_colr, minval = minval, maxval = maxval)
else:
- grass.mapcalc("$tmp_colr = double(if(row() == 1, $minval, $maxval))",
- tmp_colr = tmp_colr, minval = minval, maxval = maxval)
+ grass.mapcalc("$tmp_colr = double(if(row() == 1, $minval, $maxval))",
+ tmp_colr = tmp_colr, minval = minval, maxval = maxval)
if color:
- color_cmd = {'color': color}
+ color_cmd = {'color': color}
elif raster:
- color_cmd = {'raster': raster}
+ color_cmd = {'raster': raster}
elif rules:
- color_cmd = {'rules': rules}
+ color_cmd = {'rules': rules}
if flip:
- flip_flag = 'n'
+ flip_flag = 'n'
else:
- flip_flag = ''
+ flip_flag = ''
grass.run_command('r.colors', map = tmp_colr, flags = flip_flag, quiet = True, **color_cmd)
@@ -220,9 +220,9 @@
p = grass.feed_command('r.what.color', flags = 'i', input = tmp_colr, stdout = f)
lastval = None
for v in sorted(vals):
- if v == lastval:
- continue
- p.stdin.write('%f\n' % v)
+ if v == lastval:
+ continue
+ p.stdin.write('%f\n' % v)
p.stdin.close()
p.wait()
f.close()
@@ -233,17 +233,17 @@
t = string.Template("UPDATE $table SET $rgb_column = '$colr' WHERE $column = $value;\n")
found = 0
for line in fi:
- [value, colr] = line.split(': ')
- colr = colr.strip()
- if len(colr.split(':')) != 3:
- continue
- fo.write(t.substitute(table = table, rgb_column = rgb_column, colr = colr, column = column, value = value))
- found += 1
+ [value, colr] = line.split(': ')
+ colr = colr.strip()
+ if len(colr.split(':')) != 3:
+ continue
+ fo.write(t.substitute(table = table, rgb_column = rgb_column, colr = colr, column = column, value = value))
+ found += 1
fi.close()
fo.close()
if not found:
- grass.fatal(_("No values found in color range"))
+ grass.fatal(_("No values found in color range"))
# apply SQL commands to update the table with values
grass.message(_("Writing %s colors...") % found)
@@ -254,18 +254,18 @@
grass.fatal(_("Processing SQL transaction"))
if flags['s']:
- vcolors = "vcolors_%d" % pid
- grass.run_command('g.rename', raster = (tmp_colr, vcolors), quiet = True)
- grass.message(_("Raster map containing color rules saved to <%s>") % vcolors)
- # TODO save full v.colors command line history
- grass.run_command('r.support', map = vcolors,
- history = "",
- source1 = "vector map = %s" % map,
- source2 = "column = %s" % column,
- title = _("Dummy raster to use as thematic vector legend"),
- description = "generated by v.colors using r.mapcalc")
- grass.run_command('r.support', map = vcolors,
- history = _("RGB saved into <%s> using <%s%s%s>") % (rgb_column, color, raster, rules))
+ vcolors = "vcolors_%d" % pid
+ grass.run_command('g.rename', raster = (tmp_colr, vcolors), quiet = True)
+ grass.message(_("Raster map containing color rules saved to <%s>") % vcolors)
+ # TODO save full v.colors command line history
+ grass.run_command('r.support', map = vcolors,
+ history = "",
+ source1 = "vector map = %s" % map,
+ source2 = "column = %s" % column,
+ title = _("Dummy raster to use as thematic vector legend"),
+ description = "generated by v.colors using r.mapcalc")
+ grass.run_command('r.support', map = vcolors,
+ history = _("RGB saved into <%s> using <%s%s%s>") % (rgb_column, color, raster, rules))
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass-addons/grass7/vector/v.concave.hull/v.concave.hull.py
===================================================================
--- grass-addons/grass7/vector/v.concave.hull/v.concave.hull.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.concave.hull/v.concave.hull.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -2,14 +2,14 @@
############################################################################
#
-# MODULE: v.concave.hull
-# AUTHOR(S): Markus Metz
-# PURPOSE: Creates a concave hull around points
-# COPYRIGHT: (C) 2013-2014 by the GRASS Development Team
+# MODULE: v.concave.hull
+# AUTHOR(S): Markus Metz
+# PURPOSE: Creates a concave hull around points
+# COPYRIGHT: (C) 2013-2014 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.
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
#
#############################################################################
@@ -87,7 +87,7 @@
grass.message(_("Geometry conversion..."))
grass.run_command('v.extract', input = delaunay, output = out_lines_tmp,
- type = 'boundary', layer = '-1', quiet = True)
+ type = 'boundary', layer = '-1', quiet = True)
grass.run_command('v.type', input = out_lines_tmp, output = out_lines_nocat,
from_type = 'boundary', to_type = 'line', quiet = True)
grass.run_command('v.type', input = delaunay, output = out_points,
@@ -122,7 +122,7 @@
N = 0
tmpf = file(tmp)
for line in tmpf:
- N += 1
+ N += 1
tmpf.close()
max_length = 0.0
@@ -144,10 +144,10 @@
inf = file(tmp + ".sort")
l = 0
for line in inf:
- if l == ppos:
- max_length = float(line.rstrip('\r\n'))
- break
- l += 1
+ if l == ppos:
+ max_length = float(line.rstrip('\r\n'))
+ break
+ l += 1
inf.close()
grass.message(_("Feature selection..."))
@@ -157,13 +157,13 @@
type = 'line', where = 'length < %f' % max_length, quiet = True)
grass.run_command('v.category', input = lines_concave,
- output = lines_concave_nocat, type = 'line',
- op = 'del', cat = '-1', quiet = True)
+ output = lines_concave_nocat, type = 'line',
+ op = 'del', cat = '-1', quiet = True)
borders_concave = prefix + '_delaunay_borders_select'
grass.run_command('v.type', input = lines_concave_nocat,
output = borders_concave, from_type = 'line',
- to_type = 'boundary', quiet = True)
+ to_type = 'boundary', quiet = True)
areas_concave = prefix + '_delaunay_areas_select'
grass.run_command('v.centroids', input = borders_concave,
@@ -179,7 +179,7 @@
grass.run_command('v.extract', input = areas_concave,
output = areas_concave_extr, type = 'area',
- where='count = 1', quiet = True)
+ where='count = 1', quiet = True)
grass.message(_("The following warnings can be ignored"), flag = 'i')
grass.run_command('v.dissolve', input = areas_concave_extr,
Modified: grass-addons/grass7/vector/v.convert.all/v.convert.all.py
===================================================================
--- grass-addons/grass7/vector/v.convert.all/v.convert.all.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.convert.all/v.convert.all.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -2,15 +2,15 @@
#
############################################################################
#
-# MODULE: v.convert.all
-# AUTHOR(S): Markus Neteler, converted to Python by Glynn Clements
-# PURPOSE: converts all old GRASS < V5.7 vector maps to current format
-# in current mapset
-# COPYRIGHT: (C) 2004, 2008 by the GRASS Development Team
+# MODULE: v.convert.all
+# AUTHOR(S): Markus Neteler, converted to Python by Glynn Clements
+# PURPOSE: converts all old GRASS < V5.7 vector maps to current format
+# in current mapset
+# COPYRIGHT: (C) 2004, 2008 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.
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
#
#############################################################################
@@ -32,8 +32,8 @@
converted = 0
ret = 0
for vect in grass.list_grouped('oldvect')[mapset]:
- inmap = "%s@%s" % (vect, mapset)
- outmap = vect.replace(".", "_")
+ inmap = "%s@%s" % (vect, mapset)
+ outmap = vect.replace(".", "_")
try:
grass.run_command("v.convert", input=inmap, output=outmap)
except CalledModuleError:
@@ -42,13 +42,13 @@
else:
converted += 1
- if converted < 1:
- grass.warning(_("No vector maps converted as no old vector maps present in current mapset."))
- else:
- grass.message(_("Total %u vector maps in current mapset converted.") % converted)
- grass.message(_("Please verify new vector map(s) before deleting old vector map(s)."))
+ if converted < 1:
+ grass.warning(_("No vector maps converted as no old vector maps present in current mapset."))
+ else:
+ grass.message(_("Total %u vector maps in current mapset converted.") % converted)
+ grass.message(_("Please verify new vector map(s) before deleting old vector map(s)."))
- sys.exit(ret)
+ sys.exit(ret)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py
===================================================================
--- grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.faultdirections/v.faultdirections.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -64,7 +64,7 @@
map_=vector,
column=column,
flags='c').splitlines():
- azimuth.append(float(line))
+ azimuth.append(float(line))
bins = 360/step
az_bins = np.histogram(azimuth, bins=bins, range=(0,360))
@@ -96,7 +96,7 @@
# Use custom colors and opacity
for r, bar in zip(radii, bars):
- bar.set_alpha(0.5)
+ bar.set_alpha(0.5)
plt.show()
Modified: grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py
===================================================================
--- grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.in.gbif/v.in.gbif.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -64,7 +64,7 @@
def main():
-
+
gbifraw = options['input']
gbifimported = options['output']
directory = options['dir']
@@ -71,9 +71,9 @@
move_vrt_gbif_to_dir = flags['c']
gbifvrt = gbifimported+'.vrt'
gbif_vrt_layer = gbifimported
- gbifcsv = gbifimported+'.csv'
+ gbifcsv = gbifimported+'.csv'
reproject_gbif = flags['r']
- global tmp
+ global tmp
# check for unsupported locations or unsupported combination of option and projected location
in_proj = grass.parse_command('g.proj', flags='g')
@@ -80,7 +80,7 @@
if in_proj['name'].lower() == 'xy_location_unprojected':
grass.fatal(_("xy-locations are not supported"))
-
+
# import GBIF data
grass.message( "Starting importing GBIF data ..." )
grass.message( "preparing data for vrt ..." )
@@ -91,14 +91,14 @@
# quote raw data
with open('%s' % (gbifraw), 'rb') as csvinfile:
- gbifreader = csv.reader(csvinfile, delimiter='\t')
- with open ('%s' % (new_gbif_csv), 'wb') as csvoutfile:
- gbifwriter = csv.writer(csvoutfile, quotechar='"', quoting=csv.QUOTE_ALL)
- for row in gbifreader:
- gbifwriter.writerow(row)
+ gbifreader = csv.reader(csvinfile, delimiter='\t')
+ with open ('%s' % (new_gbif_csv), 'wb') as csvoutfile:
+ gbifwriter = csv.writer(csvoutfile, quotechar='"', quoting=csv.QUOTE_ALL)
+ for row in gbifreader:
+ gbifwriter.writerow(row)
grass.message( "----" )
- # write vrt
+ # write vrt
grass.message( "writing vrt ..." )
new_gbif_vrt = os.path.join( gbiftempdir, gbifvrt )
@@ -108,59 +108,59 @@
<SrcDataSource relativeToVRT="1">%s</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
- <Field name="g_gbifid" src="gbifid" type="Integer" />
- <Field name="g_datasetkey" src="datasetkey" type="String" width="255" />
- <Field name="g_occurrenceid" src="occurrenceid" type="String" width="255" />
- <Field name="g_kingdom" src="kingdom" type="String" width="50" />
- <Field name="g_phylum" src="phylum" type="String" width="50" />
- <Field name="g_class" src="class" type="String" width="50" />
- <Field name="g_order" src="order" type="String" width="50" />
- <Field name="g_family" src="family" type="String" width="100" />
- <Field name="g_genus" src="genus" type="String" width="255" />
- <Field name="g_species" src="species" type="String" width="255" />
- <Field name="g_infraspecificepithet" src="infraspecificepithet" type="String" width="100" />
- <Field name="g_taxonrank" src="taxonrank" type="String" width="50" />
- <Field name="g_scientificname" src="scientificname" type="String" width="255" />
- <Field name="g_countrycode" src="countrycode" type="String" width="25" />
- <Field name="g_locality" src="locality" type="String" width="255" />
- <Field name="g_publishingorgkey" src="publishingorgkey" type="String" width="255" />
- <Field name="g_decimallatitude" src="decimallatitude" type="Real" />
- <Field name="g_decimallongitude" src="decimallongitude" type="Real" />
- <Field name="g_elevation" src="elevation" type="Real" />
- <Field name="g_elevationaccuracy" src="elevationaccuracy" type="String" width="50" />
- <Field name="g_depth" src="depth" type="String" width="255" />
- <Field name="g_depthaccuracy" src="depthaccuracy" type="String" width="255" />
- <Field name="g_eventdate" src="eventdate" type="String" width="255" />
- <Field name="g_day" src="day" type="Integer" width="255" />
- <Field name="g_month" src="month" type="Integer" width="255" />
- <Field name="g_year" src="year" type="Integer" width="255" />
- <Field name="g_taxonkey" src="taxonkey" type="String" width="100" />
- <Field name="g_specieskey" src="specieskey" type="String" width="100" />
- <Field name="g_basisofrecord" src="basisofrecord" type="String" width="100" />
- <Field name="g_institutioncode" src="institutioncode" type="String" width="100" />
- <Field name="g_collectioncode" src="collectioncode" type="String" width="100" />
- <Field name="g_catalognumber" src="catalognumber" type="String" width="255" />
- <Field name="g_recordnumber" src="recordnumber" type="String" width="255" />
- <Field name="g_identifiedby" src="identifiedby" type="String" width="255" />
- <Field name="g_license" src="license" type="String" width="255" />
- <Field name="g_rightsholder" src="rightsholder" type="String" width="255" />
- <Field name="g_recordedby" src="recordedby" type="String" width="255" />
- <Field name="g_typestatus" src="typestatus" type="String" width="255" />
- <Field name="g_establishmentmeans" src="establishmentmeans" type="String" width="255" />
- <Field name="g_lastinterpreted" src="lastinterpreted" type="String" width="255" />
- <Field name="g_mediatype" src="mediatype" type="String" width="100" />
- <Field name="g_issue" src="issue" type="String" width="255" />
- <GeometryField encoding="PointFromColumns" x="decimallongitude" y="decimallatitude"/>
- </OGRVRTLayer>
- </OGRVRTDataSource>""" % (gbif_vrt_layer, gbifcsv) )
-
+ <Field name="g_gbifid" src="gbifid" type="Integer" />
+ <Field name="g_datasetkey" src="datasetkey" type="String" width="255" />
+ <Field name="g_occurrenceid" src="occurrenceid" type="String" width="255" />
+ <Field name="g_kingdom" src="kingdom" type="String" width="50" />
+ <Field name="g_phylum" src="phylum" type="String" width="50" />
+ <Field name="g_class" src="class" type="String" width="50" />
+ <Field name="g_order" src="order" type="String" width="50" />
+ <Field name="g_family" src="family" type="String" width="100" />
+ <Field name="g_genus" src="genus" type="String" width="255" />
+ <Field name="g_species" src="species" type="String" width="255" />
+ <Field name="g_infraspecificepithet" src="infraspecificepithet" type="String" width="100" />
+ <Field name="g_taxonrank" src="taxonrank" type="String" width="50" />
+ <Field name="g_scientificname" src="scientificname" type="String" width="255" />
+ <Field name="g_countrycode" src="countrycode" type="String" width="25" />
+ <Field name="g_locality" src="locality" type="String" width="255" />
+ <Field name="g_publishingorgkey" src="publishingorgkey" type="String" width="255" />
+ <Field name="g_decimallatitude" src="decimallatitude" type="Real" />
+ <Field name="g_decimallongitude" src="decimallongitude" type="Real" />
+ <Field name="g_elevation" src="elevation" type="Real" />
+ <Field name="g_elevationaccuracy" src="elevationaccuracy" type="String" width="50" />
+ <Field name="g_depth" src="depth" type="String" width="255" />
+ <Field name="g_depthaccuracy" src="depthaccuracy" type="String" width="255" />
+ <Field name="g_eventdate" src="eventdate" type="String" width="255" />
+ <Field name="g_day" src="day" type="Integer" width="255" />
+ <Field name="g_month" src="month" type="Integer" width="255" />
+ <Field name="g_year" src="year" type="Integer" width="255" />
+ <Field name="g_taxonkey" src="taxonkey" type="String" width="100" />
+ <Field name="g_specieskey" src="specieskey" type="String" width="100" />
+ <Field name="g_basisofrecord" src="basisofrecord" type="String" width="100" />
+ <Field name="g_institutioncode" src="institutioncode" type="String" width="100" />
+ <Field name="g_collectioncode" src="collectioncode" type="String" width="100" />
+ <Field name="g_catalognumber" src="catalognumber" type="String" width="255" />
+ <Field name="g_recordnumber" src="recordnumber" type="String" width="255" />
+ <Field name="g_identifiedby" src="identifiedby" type="String" width="255" />
+ <Field name="g_license" src="license" type="String" width="255" />
+ <Field name="g_rightsholder" src="rightsholder" type="String" width="255" />
+ <Field name="g_recordedby" src="recordedby" type="String" width="255" />
+ <Field name="g_typestatus" src="typestatus" type="String" width="255" />
+ <Field name="g_establishmentmeans" src="establishmentmeans" type="String" width="255" />
+ <Field name="g_lastinterpreted" src="lastinterpreted" type="String" width="255" />
+ <Field name="g_mediatype" src="mediatype" type="String" width="100" />
+ <Field name="g_issue" src="issue" type="String" width="255" />
+ <GeometryField encoding="PointFromColumns" x="decimallongitude" y="decimallatitude"/>
+ </OGRVRTLayer>
+ </OGRVRTDataSource>""" % (gbif_vrt_layer, gbifcsv) )
+
f.close()
grass.message( "----" )
- # Give information where output file are saved
+ # Give information where output file are saved
grass.message( "GBIF vrt files:" )
grass.message( gbifvrt )
- grass.message( "-" )
+ grass.message( "-" )
grass.message( gbifcsv )
grass.message( "----" )
@@ -168,30 +168,30 @@
grass.message( "importing GBIF vrt ..." )
# reprojection-on-the-fly if flag r
-
+
if reproject_gbif :
-
- grass.message( "reprojecting data on-the-fly ..." )
- grass.run_command("v.import", input = new_gbif_vrt,
+
+ grass.message( "reprojecting data on-the-fly ..." )
+ grass.run_command("v.import", input = new_gbif_vrt,
output = gbifimported,
quiet = True)
- # no reprojection-on-the-fly
-
+ # no reprojection-on-the-fly
+
else:
-
- grass.run_command("v.in.ogr", input = new_gbif_vrt,
+
+ grass.run_command("v.in.ogr", input = new_gbif_vrt,
layer = gbif_vrt_layer,
output = gbifimported,
quiet = True)
grass.message( "..." )
- # v.in.gbif done!
+ # v.in.gbif 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)
@@ -198,10 +198,10 @@
shutil.move(new_gbif_csv, directory)
grass.message( "in following user defined directory:" )
grass.message( directory )
- grass.message( "----" )
-
+ grass.message( "----" )
+
else:
-
+
grass.message( "----")
grass.message("Some clean up ...")
os.remove("%s" % new_gbif_vrt)
@@ -208,7 +208,7 @@
os.remove("%s" % new_gbif_csv)
grass.message("Clean up done.")
grass.message( "----")
-
+
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass-addons/grass7/vector/v.in.gps/v.in.gps.py
===================================================================
--- grass-addons/grass7/vector/v.in.gps/v.in.gps.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.in.gps/v.in.gps.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -2,28 +2,28 @@
#
############################################################################
#
-# MODULE: v.in.gps
+# MODULE: v.in.gps
#
-# PURPOSE: Import GPS data from a GPS receiver or file into a GRASS
-# vector map using gpsbabel
+# PURPOSE: Import GPS data from a GPS receiver or file into a GRASS
+# vector map using gpsbabel
#
-# COPYRIGHT: (c) 2011 Hamish Bowman, 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.
+# COPYRIGHT: (c) 2011 Hamish Bowman, 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.
#
-# AUTHOR: Hamish Bowman, Dunedin, New Zealand
-# Python version based on v.out.gps.py by Glynn Clements
-# Work-alike of the v.in.gpsbabel shell script from GRASS 6
+# AUTHOR: Hamish Bowman, Dunedin, New Zealand
+# Python version based on v.out.gps.py by Glynn Clements
+# Work-alike of the v.in.gpsbabel shell script from GRASS 6
#
#############################################################################
#
# REQUIREMENTS:
-# - GPSBabel from http://gpsbabel.sourceforge.net
-# - cs2cs from PROJ.4 (for m.proj) http://proj.osgeo.org
+# - GPSBabel from http://gpsbabel.sourceforge.net
+# - cs2cs from PROJ.4 (for m.proj) http://proj.osgeo.org
#
# - report supported GPSBabel formats:
-# gpsbabel -^2 | tr '\t' ';' | sort -t';' -k3
+# gpsbabel -^2 | tr '\t' ';' | sort -t';' -k3
#
#############################################################################
#
@@ -104,26 +104,26 @@
nflags = len(filter(None, [wpt, rte, trk]))
if nflags > 1:
- grass.fatal(_("One feature at a time please."))
+ grass.fatal(_("One feature at a time please."))
if nflags < 1:
- grass.fatal(_("No features requested for import."))
+ grass.fatal(_("No features requested for import."))
#### check for gpsbabel
### FIXME: may need --help or similar?
if not grass.find_program("gpsbabel"):
- grass.fatal(_("The gpsbabel program was not found, please install it first.\n") +
- "http://gpsbabel.sourceforge.net")
+ grass.fatal(_("The gpsbabel program was not found, please install it first.\n") +
+ "http://gpsbabel.sourceforge.net")
#### check for cs2cs
if not grass.find_program("cs2cs"):
- grass.fatal(_("The cs2cs program was not found, please install it first.\n") +
- "http://proj.osgeo.org")
+ grass.fatal(_("The cs2cs program was not found, please install it first.\n") +
+ "http://proj.osgeo.org")
#todo
# # check if we will overwrite data
# if grass.findfile(output) and not grass.overwrite():
-# grass.fatal(_("Output file already exists."))
+# grass.fatal(_("Output file already exists."))
#### set temporary files
tmp = grass.tempfile()
@@ -130,41 +130,41 @@
# import as GPX using v.in.ogr
# if trk:
-# linetype = "FORCE_GPX_TRACK=YES"
+# linetype = "FORCE_GPX_TRACK=YES"
# elif rte:
-# linetype = "FORCE_GPX_TRACK=YES"
+# linetype = "FORCE_GPX_TRACK=YES"
# else:
-# linetype = None
+# linetype = None
if format == 'gpx':
- # short circuit, we have what we came for.
+ # short circuit, we have what we came for.
#todo
-# grass.try_remove(output)
-# os.rename(tmp_gpx, output)
- grass.verbose("Fast exit.")
- sys.exit()
+# grass.try_remove(output)
+# os.rename(tmp_gpx, output)
+ grass.verbose("Fast exit.")
+ sys.exit()
# run gpsbabel
if wpt:
- gtype = '-w'
+ gtype = '-w'
elif trk:
- gtype = '-t'
+ gtype = '-t'
elif rte:
- gtype = '-r'
+ gtype = '-r'
else:
- gtype = ''
+ gtype = ''
grass.verbose("Running GPSBabel ...")
ret = grass.call(['gpsbabel',
- gtype,
- '-i', format,
- '-f', output,
- '-o', 'gpx',
- '-F', tmp + '.gpx'])
+ gtype,
+ '-i', format,
+ '-f', output,
+ '-o', 'gpx',
+ '-F', tmp + '.gpx'])
if ret != 0:
- grass.fatal(_("Error running GPSBabel"))
+ grass.fatal(_("Error running GPSBabel"))
grass.verbose("Importing data ...")
@@ -203,12 +203,12 @@
#
# lineno = 0
# for line in p1.stdout:
-# lineno += 1
-# if lineno < 11:
-# continue
-# line = re1.sub(r'#\1', line)
-# line = re2.sub(r'# 1 ', line)
-# p2.stdin.write(line)
+# lineno += 1
+# if lineno < 11:
+# continue
+# line = re1.sub(r'#\1', line)
+# line = re2.sub(r'# 1 ', line)
+# p2.stdin.write(line)
#
# p2.stdin.close()
# p1.wait()
@@ -215,7 +215,7 @@
# p2.wait()
#
# if p1.returncode != 0 or p2.returncode != 0:
-# grass.fatal(_("Error reprojecting data"))
+# grass.fatal(_("Error reprojecting data"))
#
# tmp_vogb = "tmp_vogb_epsg4326_%d" % os.getpid()
# p3 = grass.feed_command('v.in.ascii', out = tmp_vogb, format = 'standard', flags = 'n', quiet = True)
@@ -222,10 +222,10 @@
# tf = open(tmp_proj, 'r')
#
# for line in tf:
-# line = re3.sub(r' \1', line)
-# line = re4.sub(r' \1', line)
-# line = re5.sub('', line)
-# p3.stdin.write(line)
+# line = re3.sub(r' \1', line)
+# line = re4.sub(r' \1', line)
+# line = re5.sub('', line)
+# p3.stdin.write(line)
#
# p3.stdin.close()
# tf.close()
@@ -232,7 +232,7 @@
# p3.wait()
#
# if p3.returncode != 0:
-# grass.fatal(_("Error reprojecting data"))
+# grass.fatal(_("Error reprojecting data"))
Modified: grass-addons/grass7/vector/v.in.natura2000/v.in.natura2000.py
===================================================================
--- grass-addons/grass7/vector/v.in.natura2000/v.in.natura2000.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.in.natura2000/v.in.natura2000.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -123,7 +123,7 @@
sys.exit(1)
def main():
-
+
n2k_input = options['input']
n2k_output = options['output']
pa_sitetype_input = options['sitetype']
@@ -146,19 +146,19 @@
list_habitats = flags['h']
list_species = flags['s']
list_site_type = flags['t']
- global tmp
+ global tmp
try:
- import pyspatialite.dbapi2 as db
+ import pyspatialite.dbapi2 as db
except:
- grass.fatal( "pyspatialite is needed to run this script.\n"
+ grass.fatal( "pyspatialite is needed to run this script.\n"
"source: https://pypi.python.org/pypi/pyspatialite \n"
- "Please activate/install it in your python stack.")
+ "Please activate/install it in your python stack.")
if list_n2k_layer :
grass.message( "Available data layer(s):" )
grass.message( "may take some time ..." )
- grass.message( "..." )
+ grass.message( "..." )
grass.run_command("v.in.ogr", input = n2k_input,
flags = 'l')
@@ -166,15 +166,15 @@
grass.message( "Biogeographic regions:" )
conn = db.connect("%s" % n2k_input)
c = conn.cursor()
- for row in c.execute('SELECT BIOGEFRAPHICREG FROM BIOREGION GROUP BY BIOGEFRAPHICREG'):
+ for row in c.execute('SELECT BIOGEFRAPHICREG FROM BIOREGION GROUP BY BIOGEFRAPHICREG'):
grass.message( row )
- conn.close()
+ conn.close()
if list_ms :
grass.message( "EU member states:" )
conn = db.connect("%s" % n2k_input)
c = conn.cursor()
- for row in c.execute('SELECT MS FROM Natura2000polygon GROUP BY MS'):
+ for row in c.execute('SELECT MS FROM Natura2000polygon GROUP BY MS'):
grass.message( row )
conn.close()
@@ -183,7 +183,7 @@
conn = db.connect("%s" % n2k_input)
c = conn.cursor()
try:
- for row in c.execute('SELECT HABITATCODE, DESCRIPTION FROM HABITATS GROUP BY HABITATCODE'):
+ for row in c.execute('SELECT HABITATCODE, DESCRIPTION FROM HABITATS GROUP BY HABITATCODE'):
grass.message( row )
except:
pass
@@ -196,7 +196,7 @@
conn = db.connect("%s" % n2k_input)
c = conn.cursor()
try:
- for row in c.execute('SELECT SPECIESCODE, SPECIESNAME FROM SPECIES GROUP BY SPECIESCODE'):
+ for row in c.execute('SELECT SPECIESCODE, SPECIESNAME FROM SPECIES GROUP BY SPECIESCODE'):
grass.message( row )
except:
pass
@@ -208,7 +208,7 @@
grass.message( "site types:" )
conn = db.connect("%s" % n2k_input)
c = conn.cursor()
- for row in c.execute('SELECT SITETYPE FROM NATURA2000SITES GROUP BY SITETYPE'):
+ for row in c.execute('SELECT SITETYPE FROM NATURA2000SITES GROUP BY SITETYPE'):
grass.message( row )
conn.close()
@@ -216,19 +216,19 @@
grass.message( "importing protected areas of site type: %s" % pa_sitetype_input )
grass.message( "may take some time ..." )
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
- layer = "natura2000polygon",
- output = n2k_output,
- where = "SITETYPE = '%s'" % (pa_sitetype_input),
- quiet = False)
+ layer = "natura2000polygon",
+ output = n2k_output,
+ where = "SITETYPE = '%s'" % (pa_sitetype_input),
+ quiet = False)
if ms_input :
grass.message( "importing protected areas of member state: %s" % ms_input )
grass.message( "may take some time ..." )
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
- layer = "natura2000polygon",
- output = n2k_output,
- where = "MS = '%s'" % (ms_input),
- quiet = False)
+ layer = "natura2000polygon",
+ output = n2k_output,
+ where = "MS = '%s'" % (ms_input),
+ quiet = False)
if habitat_code_input :
grass.message( "importing protected areas with habitat (code): %s" % habitat_code_input )
@@ -242,7 +242,7 @@
sqlhabitat += 'WHERE HABITATCODE = "%s" ' % (habitat_code_input)
sqlhabitat += 'ORDER BY "SITECODE"'
grass.message ( sqlhabitat )
- c.execute( sqlhabitat )
+ c.execute( sqlhabitat )
# create spatial view of defined habitat - part 1
grass.message( "spatial view: %s" % habitat_spatial_view )
sqlhabitatspatial1 = 'CREATE VIEW "%s" AS ' % (habitat_spatial_view)
@@ -257,25 +257,25 @@
sqlhabitatspatial1 += '"b"."PERCENTAGECOVER" AS "PERCENTAGECOVER" '
sqlhabitatspatial1 += 'FROM "Natura2000polygon" AS "a" '
sqlhabitatspatial1 += 'JOIN %s AS "b" USING ("SITECODE") ' % (habitat_view)
- sqlhabitatspatial1 += 'ORDER BY "a"."SITECODE";'
+ sqlhabitatspatial1 += 'ORDER BY "a"."SITECODE";'
grass.message ( sqlhabitatspatial1 )
c.execute( sqlhabitatspatial1 )
- # create spatial view of defined habitat - part 2
+ # create spatial view of defined habitat - part 2
sqlhabitatspatial2 = 'INSERT INTO views_geometry_columns '
sqlhabitatspatial2 += '(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, read_only) '
sqlhabitatspatial2 += 'VALUES ("%s", "geometry", "rowid", "natura2000polygon", "geometry", 1);' % (habitat_spatial_view.lower())
- grass.message ( sqlhabitatspatial2 )
- # execute spatial vieww
+ grass.message ( sqlhabitatspatial2 )
+ # execute spatial vieww
c.execute( sqlhabitatspatial2 )
- conn.commit()
+ conn.commit()
conn.close()
# import spatial view
grass.message ( "importing data..." )
- grass.message ( "may take some time..." )
+ grass.message ( "may take some time..." )
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
layer = "%s" % (habitat_spatial_view),
output = n2k_output,
- quiet = False)
+ quiet = False)
if species_code_input :
grass.message( "importing protected areas with species (code): %s" % species_code_input )
@@ -289,7 +289,7 @@
sqlspecies += 'WHERE SPECIESCODE = "%s" ' % (species_code_input)
sqlspecies += 'ORDER BY "SITECODE"'
grass.message ( sqlspecies )
- c.execute( sqlspecies )
+ c.execute( sqlspecies )
# create spatial view of defined species - part 1
grass.message( "spatial view: %s" % species_spatial_view )
sqlspeciesspatial1 = 'CREATE VIEW "%s" AS ' % (species_spatial_view)
@@ -309,25 +309,25 @@
sqlspeciesspatial1 += '"b"."GLOBAL" AS "GLOBAL" '
sqlspeciesspatial1 += 'FROM "Natura2000polygon" AS "a" '
sqlspeciesspatial1 += 'JOIN %s AS "b" USING ("SITECODE") ' % (species_view)
- sqlspeciesspatial1 += 'ORDER BY "a"."SITECODE";'
+ sqlspeciesspatial1 += 'ORDER BY "a"."SITECODE";'
grass.message ( sqlspeciesspatial1 )
- c.execute( sqlspeciesspatial1 )
- # create spatial view of defined habitat - part 2
+ c.execute( sqlspeciesspatial1 )
+ # create spatial view of defined habitat - part 2
sqlspeciesspatial2 = 'INSERT INTO views_geometry_columns '
sqlspeciesspatial2 += '(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, read_only) '
sqlspeciesspatial2 += 'VALUES ("%s", "geometry", "rowid", "natura2000polygon", "geometry", 1);' % (species_spatial_view.lower())
- grass.message ( sqlspeciesspatial2 )
- # execute spatial view
+ grass.message ( sqlspeciesspatial2 )
+ # execute spatial view
c.execute( sqlspeciesspatial2 )
- conn.commit()
+ conn.commit()
conn.close()
# import spatial view
grass.message ( "importing data..." )
- grass.message ( "may take some time..." )
+ grass.message ( "may take some time..." )
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
layer = "%s" % (species_spatial_view),
output = n2k_output,
- quiet = False)
+ quiet = False)
if biogeoreg_long :
grass.message( "importing protected areas of biogeographic region: %s" % biogeoreg_long )
@@ -352,25 +352,25 @@
sqlbioregspatial1 += '"b"."PERCENTAGE" AS "PERCENTAGE" '
sqlbioregspatial1 += 'FROM "Natura2000polygon" AS "a" '
sqlbioregspatial1 += 'JOIN %s AS "b" USING ("SITECODE") ' % (biogeoreg_view)
- sqlbioregspatial1 += 'ORDER BY "a"."SITECODE";'
+ sqlbioregspatial1 += 'ORDER BY "a"."SITECODE";'
grass.message ( sqlbioregspatial1 )
- c.execute( sqlbioregspatial1)
+ c.execute( sqlbioregspatial1)
# create spatial view of defined biogeographical region - part 2
sqlbioregspatial2 = 'INSERT INTO views_geometry_columns '
sqlbioregspatial2 += '(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, read_only) '
sqlbioregspatial2 += 'VALUES ("%s", "geometry", "rowid", "natura2000polygon", "geometry", 1);' % (biogeoreg_spatial_view.lower())
- grass.message ( sqlbioregspatial2 )
- # execute spatial view
+ grass.message ( sqlbioregspatial2 )
+ # execute spatial view
c.execute( sqlbioregspatial2 )
- conn.commit()
+ conn.commit()
conn.close()
# import spatial view
grass.message ( "importing data..." )
- grass.message ( "may take some time..." )
+ grass.message ( "may take some time..." )
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
layer = "%s" % (biogeoreg_spatial_view),
output = n2k_output,
- quiet = False)
+ quiet = False)
if layer_exist :
grass.message( "importing existing spatial layer %s of the dataset" % layer_exist )
@@ -377,7 +377,7 @@
grass.run_command( "v.in.ogr", input = "%s" % (n2k_input),
layer = "%s" % (layer_exist),
output = n2k_output,
- quiet = False)
+ quiet = False)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass-addons/grass7/vector/v.in.pygbif/v.in.pygbif.py
===================================================================
--- grass-addons/grass7/vector/v.in.pygbif/v.in.pygbif.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.in.pygbif/v.in.pygbif.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -185,14 +185,6 @@
from grass.pygrass.vector.geometry import Point
from dateutil.parser import parse
-#reload(sys)
-#sys.setdefaultencoding('utf-8')
-
-if not "GISBASE" in list(os.environ.keys()):
- grass.message("You must be in GRASS GIS to run this program.")
- sys.exit(1)
-
-
def set_output_encoding(encoding='utf-8'):
import sys
import codecs
Modified: grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py
===================================================================
--- grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.in.redlist/v.in.redlist.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -71,7 +71,7 @@
def main():
-
+
redlist_shapefile_long = options['input']
imported_species = options['species_name']
species_to_import = options['output']
@@ -82,51 +82,51 @@
redlist_shapefile_short = os.path.basename(redlist_shapefile_long)
species_filename = redlist_shapefile_short.split('.')[0]
species_file = species_filename+'.txt'
- global tmp
+ 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) )
+
+ 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
-
+ # 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")))
+
+ 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 :
+
+ 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)
+ 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()
Modified: grass-addons/grass7/vector/v.median/v.median.py
===================================================================
--- grass-addons/grass7/vector/v.median/v.median.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.median/v.median.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -68,29 +68,29 @@
overwrite = os.getenv('GRASS_OVERWRITE')
# if output is not set return to stdout
if map_name == '-':
- grass.message(output)
+ grass.message(output)
# else
else:
- # output file
- goutfile = grass.find_file(name = map_name, element = 'vector',
+ # output file
+ goutfile = grass.find_file(name = map_name, element = 'vector',
mapset = '.')
# output tempfile
- temp_out = grass.tempfile()
- file_out = open(temp_out,'w')
- file_out.write(output)
- file_out.close()
- # output file exists and not overwrite
+ temp_out = grass.tempfile()
+ file_out = open(temp_out,'w')
+ file_out.write(output)
+ file_out.close()
+ # output file exists and not overwrite
if goutfile['file'] and overwrite != '1':
- grass.fatal(_("Vector map <%s> already exists") % map_name)
- # output file exists and overwrite
- elif goutfile['file'] and overwrite == '1':
- grass.warning(_("Vector map <%s> already exists and will be overwritten") % map_name)
- grass.run_command('v.in.ascii', overwrite = True, input=temp_out,
- output = map_name)
- # output file not exists
- else:
- grass.run_command('v.in.ascii', input=temp_out, output = map_name)
- try_remove(temp_out)
+ grass.fatal(_("Vector map <%s> already exists") % map_name)
+ # output file exists and overwrite
+ elif goutfile['file'] and overwrite == '1':
+ grass.warning(_("Vector map <%s> already exists and will be overwritten") % map_name)
+ grass.run_command('v.in.ascii', overwrite = True, input=temp_out,
+ output = map_name)
+ # output file not exists
+ else:
+ grass.run_command('v.in.ascii', input=temp_out, output = map_name)
+ try_remove(temp_out)
if __name__ == "__main__":
options, flags = grass.parser()
Modified: grass-addons/grass7/vector/v.out.gps/v.out.gps.py
===================================================================
--- grass-addons/grass7/vector/v.out.gps/v.out.gps.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.out.gps/v.out.gps.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -2,27 +2,27 @@
#
############################################################################
#
-# MODULE: v.out.gps
+# MODULE: v.out.gps
#
-# PURPOSE: Exports a GRASS vector map to a GPS receiver
-# or data file using GPSBabel
+# PURPOSE: Exports a GRASS vector map to a GPS receiver
+# or data file using GPSBabel
#
-# COPYRIGHT: (c) 2008-2009 Hamish Bowman, 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.
+# COPYRIGHT: (c) 2008-2009 Hamish Bowman, 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.
#
-# AUTHOR: Hamish Bowman, Dunedin, New Zealand
-# Converted to Python by Glynn Clements
+# AUTHOR: Hamish Bowman, Dunedin, New Zealand
+# Converted to Python by Glynn Clements
#
#############################################################################
#
# REQUIREMENTS:
-# - GPSBabel from http://gpsbabel.sourceforge.net
-# - cs2cs from PROJ.4 (for m.proj) http://proj.osgeo.org
+# - GPSBabel from http://gpsbabel.sourceforge.net
+# - cs2cs from PROJ.4 (for m.proj) http://proj.osgeo.org
#
# - report supported GPSBabel formats:
-# gpsbabel -^2 | tr '\t' ';' | sort -t';' -k3
+# gpsbabel -^2 | tr '\t' ';' | sort -t';' -k3
#
#############################################################################
#
@@ -91,20 +91,20 @@
def cleanup():
grass.verbose("Cleaning up ...")
if tmp:
- grass.try_remove(tmp)
+ grass.try_remove(tmp)
if tmp_proj:
- grass.try_remove(tmp_proj)
+ grass.try_remove(tmp_proj)
if tmp_gpx:
- grass.try_remove(tmp_gpx)
+ grass.try_remove(tmp_gpx)
# only try to remove map if it exists to avoid ugly warnings
if tmp_vogb:
- if grass.find_file(tmp_vogb, element = 'vector')['name']:
- grass.run_command('g.remove', flags = 'f', type = 'vector',
+ if grass.find_file(tmp_vogb, element = 'vector')['name']:
+ grass.run_command('g.remove', flags = 'f', type = 'vector',
name = tmp_vogb, quiet = True)
if tmp_extr:
- if grass.find_file(tmp_extr, element = 'vector')['name']:
- grass.run_command('g.remove', flags = 'f', type = 'vector',
+ if grass.find_file(tmp_extr, element = 'vector')['name']:
+ grass.run_command('g.remove', flags = 'f', type = 'vector',
name = tmp_vogb, quiet = True)
tmp = None
@@ -128,31 +128,31 @@
nflags = len(filter(None, [wpt, rte, trk]))
if nflags > 1:
- grass.fatal(_("One feature at a time please."))
+ grass.fatal(_("One feature at a time please."))
if nflags < 1:
- grass.fatal(_("No features requested for export."))
+ grass.fatal(_("No features requested for export."))
# set some reasonable defaults
if not type:
- if wpt:
- type = 'point'
- else:
- type = 'line'
+ if wpt:
+ type = 'point'
+ else:
+ type = 'line'
#### check for gpsbabel
### FIXME: may need --help or similar?
if not grass.find_program("gpsbabel"):
- grass.fatal(_("The gpsbabel program was not found, please install it first.\n") +
- "http://gpsbabel.sourceforge.net")
+ grass.fatal(_("The gpsbabel program was not found, please install it first.\n") +
+ "http://gpsbabel.sourceforge.net")
#### check for cs2cs
if not grass.find_program("cs2cs"):
- grass.fatal(_("The cs2cs program was not found, please install it first.\n") +
- "http://proj.osgeo.org")
+ grass.fatal(_("The cs2cs program was not found, please install it first.\n") +
+ "http://proj.osgeo.org")
# check if we will overwrite data
if os.path.exists(output) and not grass.overwrite():
- grass.fatal(_("Output file already exists."))
+ grass.fatal(_("Output file already exists."))
#### set temporary files
tmp = grass.tempfile()
@@ -159,8 +159,8 @@
# SQL extract if needed
if where:
- grass.verbose("Extracting data ...")
- tmp_extr = "tmp_vogb_extr_%d" % os.getpid()
+ grass.verbose("Extracting data ...")
+ tmp_extr = "tmp_vogb_extr_%d" % os.getpid()
try:
grass.run_command('v.extract', input="$GIS_OPT_INPUT",
output=tmp_extr, type=type, layer=layer,
@@ -168,15 +168,15 @@
except CalledModuleError:
grass.fatal(_("Error executing SQL query"))
- kv = grass.vector_info_topo(tmp_extr)
- if kv['primitives'] == 0:
- grass.fatal(_("SQL query returned an empty map (no %s features?)") % type)
+ kv = grass.vector_info_topo(tmp_extr)
+ if kv['primitives'] == 0:
+ grass.fatal(_("SQL query returned an empty map (no %s features?)") % type)
- inmap = tmp_extr
+ inmap = tmp_extr
else:
- # g.copy vector="$GIS_OPT_INPUT,tmp_vogb_extr_$$" # to get a copy of DB into local mapset
- # INMAP="tmp_vogb_extr_$$"
- inmap = input
+ # g.copy vector="$GIS_OPT_INPUT,tmp_vogb_extr_$$" # to get a copy of DB into local mapset
+ # INMAP="tmp_vogb_extr_$$"
+ inmap = input
#### set up projection info
# TODO: check if we are already in ll/WGS84. If so skip m.proj step.
@@ -203,12 +203,12 @@
lineno = 0
for line in p1.stdout:
- lineno += 1
- if lineno < 11:
- continue
- line = re1.sub(r'#\1', line)
- line = re2.sub(r'# 1 ', line)
- p2.stdin.write(line)
+ lineno += 1
+ if lineno < 11:
+ continue
+ line = re1.sub(r'#\1', line)
+ line = re2.sub(r'# 1 ', line)
+ p2.stdin.write(line)
p2.stdin.close()
p1.wait()
@@ -215,7 +215,7 @@
p2.wait()
if p1.returncode != 0 or p2.returncode != 0:
- grass.fatal(_("Error reprojecting data"))
+ grass.fatal(_("Error reprojecting data"))
tmp_vogb = "tmp_vogb_epsg4326_%d" % os.getpid()
p3 = grass.feed_command('v.in.ascii', out = tmp_vogb, format = 'standard', flags = 'n', quiet = True)
@@ -222,10 +222,10 @@
tf = open(tmp_proj, 'r')
for line in tf:
- line = re3.sub(r' \1', line)
- line = re4.sub(r' \1', line)
- line = re5.sub('', line)
- p3.stdin.write(line)
+ line = re3.sub(r' \1', line)
+ line = re4.sub(r' \1', line)
+ line = re5.sub('', line)
+ p3.stdin.write(line)
p3.stdin.close()
tf.close()
@@ -232,18 +232,18 @@
p3.wait()
if p3.returncode != 0:
- grass.fatal(_("Error reprojecting data"))
+ grass.fatal(_("Error reprojecting data"))
# don't v.db.connect directly as source table will be removed with
# temporary map in that case. So we make a temp copy of it to work with.
kv = vector_db(inmap)
if layer in kv:
- db_params = kv[layer]
+ db_params = kv[layer]
- db_table = db_params['table']
- db_key = db_params['key']
- db_database = db_params['database']
- db_driver = db_params['driver']
+ db_table = db_params['table']
+ db_key = db_params['key']
+ db_database = db_params['database']
+ db_driver = db_params['driver']
try:
grass.run_command('db.copy',
@@ -262,11 +262,11 @@
# export as GPX using v.out.ogr
if trk:
- linetype = "FORCE_GPX_TRACK=YES"
+ linetype = "FORCE_GPX_TRACK=YES"
elif rte:
- linetype = "FORCE_GPX_TRACK=YES"
+ linetype = "FORCE_GPX_TRACK=YES"
else:
- linetype = None
+ linetype = None
# BUG: cat is being reported as evelation and attribute output is skipped.
# (v.out.ogr DB reading or ->OGR GPX driver bug<-
@@ -288,33 +288,33 @@
grass.fatal(_("Error exporting data"))
if format == 'gpx':
- # short circuit, we have what we came for.
- grass.try_remove(output)
- os.rename(tmp_gpx, output)
- grass.verbose("Fast exit.")
- sys.exit()
+ # short circuit, we have what we came for.
+ grass.try_remove(output)
+ os.rename(tmp_gpx, output)
+ grass.verbose("Fast exit.")
+ sys.exit()
# run gpsbabel
if wpt:
- gtype = '-w'
+ gtype = '-w'
elif trk:
- gtype = '-t'
+ gtype = '-t'
elif rte:
- gtype = '-r'
+ gtype = '-r'
else:
- gtype = ''
+ gtype = ''
grass.verbose("Running GPSBabel ...")
ret = grass.call(['gpsbabel',
- gtype,
- '-i', 'gpx',
- '-f', tmp + '.gpx',
- '-o', format,
- '-F', output])
+ gtype,
+ '-i', 'gpx',
+ '-f', tmp + '.gpx',
+ '-o', format,
+ '-F', output])
if ret != 0:
- grass.fatal(_("Error running GPSBabel"))
+ grass.fatal(_("Error running GPSBabel"))
grass.verbose("Done.")
Modified: grass-addons/grass7/vector/v.ply.rectify/v.ply.rectify.py
===================================================================
--- grass-addons/grass7/vector/v.ply.rectify/v.ply.rectify.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.ply.rectify/v.ply.rectify.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -50,30 +50,30 @@
#### check for v.in.ply, v.out.ply
if not grass.find_program("v.in.ply", '--help'):
- grass.fatal(_("The GRASS addon v.in.ply was not found, please install it first.\n"))
+ grass.fatal(_("The GRASS addon v.in.ply was not found, please install it first.\n"))
if not grass.find_program("v.out.ply", '--help'):
- grass.fatal(_("The GRASS addon v.out.ply was not found, please install it first.\n"))
+ grass.fatal(_("The GRASS addon v.out.ply was not found, please install it first.\n"))
# import input PLY file
infile = options['input']
if not os.path.exists(infile):
- grass.fatal(_("Unable to read input file <%s>") % infile)
+ grass.fatal(_("Unable to read input file <%s>") % infile)
grass.debug("input file=[%s]" % infile)
if not infile[-4:].lower() == '.ply':
- grass.fatal(_("Input file must end with .ply or .PLY"))
-
+ grass.fatal(_("Input file must end with .ply or .PLY"))
+
gcpfile = infile[:-4] + ".txt"
srcdir, ply = os.path.split(infile)
ply = ply[:-4]
if not os.path.exists(gcpfile):
- gcpfile = infile[:-4] + ".TXT"
- if not os.path.exists(gcpfile):
- grass.fatal(_("Input file with GCPs must be <%s> or <%s>") % ply + ".txt", ply + ".TXT")
+ gcpfile = infile[:-4] + ".TXT"
+ if not os.path.exists(gcpfile):
+ grass.fatal(_("Input file with GCPs must be <%s> or <%s>") % ply + ".txt", ply + ".TXT")
if options['output'] is not None and options['output'] != '':
- ply = options['output']
+ ply = options['output']
clist = list()
@@ -103,7 +103,7 @@
found = grass.find_file(ply, element = 'vector', mapset = currmapset)
if found['name'] != ply:
- grass.fatal(_('PLY import failed!'))
+ grass.fatal(_('PLY import failed!'))
# detach table
table = gvector.vector_layer_db(map = ply, layer = 1)['table']
@@ -112,21 +112,21 @@
# print RMS
rmsfile = os.path.join(srcdir, ply + "_rms.csv")
grass.run_command('v.rectify', input = ply, output = ply + '_georef',
- points = gcpfile, flags = '3bor', separator = ';',
- rmsfile = rmsfile)
+ points = gcpfile, flags = '3bor', separator = ';',
+ rmsfile = rmsfile)
# georectify
ply_georef = ply + '_georef'
grass.run_command('v.rectify', input = ply, output = ply_georef,
- points = gcpfile, flags = '3bo')
+ points = gcpfile, flags = '3bo')
# output vector exists?
found = grass.find_file(ply_georef, element = 'vector', mapset = currmapset)
if found['name'] != ply_georef:
- grass.run_command('v.db.connect', map = ply,
- layer = 1, table = table, key = 'cat')
- grass.fatal('PLY import failed!')
+ grass.run_command('v.db.connect', map = ply,
+ layer = 1, table = table, key = 'cat')
+ grass.fatal('PLY import failed!')
grass.run_command('v.db.connect', map = ply_georef,
layer = 1, table = table, key = 'cat')
@@ -138,34 +138,34 @@
grass.run_command('v.db.connect', map = ply_georef, layer = 1, flags = 'd')
if export_shifted:
- vinfo = gvector.vector_info(map = ply_georef)
- north_center = (float(vinfo['north']) + float(vinfo['south'])) / -2.0
- east_center = (float(vinfo['east']) + float(vinfo['west'])) / -2.0
- height_center = (float(vinfo['top']) + float(vinfo['bottom'])) / -2.0
+ vinfo = gvector.vector_info(map = ply_georef)
+ north_center = (float(vinfo['north']) + float(vinfo['south'])) / -2.0
+ east_center = (float(vinfo['east']) + float(vinfo['west'])) / -2.0
+ height_center = (float(vinfo['top']) + float(vinfo['bottom'])) / -2.0
- ply_shifted = ply_georef + '_shifted'
- grass.run_command('v.transform', input = ply_georef, layer = -1,
- output = ply_shifted, xshift = east_center,
- yshift = north_center, zshift = height_center,
- xscale = 1.0, yscale = 1.0, zscale = 1.0, zrot = 0.0,
- flags = 'b')
-
- # output vector exists?
- found = grass.find_file(ply_shifted, element = 'vector', mapset = currmapset)
+ ply_shifted = ply_georef + '_shifted'
+ grass.run_command('v.transform', input = ply_georef, layer = -1,
+ output = ply_shifted, xshift = east_center,
+ yshift = north_center, zshift = height_center,
+ xscale = 1.0, yscale = 1.0, zscale = 1.0, zrot = 0.0,
+ flags = 'b')
+
+ # output vector exists?
+ found = grass.find_file(ply_shifted, element = 'vector', mapset = currmapset)
- if found['name'] != ply_shifted:
- grass.run_command('v.db.connect', map = ply,
- layer = 1, table = table, key = 'cat')
- grass.fatal('PLY import failed!')
+ if found['name'] != ply_shifted:
+ grass.run_command('v.db.connect', map = ply,
+ layer = 1, table = table, key = 'cat')
+ grass.fatal('PLY import failed!')
- grass.run_command('v.db.connect', map = ply_shifted,
- layer = 1, table = table, key = 'cat')
-
- output = os.path.join(srcdir, ply_shifted + '.ply')
- grass.run_command('v.out.ply', input = ply_shifted, output = output,
- columns = columns)
-
- grass.run_command('v.db.connect', map = ply_shifted, layer = 1, flags = 'd')
+ grass.run_command('v.db.connect', map = ply_shifted,
+ layer = 1, table = table, key = 'cat')
+
+ output = os.path.join(srcdir, ply_shifted + '.ply')
+ grass.run_command('v.out.ply', input = ply_shifted, output = output,
+ columns = columns)
+
+ grass.run_command('v.db.connect', map = ply_shifted, layer = 1, flags = 'd')
Modified: grass-addons/grass7/vector/v.sort.points/v.sort.points.py
===================================================================
--- grass-addons/grass7/vector/v.sort.points/v.sort.points.py 2019-01-17 21:34:28 UTC (rev 73968)
+++ grass-addons/grass7/vector/v.sort.points/v.sort.points.py 2019-01-17 21:46:42 UTC (rev 73969)
@@ -45,10 +45,10 @@
try:
return int(s)
except ValueError:
- try:
- return float(s)
- except:
- return s
+ try:
+ return float(s)
+ except:
+ return s
def main():
options, flags = gscript.parser()
@@ -69,8 +69,8 @@
for colcount in range(1,len(sorted_cols)):
name = sorted_cols[colcount][0]
type = sorted_cols[colcount][1]['type']
- if name == sort_column and (type != 'INTEGER' and type != 'DOUBLE PRECISION'):
- gscript.fatal('Sort column must be numeric')
+ if name == sort_column and (type != 'INTEGER' and type != 'DOUBLE PRECISION'):
+ gscript.fatal('Sort column must be numeric')
if name == key_column:
continue
colnames.append(name)
More information about the grass-commit
mailing list