Opened 10 years ago
Closed 10 years ago
#2431 closed defect (fixed)
vector_what fails with multiple layer/cat
| Reported by: | artegion | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 7.0.0 |
| Component: | Vector | Version: | svn-releasebranch70 |
| Keywords: | query, v.what | Cc: | |
| CPU: | Unspecified | Platform: | All |
Description
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.
Attachments (1)
Change History (11)
comment:1 by , 10 years ago
follow-up: 3 comment:2 by , 10 years ago
| Keywords: | query v.what added |
|---|---|
| Milestone: | 6.4.5 → 7.0.0 |
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.
follow-up: 4 comment:3 by , 10 years ago
follow-up: 5 comment:4 by , 10 years ago
Replying to annakrat:
Replying to 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'
follow-up: 6 comment:5 by , 10 years ago
follow-up: 7 comment:6 by , 10 years ago
Replying to annakrat:
Replying to mmetz:
Not working in RHEL 6.x and derivates with python 2.6.6:
object_pairs_hookis 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)
follow-up: 8 comment:7 by , 10 years ago
Replying to mmetz:
Replying to annakrat:
Replying to mmetz:
Not working in RHEL 6.x and derivates with python 2.6.6:
object_pairs_hookis 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?
follow-up: 9 comment:8 by , 10 years ago
Replying to annakrat:
Replying to mmetz:
Replying to annakrat:
Replying to mmetz:
Not working in RHEL 6.x and derivates with python 2.6.6:
object_pairs_hookis 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.
follow-up: 10 comment:9 by , 10 years ago
comment:10 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |

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.