[GRASS-SVN] r60359 - grass/trunk/scripts/v.report
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 19 20:32:43 PDT 2014
Author: hcho
Date: 2014-05-19 20:32:42 -0700 (Mon, 19 May 2014)
New Revision: 60359
Modified:
grass/trunk/scripts/v.report/v.report.py
Log:
v.report: cat mismatch bug fixed.
How to reproduce the bug
1. Merge multiple lines into polylines:
v.build.polylines input=lines output=polylines cat=first
lines attribute table is copied to polylines attribute table, but not all
records have associated polyline features because only first attribute was
linked to a feature.
2. v.db.select -c map=polylines, which is called by v.report, returns all
records, which then are stored in records1.
E.g,. three lines 1, 2, and 3 are merged into a polyline 3. Attributes 1 and
2 are orphaned.
cat|desc
1|
2|
3|new polyline
3. v.to.db -p map=polylines option=option... returns only attributes that are
linked to features and they are stored in records2.
E.g.,
cat|length
3|1000
4. Now, sorted records1 and sorted records2 may not have the same ordered cats
or even len(records1) != len(records2).
5. v.report always reports cats starting from 1 to #features, which can be
wrong, because records1 has all the records in the attribute table, but
records2 only has a subset of records1. Zipping two lists of different
sizes...
E.g., 1 from v.db.select, new polyline|1000 from v.to.db
cat|desc|length
1|new polyline|1000
Modified: grass/trunk/scripts/v.report/v.report.py
===================================================================
--- grass/trunk/scripts/v.report/v.report.py 2014-05-20 03:11:33 UTC (rev 60358)
+++ grass/trunk/scripts/v.report/v.report.py 2014-05-20 03:32:42 UTC (rev 60359)
@@ -4,6 +4,7 @@
#
# MODULE: v.report
# AUTHOR(S): Markus Neteler, converted to Python by Glynn Clements
+# Bug fixed by Huidae Cho <grass4u gmail.com>
# PURPOSE: Reports geometry statistics for vector maps
# COPYRIGHT: (C) 2005, 2007-2009 by MN and the GRASS Development Team
#
@@ -67,9 +68,8 @@
grass.fatal(_("Vector map <%s> not found") % mapname)
colnames = grass.vector_columns(mapname, layer, getDict = False, stderr = nuldev)
-
- if not colnames:
- colnames = ['cat']
+# if not colnames:
+# colnames = ['cat']
if option == 'coor':
columns = ['dummy1','dummy2','dummy3']
@@ -124,7 +124,11 @@
records2.sort()
#make pre-table
- records3 = [r1 + r2[1:] for r1, r2 in zip(records1, records2)]
+ # len(records1) may not be the same as len(records2) because
+ # v.db.select can return attributes that are not linked to features.
+ records3 = []
+ for r2 in records2:
+ records3.append(filter(lambda r1: r1[0] == r2[0], records1)[0] + r2[1:])
else:
records1 = []
p = grass.pipe_command('v.category', inp = mapname, layer = layer, option = 'print')
More information about the grass-commit
mailing list