[GRASS-dev] ERROR grass addon v/r.surf.nnbathy using a lat/lon location

Dear all,

I am using r.surf.nnbathy (on GRASS 7.4)

Using a projected location (meters) I obtain a result

Using lat/lon location I see the following error:

Traceback (most recent call last):
File
“/home/roberto/.grass7/addons/scripts/r.surf.nnbathy”, line
80, in
main()
File
“/home/roberto/.grass7/addons/scripts/r.surf.nnbathy”, line
74, in main
obj = Nnbathy_raster(options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 107, in init
Nnbathy.init(self, options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 13, in init
self.region()
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 20, in region
reg_N = float(kv[‘north’])
ValueError: invalid literal for float(): 47:00:29.111155N

I think the error is due to the https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.surf.nnbathy/nnbathy.py file and in particular to the region() function

reg = grass.read_command(“g.region”, flags=‘p’)

kv = grass.parse_key_val(reg, sep=‘:’)

reg_N = float(kv[‘north’])

reg_W = float(kv[‘west’])

reg_S = float(kv[‘south’])

reg_E = float(kv[‘east’])

nsres = float(kv[‘nsres’])

ewres = float(kv[‘ewres’])

perhaps this can be a solution:

in_region = gscript.region()

reg_E=float(in_region[‘e’])

reg_W=float(in_region[‘w’])

reg_N=float(in_region[‘s’])

reg_S=float(in_region[‘s’])

nsres = float(in_region[‘nsres’])

ewres = float(in_region[‘ewres’])

If you agree I will do some test and I can update the add-on

Any suggestions?

Thanks in advanced for your help
R

I have tested my solution and it works.
Can I do the push on SVN? My question is for Martin Landa who is mentor for the authors of the command and did the last commit of nnbathy.py command?

I found also two more problem in the v.surf.nnbathy command.

  1. The command crash. It is probaby due to the v.out.ascii -r command (the -r option do not works correctly, at least on GRASS 7.4). It is possible to remove the -r flag in this command and the v.in.nnbathy works correctly, even if the output is different. Perhaps is a better output, because it use also the points outside the computational region for the interpolation.

  2. An other problem is due to the command to write output ascii file for interpolation → fout.write(parts[0]+’ ‘+parts[1]+’ ‘+parts[3]) is valid only for 2D geometry while for 3D geometry the correct command is fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[4])

I think we need an if condition to check if the geometry is 2 or 3D. I have no idea of a possible python command… I will do some search… Have you any suggestion?

R

···

2018-03-23 18:05 GMT+01:00 Roberto Marzocchi <roberto.marzocchi@gmail.com>:

Dear all,

I am using r.surf.nnbathy (on GRASS 7.4)

Using a projected location (meters) I obtain a result

Using lat/lon location I see the following error:

Traceback (most recent call last):
File
“/home/roberto/.grass7/addons/scripts/r.surf.nnbathy”, line
80, in
main()
File
“/home/roberto/.grass7/addons/scripts/r.surf.nnbathy”, line
74, in main
obj = Nnbathy_raster(options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 107, in init
Nnbathy.init(self, options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 13, in init
self.region()
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 20, in region
reg_N = float(kv[‘north’])
ValueError: invalid literal for float(): 47:00:29.111155N

I think the error is due to the https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.surf.nnbathy/nnbathy.py file and in particular to the region() function

reg = grass.read_command(“g.region”, flags=‘p’)

kv = grass.parse_key_val(reg, sep=‘:’)

reg_N = float(kv[‘north’])

reg_W = float(kv[‘west’])

reg_S = float(kv[‘south’])

reg_E = float(kv[‘east’])

nsres = float(kv[‘nsres’])

ewres = float(kv[‘ewres’])

perhaps this can be a solution:

in_region = gscript.region()

reg_E=float(in_region[‘e’])

reg_W=float(in_region[‘w’])

reg_N=float(in_region[‘s’])

reg_S=float(in_region[‘s’])

nsres = float(in_region[‘nsres’])

ewres = float(in_region[‘ewres’])

If you agree I will do some test and I can update the add-on

Any suggestions?

Thanks in advanced for your help

R

I have no idea of a possible python command.. I will do some >search.. Have

you any suggestion?

Have a look into pygrass

https://grass.osgeo.org/grass74/manuals/libpython/pygrass_vector.html

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Dev-f3991897.html

from grass.pygrass.vector import VectorTopo
pnt = VectorTopo(options[‘input’])

pnt.open(mode=‘r’)
test=pnt.read(1)
if test.is2D==True:

fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[3])

else:

fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[4])

Maybe not the best code… but it seem to works…

···

2018-03-26 12:21 GMT+02:00 Helmut Kudrnovsky <hellik@web.de>:

I have no idea of a possible python command… I will do some >search… Have
you any suggestion?

Have a look into pygrass

https://grass.osgeo.org/grass74/manuals/libpython/pygrass_vector.html


best regards
Helmut

Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Dev-f3991897.html


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

On 26 March 2018 at 14:50, Roberto Marzocchi
<roberto.marzocchi@gmail.com> wrote:

from grass.pygrass.vector import VectorTopo
pnt = VectorTopo(options['input'])
pnt.open(mode='r')
test=pnt.read(1)
if test.is2D==True:
   fout.write(parts[0]+' '+parts[1]+' '+parts[3])
else:
   fout.write(parts[0]+' '+parts[1]+' '+parts[4])

it is better not use this way to concatenate string, but it is better
to use .format function

Maybe not the best code.. but it seem to works..

--
ciao
Luca

www.lucadelu.org

Hi Luca,

fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[3]) → is part of the actual command.

I can do debug, but I would like to be cautious in completly rewriting the module without the endorsement of the authors.

R

···

2018-03-27 12:06 GMT+02:00 Luca Delucchi <lucadeluge@gmail.com>:

On 26 March 2018 at 14:50, Roberto Marzocchi
<roberto.marzocchi@gmail.com> wrote:

from grass.pygrass.vector import VectorTopo
pnt = VectorTopo(options[‘input’])
pnt.open(mode=‘r’)
test=pnt.read(1)
if test.is2D==True:
fout.write(parts[0]+’ ‘+parts[1]+’ ‘+parts[3])
else:
fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[4])

it is better not use this way to concatenate string, but it is better
to use .format function

Maybe not the best code… but it seem to works…


ciao
Luca

www.lucadelu.org

Hi,

2018-03-27 14:48 GMT+02:00 Roberto Marzocchi <roberto.marzocchi@gmail.com>:

fout.write(parts[0]+' '+parts[1]+' '+parts[3]) --> is part of the
actual command.

I can do debug, but I would like to be cautious in completly rewriting the
module without the endorsement of the authors.

please feel free to provide patch and attach it to a reported ticket. Martin

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

Ok. I do a commit with some changes to nnbathy.py command:

  • correction in read region
  • correction due to the problem of v.out.ascii -r
  • correction suggested by Luca for string concatenation

A problem remains open when using v.surf.nnbathy from GUI because the name of the vector map with @mapset seem to be a problem…

Fetching data…
WARNING: Illegal filename ztd_temp@meteo. Character <@> not allowed.
Traceback (most recent call last):
File
“/home/roberto/.grass7/addons/scripts/v.surf.nnbathy”, line
115, in
main()
File
“/home/roberto/.grass7/addons/scripts/v.surf.nnbathy”, line
106, in main
obj = Nnbathy_vector(options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 128, in init
self._load(options)
File “/home/roberto/.grass7/addons/etc/v.surf.nnbathy/nnba
thy.py”, line 171, in _load
grass.fatal_error(“Invalid input: %s” % e)
AttributeError: ‘module’ object has no attribute
‘fatal_error’

Removing the mapset from input name (ztd_temp@meteo → ztd_temp) the module works correctly. I do not know how to solve this problem. Perhaps it has an easy solution for you.

All the best,
R

···

2018-03-27 21:11 GMT+02:00 Martin Landa <landa.martin@gmail.com>:

Hi,

2018-03-27 14:48 GMT+02:00 Roberto Marzocchi <roberto.marzocchi@gmail.com>:

fout.write(parts[0]+’ ‘+parts[1]+’ '+parts[3]) → is part of the
actual command.

I can do debug, but I would like to be cautious in completly rewriting the
module without the endorsement of the authors.

please feel free to provide patch and attach it to a reported ticket. Martin


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

Removing the mapset from input name (ztd_temp@meteo --> >ztd_temp) the

module works correctly. I do not know how to solve >this problem. Perhaps it
has an easy solution for you.

Just have a look into GRASS scripts, e.g.

https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.habitat.dem/v.habitat.dem.py#L125

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Dev-f3991897.html

Thanks Helmut. I have corrected the script.

Now it works also from GUI

R

···

2018-03-29 17:48 GMT+02:00 Helmut Kudrnovsky <hellik@web.de>:

Removing the mapset from input name (ztd_temp@meteo → >ztd_temp) the
module works correctly. I do not know how to solve >this problem. Perhaps it
has an easy solution for you.

Just have a look into GRASS scripts, e.g.

https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.habitat.dem/v.habitat.dem.py#L125


best regards
Helmut

Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Dev-f3991897.html


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