[CC to grass-dev]
Nikos Alexandris wrote:
# faster/ easier way: use of the "grass.region()" function
rows = int(grass.region()['rows'])
cols = int(grass.region()['cols'])
In 7.0, these fields are already integers; r40555 should be
backported.
--
Glynn Clements <glynn@gclements.plus.com>
On Mon, May 31, 2010 at 3:50 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:
[CC to grass-dev]
Nikos Alexandris wrote:
\# faster/ easier way: use of the "grass\.region\(\)" function
rows = int\(grass\.region\(\)\['rows'\]\)
cols = int\(grass\.region\(\)\['cols'\]\)
In 7.0, these fields are already integers; r40555 should be
backported.
AFAIK it has been backported some time ago.
http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/lib/python/core.py#L503
Markus
Markus Neteler wrote:
>> # faster/ easier way: use of the "grass.region()" function
>> rows = int(grass.region()['rows'])
>> cols = int(grass.region()['cols'])
>
> In 7.0, these fields are already integers; r40555 should be
> backported.
AFAIK it has been backported some time ago.
http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/lib/python/core.py#L503
Okay; change that to "I should 'svn update' the other branches more
often", then 
--
Glynn Clements <glynn@gclements.plus.com>
On Tuesday 01 of June 2010 05:46:22 Glynn Clements wrote:
Markus Neteler wrote:
> >> # faster/ easier way: use of the "grass.region()" function
> >> rows = int(grass.region()['rows'])
> >> cols = int(grass.region()['cols'])
> >
> > In 7.0, these fields are already integers; r40555 should be
> > backported.
>
> AFAIK it has been backported some time ago.
>
> http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/lib/
> python/core.py#L503
Okay; change that to "I should 'svn update' the other branches more
often", then 
This means it should be like:
rows = grass.region()['rows']
cols = grass.region()['cols']
Right?
Nikos
Nikos Alexandris wrote:
> > >> # faster/ easier way: use of the "grass.region()" function
> > >> rows = int(grass.region()['rows'])
> > >> cols = int(grass.region()['cols'])
> > >
> > > In 7.0, these fields are already integers; r40555 should be
> > > backported.
> >
> > AFAIK it has been backported some time ago.
> >
> > http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/lib/
> > python/core.py#L503
>
> Okay; change that to "I should 'svn update' the other branches more
> often", then 
This means it should be like:
rows = grass.region()['rows']
cols = grass.region()['cols']
Right?
Right; although you should store the result of grass.region() to avoid
redundant g.region commands, i.e.:
rgn = grass.region()
rows = rgn['rows']
cols = rgn['cols']
--
Glynn Clements <glynn@gclements.plus.com>
Nikos Alexandris wrote:
> > > >> rows = int(grass.region()['rows'])
> > > >> cols = int(grass.region()['cols'])
Glynn:
> > > > In 7.0, these fields are already integers; r40555 should be
> > > > backported.
Markus:
> > > AFAIK it has been backported some time ago.
> > > http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/
> > > lib/ python/core.py#L503
Glynn:
> > Okay; change that to "I should 'svn update' the other branches more
> > often", then 
Nikos:
> This means it should be like:
>
> rows = grass.region()['rows']
> cols = grass.region()['cols']
>
> Right?
Glynn Clements wrote:
Right; although you should store the result of grass.region() to avoid
redundant g.region commands, i.e.:
rgn = grass.region()
rows = rgn['rows']
cols = rgn['cols']
Is python's "int()" truncating or rounding up values? The question came to me
while thinking of r.mapcalc's respective functions ( i.e. "int() != round()" )
Nikos
Nikos Alexandris wrote:
Nikos Alexandris wrote:
> > > > >> rows = int(grass.region()['rows'])
> > > > >> cols = int(grass.region()['cols'])
Is python's "int()" truncating or rounding up values? The question came to me
while thinking of r.mapcalc's respective functions ( i.e. "int() != round()" )
In this case, neither; it's just converting strings to integers. The
rows and cols values in the g.region output will always be integers.
If you pass a floating-point value to int(), it will be truncated
(i.e. rounded towards zero):
> int(1.9)
1
> int(-1.9)
-1
If you pass a string containing a decimal point to int(), it will
raise an exception:
> int("1.9")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.9'
--
Glynn Clements <glynn@gclements.plus.com>
Nikos Alexandris wrote:
> > > > > >> rows = int(grass.region()['rows'])
> > > > > >> cols = int(grass.region()['cols'])
>
> Is python's "int()" truncating or rounding up values? The question came
> to me while thinking of r.mapcalc's respective functions ( i.e. "int()
> != round()" )
Glynn Clements wrote:
In this case, neither;

it's just converting strings to integers. The
rows and cols values in the g.region output will always be integers.
Right... needles question (=I need to rest a bit).
If you pass a floating-point value to int(), it will be truncated
(i.e. rounded towards zero):
> int(1.9)
1
> int(-1.9)
-1
If you pass a string containing a decimal point to int(), it will
raise an exception:
> int("1.9")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.9'
Thanks for details, Nikos