[GRASS-dev] [GRASS-SVN] r70632 - grass/trunk/scripts/v.report

Hi,

are you planning to backport bugfixes to relb72? Thanks, Ma

2017-02-20 1:15 GMT+01:00 <svn_grass@osgeo.org>:

Author: hcho
Date: 2017-02-19 16:15:14 -0800 (Sun, 19 Feb 2017)
New Revision: 70632

Modified:
   grass/trunk/scripts/v.report/v.report.py
Log:
v.report: Fix unit=percent

Modified: grass/trunk/scripts/v.report/v.report.py

--- grass/trunk/scripts/v.report/v.report.py 2017-02-19 23:40:29 UTC (rev 70631)
+++ grass/trunk/scripts/v.report/v.report.py 2017-02-20 00:15:14 UTC (rev 70632)
@@ -81,7 +81,7 @@
     else:
         extracolnames = [option]

- if units in ['p', 'percent']:
+ if units == 'percent':
         unitsp = 'meters'
     elif units:
         unitsp = units
@@ -90,6 +90,7 @@

     # NOTE: we suppress -1 cat and 0 cat
     if isConnection:
+ f = grass.vector_db(map=mapname)[int(layer)]
         p = grass.pipe_command('v.db.select', quiet=True, map=mapname, layer=layer)
         records1 =
         catcol = -1
@@ -97,12 +98,12 @@
             cols = line.rstrip('\r\n').split('|')
             if catcol == -1:
                 for i in range(0, len(cols)):
- if cols[i] == 'cat':
+ if cols[i] == f['key']:
                         catcol = i
                         break
                 if catcol == -1:
- # shouldn't happen, but let's do this
- catcol = 0
+ grass.fatal(_("There is a table connected to input vector map '%s', but "
+ "there is no key column '%s'.") % (mapname, f['key']))
                 continue
             if cols[catcol] == '-1' or cols[catcol] == '0':
                 continue
@@ -115,7 +116,6 @@

         if len(records1) == 0:
             try:
- f = grass.vector_db(map=mapname)[int(layer)]
                 grass.fatal(_("There is a table connected to input vector map '%s', but "
                               "there are no categories present in the key column '%s'. Consider using "
                               "v.to.db to correct this.") % (mapname, f['key']))
@@ -142,6 +142,7 @@
         for r2 in records2:
             records3.append(filter(lambda r1: r1[catcol] == r2[0], records1)[0] + r2[1:])
     else:
+ catcol = 0
         records1 =
         p = grass.pipe_command('v.category', inp=mapname, layer=layer, option='print')
         for line in p.stdout:
@@ -172,15 +173,18 @@
     numcols = len(colnames) + len(extracolnames)

     # calculate percents if requested
- if units != '' and units in ['p', 'percent']:
- # calculate total area value
- areatot = 0
+ if units == 'percent' and option != 'coor':
+ # calculate total value
+ total = 0
         for r in records3:
- areatot += float(r[-1])
+ total += float(r[-1])

- # calculate area percentages
- records4 = [float(r[-1]) * 100 / areatot for r in records3]
- records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]
+ # calculate percentages
+ records4 = [float(r[-1]) * 100 / total for r in records3]
+ if type(records1[0]) == int:
+ records3 = [[r1] + [r4] for r1, r4 in zip(records1, records4)]
+ else:
+ records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]

     # sort results
     if options['sort']:

_______________________________________________
grass-commit mailing list
grass-commit@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

no problem, I’ll backport it.

Thanks.

···

On Mon, Feb 20, 2017 at 2:39 AM, Martin Landa <landa.martin@gmail.com> wrote:

Hi,

are you planning to backport bugfixes to relb72? Thanks, Ma

2017-02-20 1:15 GMT+01:00 <svn_grass@osgeo.org>:

Author: hcho
Date: 2017-02-19 16:15:14 -0800 (Sun, 19 Feb 2017)
New Revision: 70632

Modified:
grass/trunk/scripts/v.report/v.report.py
Log:
v.report: Fix unit=percent

Modified: grass/trunk/scripts/v.report/v.report.py

— grass/trunk/scripts/v.report/v.report.py 2017-02-19 23:40:29 UTC (rev 70631)
+++ grass/trunk/scripts/v.report/v.report.py 2017-02-20 00:15:14 UTC (rev 70632)
@@ -81,7 +81,7 @@
else:
extracolnames = [option]

  • if units in [‘p’, ‘percent’]:
  • if units == ‘percent’:
    unitsp = ‘meters’
    elif units:
    unitsp = units
    @@ -90,6 +90,7 @@

NOTE: we suppress -1 cat and 0 cat

if isConnection:

  • f = grass.vector_db(map=mapname)[int(layer)]
    p = grass.pipe_command(‘v.db.select’, quiet=True, map=mapname, layer=layer)
    records1 =
    catcol = -1
    @@ -97,12 +98,12 @@
    cols = line.rstrip(‘\r\n’).split(‘|’)
    if catcol == -1:
    for i in range(0, len(cols)):
  • if cols[i] == ‘cat’:
  • if cols[i] == f[‘key’]:
    catcol = i
    break
    if catcol == -1:
  • shouldn’t happen, but let’s do this

  • catcol = 0
  • grass.fatal(_("There is a table connected to input vector map ‘%s’, but "
  • “there is no key column ‘%s’.”) % (mapname, f[‘key’]))
    continue
    if cols[catcol] == ‘-1’ or cols[catcol] == ‘0’:
    continue
    @@ -115,7 +116,6 @@

if len(records1) == 0:
try:

  • f = grass.vector_db(map=mapname)[int(layer)]
    grass.fatal(_("There is a table connected to input vector map ‘%s’, but "
    "there are no categories present in the key column ‘%s’. Consider using "
    “v.to.db to correct this.”) % (mapname, f[‘key’]))
    @@ -142,6 +142,7 @@
    for r2 in records2:
    records3.append(filter(lambda r1: r1[catcol] == r2[0], records1)[0] + r2[1:])
    else:
  • catcol = 0
    records1 =
    p = grass.pipe_command(‘v.category’, inp=mapname, layer=layer, option=‘print’)
    for line in p.stdout:
    @@ -172,15 +173,18 @@
    numcols = len(colnames) + len(extracolnames)

calculate percents if requested

  • if units != ‘’ and units in [‘p’, ‘percent’]:
  • calculate total area value

  • areatot = 0
  • if units == ‘percent’ and option != ‘coor’:
  • calculate total value

  • total = 0
    for r in records3:
  • areatot += float(r[-1])
  • total += float(r[-1])
  • calculate area percentages

  • records4 = [float(r[-1]) * 100 / areatot for r in records3]
  • records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]
  • calculate percentages

  • records4 = [float(r[-1]) * 100 / total for r in records3]
  • if type(records1[0]) == int:
  • records3 = [[r1] + [r4] for r1, r4 in zip(records1, records4)]
  • else:
  • records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]

sort results

if options[‘sort’]:


grass-commit mailing list
grass-commit@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-commit


Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

Hi,

2017-02-20 8:58 GMT+01:00 Huidae Cho <grass4u@gmail.com>:

no problem, I'll backport it.

ok, thanks for taking care about it. Note that only bugfixes or
cosmetics issues (we are close to freeze period) should be backported
to relb72. After releasing 7.2.1 also non-bug (minor new
functionality) issues can be backported. It's good to note such
waiting backports on wiki [1]. Ma

[1] https://trac.osgeo.org/grass/wiki/Grass7Planning#a7.2.2tobebackported

> if cols[catcol] == '-1' or cols[catcol] == '0':
> continue
> @@ -115,7 +116,6 @@
>
> if len(records1) == 0:
> try:
> - f = grass.vector_db(map=mapname)[int(layer)]
> grass.fatal(_("There is a table connected to input
> vector map '%s', but "
> "there are no categories present in the
> key column '%s'. Consider using "
> "v.to.db to correct this.") % (mapname,
> f['key']))
> @@ -142,6 +142,7 @@
> for r2 in records2:
> records3.append(filter(lambda r1: r1[catcol] == r2[0],
> records1)[0] + r2[1:])
> else:
> + catcol = 0
> records1 =
> p = grass.pipe_command('v.category', inp=mapname, layer=layer,
> option='print')
> for line in p.stdout:
> @@ -172,15 +173,18 @@
> numcols = len(colnames) + len(extracolnames)
>
> # calculate percents if requested
> - if units != '' and units in ['p', 'percent']:
> - # calculate total area value
> - areatot = 0
> + if units == 'percent' and option != 'coor':
> + # calculate total value
> + total = 0
> for r in records3:
> - areatot += float(r[-1])
> + total += float(r[-1])
>
> - # calculate area percentages
> - records4 = [float(r[-1]) * 100 / areatot for r in records3]
> - records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]
> + # calculate percentages
> + records4 = [float(r[-1]) * 100 / total for r in records3]
> + if type(records1[0]) == int:
> + records3 = [[r1] + [r4] for r1, r4 in zip(records1,
> records4)]
> + else:
> + records3 = [r1 + [r4] for r1, r4 in zip(records1,
> records4)]
>
> # sort results
> if options['sort']:
>
> _______________________________________________
> grass-commit mailing list
> grass-commit@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-commit

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

sure. usually, I don’t backport, but I’ll check the wiki. Thanks.

···

On Mon, Feb 20, 2017 at 3:11 AM, Martin Landa <landa.martin@gmail.com> wrote:

Hi,

2017-02-20 8:58 GMT+01:00 Huidae Cho <grass4u@gmail.com>:

no problem, I’ll backport it.

ok, thanks for taking care about it. Note that only bugfixes or
cosmetics issues (we are close to freeze period) should be backported
to relb72. After releasing 7.2.1 also non-bug (minor new
functionality) issues can be backported. It’s good to note such
waiting backports on wiki [1]. Ma

[1] https://trac.osgeo.org/grass/wiki/Grass7Planning#a7.2.2tobebackported

if cols[catcol] == ‘-1’ or cols[catcol] == ‘0’:
continue
@@ -115,7 +116,6 @@

if len(records1) == 0:
try:

  • f = grass.vector_db(map=mapname)[int(layer)]
    grass.fatal(_("There is a table connected to input
    vector map ‘%s’, but "
    "there are no categories present in the
    key column ‘%s’. Consider using "
    “v.to.db to correct this.”) % (mapname,
    f[‘key’]))
    @@ -142,6 +142,7 @@
    for r2 in records2:
    records3.append(filter(lambda r1: r1[catcol] == r2[0],
    records1)[0] + r2[1:])
    else:
  • catcol = 0
    records1 =
    p = grass.pipe_command(‘v.category’, inp=mapname, layer=layer,
    option=‘print’)
    for line in p.stdout:
    @@ -172,15 +173,18 @@
    numcols = len(colnames) + len(extracolnames)

calculate percents if requested

  • if units != ‘’ and units in [‘p’, ‘percent’]:
  • calculate total area value

  • areatot = 0
  • if units == ‘percent’ and option != ‘coor’:
  • calculate total value

  • total = 0
    for r in records3:
  • areatot += float(r[-1])
  • total += float(r[-1])
  • calculate area percentages

  • records4 = [float(r[-1]) * 100 / areatot for r in records3]
  • records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]
  • calculate percentages

  • records4 = [float(r[-1]) * 100 / total for r in records3]
  • if type(records1[0]) == int:
  • records3 = [[r1] + [r4] for r1, r4 in zip(records1,
    records4)]
  • else:
  • records3 = [r1 + [r4] for r1, r4 in zip(records1,
    records4)]

sort results

if options[‘sort’]:


grass-commit mailing list
grass-commit@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-commit


Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa


Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

2017-02-20 9:19 GMT+01:00 Huidae Cho <grass4u@gmail.com>:

sure. usually, I don't backport, but I'll check the wiki. Thanks.

thanks for your effort. Would be nice if all devs would take care
about backports. Ma

>> > - f = grass.vector_db(map=mapname)[int(layer)]
>> > grass.fatal(_("There is a table connected to input
>> > vector map '%s', but "
>> > "there are no categories present in
>> > the
>> > key column '%s'. Consider using "
>> > "v.to.db to correct this.") %
>> > (mapname,
>> > f['key']))
>> > @@ -142,6 +142,7 @@
>> > for r2 in records2:
>> > records3.append(filter(lambda r1: r1[catcol] == r2[0],
>> > records1)[0] + r2[1:])
>> > else:
>> > + catcol = 0
>> > records1 =
>> > p = grass.pipe_command('v.category', inp=mapname,
>> > layer=layer,
>> > option='print')
>> > for line in p.stdout:
>> > @@ -172,15 +173,18 @@
>> > numcols = len(colnames) + len(extracolnames)
>> >
>> > # calculate percents if requested
>> > - if units != '' and units in ['p', 'percent']:
>> > - # calculate total area value
>> > - areatot = 0
>> > + if units == 'percent' and option != 'coor':
>> > + # calculate total value
>> > + total = 0
>> > for r in records3:
>> > - areatot += float(r[-1])
>> > + total += float(r[-1])
>> >
>> > - # calculate area percentages
>> > - records4 = [float(r[-1]) * 100 / areatot for r in records3]
>> > - records3 = [r1 + [r4] for r1, r4 in zip(records1, records4)]
>> > + # calculate percentages
>> > + records4 = [float(r[-1]) * 100 / total for r in records3]
>> > + if type(records1[0]) == int:
>> > + records3 = [[r1] + [r4] for r1, r4 in zip(records1,
>> > records4)]
>> > + else:
>> > + records3 = [r1 + [r4] for r1, r4 in zip(records1,
>> > records4)]
>> >
>> > # sort results
>> > if options['sort']:
>> >
>> > _______________________________________________
>> > grass-commit mailing list
>> > grass-commit@lists.osgeo.org
>> > https://lists.osgeo.org/mailman/listinfo/grass-commit
>>
>>
>>
>> --
>> Martin Landa
>> http://geo.fsv.cvut.cz/gwiki/Landa
>> http://gismentors.cz/mentors/landa
>
>

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa