[GRASS-dev] [GRASS GIS] #2431: vector_what fails with multiple layer/cat

#2431: vector_what fails with multiple layer/cat
-------------------------+--------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 6.4.5
Component: Vector | Version: svn-releasebranch70
Keywords: | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
in a vector with multiple cat per point (in this case Point Id=3 has
4 cats:
[(layer=1, cat=311),(layer=1, cat=312),(layer=21, cat=321),(layer=2,
cat=322)]

while v.what gives a correct output:

{{{
v.what -a -g map=test@cavriago layer=2 coordinates=2.0,0.0
East=2
North=0
Map=test
Mapset=cavriago
Type=Point
Id=3
Layer=1
Category=311
Driver=sqlite
Database=D:\GIS_db\Gauss_Boaga\cavriago\sqlite.db
Table=test1
Key_column=cat
cat=311
t1=311
t2=
Layer=1
Category=312
Driver=sqlite
Database=D:\GIS_db\Gauss_Boaga\cavriago\sqlite.db
Table=test1
Key_column=cat
cat=312
t1=312
t2=
Layer=2
Category=321
Driver=sqlite
Database=D:\GIS_db\Gauss_Boaga\cavriago\sqlite.db
Table=test2
Key_column=cat
cat=321
l2=321
l3=
Layer=2
Category=322
Driver=sqlite
Database=D:\GIS_db\Gauss_Boaga\cavriago\sqlite.db
Table=test2
Key_column=cat
cat=322
l2=322
l3=layer2
}}}

vector_what makes a mess (It returns a single dictionary mixing up first
cat -> 'Category': 311, 'Layer': 1
and last cat -> 'Attributes': {'l2': '322', 'l3': 'layer2', 'cat': '322'}

{{{
from grass.script.vector import vector_what
vector_what(map='test', coord=(2.0,0.0), distance=0.0, ttype=None)
[{'Category': 311, 'Map': 'test', 'Layer': 1, 'Key_column': 'cat',
'Database': 'D:\\GIS_db\\Gauss_Boaga\\cavriago\\sqlite.db', 'Type':
'Point', 'Driver': 'sqlite', 'Table': 'test1', 'Attributes': {'l2': '322',
'l3': 'layer2', 'cat': '322'}, 'Mapset': 'cavriago', 'Id': '3'}]
}}}

This bug influences "Query result" dialog in wxGui while "Aggiornamento
attributi" in vector editing works correctly.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2431&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
-------------------------+--------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 6.4.5
Component: Vector | Version: svn-releasebranch70
Keywords: | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by annakrat):

Module v.what should output the result in a more hierarchical way,
otherwise it's really difficult to parse. The grass.vector_what function
was rewritten multiple times and it's still not correct. I suggest adding
another format, the easiest is json, it's easy to write and python can
read it too (json package). xml would be much more difficult. I already
started it, I just need more time for testing.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2431#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------
Changes (by annakrat):

  * keywords: => query, v.what
  * milestone: 6.4.5 => 7.0.0

Comment:

I attached a patch which adds new flag to v.what to print json and
simplifies vector_what to load json. I still need to test it more but I
would welcome if anyone could test it too on different types of vector
data with or without attributes.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2431#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by annakrat):

Replying to [comment:2 annakrat]:
> I attached a patch which adds new flag to v.what to print json and
simplifies vector_what to load json. I still need to test it more but I
would welcome if anyone could test it too on different types of vector
data with or without attributes.

Done in r62469. Testing welcome.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2431#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by mmetz):

Replying to [comment:3 annakrat]:
> Replying to [comment:2 annakrat]:
> > I attached a patch which adds new flag to v.what to print json and
simplifies vector_what to load json. I still need to test it more but I
would welcome if anyone could test it too on different types of vector
data with or without attributes.
>
> Done in r62469. Testing welcome.

Not working in RHEL 6.x and derivates with python 2.6.6:
`object_pairs_hook` is not a valid argument.

{{{
result = json.loads(ret, object_pairs_hook=orderedDict)
   File "/usr/lib64/python2.6/json/__init__.py", line 318, in
loads

return cls(encoding=encoding, **kw).decode(s)
TypeError
:
__init__() got an unexpected keyword argument
'object_pairs_hook'
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by annakrat):

Replying to [comment:4 mmetz]:
>
> Not working in RHEL 6.x and derivates with python 2.6.6:
`object_pairs_hook` is not a valid argument.
>
Thanks for catching this, should be fixed in r62645.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by mmetz):

Replying to [comment:5 annakrat]:
> Replying to [comment:4 mmetz]:
> >
> > Not working in RHEL 6.x and derivates with python 2.6.6:
`object_pairs_hook` is not a valid argument.
> >
> Thanks for catching this, should be fixed in r62645.

Unfortunately not:

{{{
   File "/home/metz/src/grass-7.1.svn/dist.x86_64-unknown-
linux-gnu/etc/python/grass/script/vector.py", line 380, in
vector_what

result = json.loads(ret, **kwargs)
   File "/usr/lib64/python2.6/json/__init__.py", line 307, in
loads

return _default_decoder.decode(s)
   File "/usr/lib64/python2.6/json/decoder.py", line 319, in
decode

obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/lib64/python2.6/json/decoder.py", line 336, in
raw_decode

obj, end = self._scanner.iterscan(s, **kw).next()
   File "/usr/lib64/python2.6/json/scanner.py", line 55, in
iterscan

rval, next_pos = action(m, context)
   File "/usr/lib64/python2.6/json/decoder.py", line 183, in
JSONObject

value, end = iterscan(s, idx=end, context=context).next()
   File "/usr/lib64/python2.6/json/scanner.py", line 55, in
iterscan

rval, next_pos = action(m, context)
   File "/usr/lib64/python2.6/json/decoder.py", line 193, in
JSONObject

raise ValueError(errmsg("Expecting , delimiter", s, end -
1))
ValueError
:
Expecting , delimiter: line 1 column 27 (char 27)
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by annakrat):

Replying to [comment:6 mmetz]:
> Replying to [comment:5 annakrat]:
> > Replying to [comment:4 mmetz]:
> > >
> > > Not working in RHEL 6.x and derivates with python 2.6.6:
`object_pairs_hook` is not a valid argument.
> > >
> > Thanks for catching this, should be fixed in r62645.
>
> Unfortunately not:
>
This happens on python 2.7 (see #2479), so it's a different problem. I
can't reproduce this error, could you run the same query with v.what with
json flag and give me the output?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by mmetz):

Replying to [comment:7 annakrat]:
> Replying to [comment:6 mmetz]:
> > Replying to [comment:5 annakrat]:
> > > Replying to [comment:4 mmetz]:
> > > >
> > > > Not working in RHEL 6.x and derivates with python 2.6.6:
`object_pairs_hook` is not a valid argument.
> > > >
> > > Thanks for catching this, should be fixed in r62645.
> >
> > Unfortunately not:
> >
> This happens on python 2.7 (see #2479), so it's a different problem.

Yes, it's a different problem, but also occurs with python 2.6.

> I can't reproduce this error, could you run the same query with v.what
with json flag and give me the output?

The problem occurred in latlon locations, fixed in r62654.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
---------------------------+------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Keywords: query, v.what | Platform: All
      Cpu: Unspecified |
---------------------------+------------------------------------------------

Comment(by annakrat):

Replying to [comment:8 mmetz]:
> The problem occurred in latlon locations, fixed in r62654.

Thanks.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#2431: vector_what fails with multiple layer/cat
-----------------------+----------------------------------------------------
  Reporter: artegion | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.0.0
Component: Vector | Version: svn-releasebranch70
Resolution: fixed | Keywords: query, v.what
  Platform: All | Cpu: Unspecified
-----------------------+----------------------------------------------------
Changes (by mmetz):

  * status: new => closed
  * resolution: => fixed

Comment:

Replying to [comment:9 annakrat]:
> Replying to [comment:8 mmetz]:
> > The problem occurred in latlon locations, fixed in r62654.
>
> Thanks.

Seems to work, and has already been backported to G7.0, closing.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2431#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>