Opened 10 years ago
Closed 6 years ago
#2413 closed defect (fixed)
pygrass: number_of wrong function associated
| Reported by: | artegion | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.4.5 |
| Component: | Python | Version: | svn-releasebranch70 |
| Keywords: | pygrass vector | Cc: | |
| CPU: | Unspecified | Platform: | All |
Description
In _NUMOF dictionary (pygrass/vector/init.py )'lines' key is associated to libvect.Vect_get_num_line_points function instead of libvect.Vect_get_num_lines
Change History (14)
follow-up: 2 comment:1 by , 10 years ago
follow-up: 3 comment:2 by , 10 years ago
| Keywords: | pygrass vector added |
|---|
Replying to lucadelu:
Replying to artegion:
In _NUMOF dictionary (pygrass/vector/init.py )'lines' key is associated to libvect.Vect_get_num_line_points function instead of libvect.Vect_get_num_lines
Fixed in r61862. If it is correct it should be backported.
Mmh, I'm still not convinced running the code below on NC:
from pprint import pprint
from grass.pygrass.vector import VectorTopo
from grass.pygrass.vector import _NUMOF
from grass.pygrass.modules.shortcuts import vector as v
def test_vect_features(vectname):
print(vectname)
with VectorTopo(vectname, mode='r') as vect:
for key in sorted(_NUMOF):
print(" %20s %6d" % (key, vect.number_of('points')))
print(' primitives:')
pprint(vect.num_primitives())
v.info(vectname)
print
test_vect_features('schools')
test_vect_features('streams')
_NUMOF is defined (http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/pygrass/vector/__init__.py#L24):
_NUMOF = {"areas": libvect.Vect_get_num_areas,
"dblinks": libvect.Vect_get_num_dblinks,
"faces": libvect.Vect_get_num_faces,
"holes": libvect.Vect_get_num_holes,
"islands": libvect.Vect_get_num_islands,
"kernels": libvect.Vect_get_num_kernels,
"lines": libvect.Vect_get_num_lines,
"points": libvect.Vect_get_num_line_points,
"nodes": libvect.Vect_get_num_nodes,
"updated_lines": libvect.Vect_get_num_updated_lines,
"updated_nodes": libvect.Vect_get_num_updated_nodes,
"volumes": libvect.Vect_get_num_volumes}
And this is what I got:
schools
areas 5
dblinks 5
faces 5
holes 5
islands 5
kernels 5
lines 5
nodes 5
points 5
updated_lines 5
updated_nodes 5
volumes 5
primitives:
{'area': 0,
'boundary': 0,
'centroid': 0,
'face': 0,
'kernel': 0,
'line': 0,
'point': 167,
'volume': 0}
+----------------------------------------------------------------------------+
| Name: schools |
| Mapset: PERMANENT |
| Location: nc_basic_spm_grass7 |
| Database: /home/pietro/docdat/gis |
| Title: Wake County schools (points map) |
| Map scale: 1:1 |
| Name of creator: helena |
| Organization: NC OneMap |
| Source date: Tue Nov 7 19:34:09 2006 |
| Timestamp (first layer): none |
|----------------------------------------------------------------------------|
| Map format: native |
|----------------------------------------------------------------------------|
| Type of map: vector (level: 2) |
| |
| Number of points: 167 Number of centroids: 0 |
| Number of lines: 0 Number of boundaries: 0 |
| Number of areas: 0 Number of islands: 0 |
| |
| Map is 3D: No |
| Number of dblinks: 1 |
| |
| Projection: Lambert Conformal Conic |
| |
| N: 248159.84441077 S: 203559.01136227 |
| E: 671714.55110786 W: 619215.13388253 |
| |
| Digitization threshold: 0 |
| Comment: |
| |
+----------------------------------------------------------------------------+
streams
areas 5
dblinks 5
faces 5
holes 5
islands 5
kernels 5
lines 5
nodes 5
points 5
updated_lines 5
updated_nodes 5
volumes 5
primitives:
{'area': 0,
'boundary': 0,
'centroid': 0,
'face': 0,
'kernel': 0,
'line': 8554,
'point': 0,
'volume': 0}
+----------------------------------------------------------------------------+
| Name: streams |
| Mapset: PERMANENT |
| Location: nc_basic_spm_grass7 |
| Database: /home/pietro/docdat/gis |
| Title: South-West Wake streams (lines map) |
| Map scale: 1:1 |
| Name of creator: helena |
| Organization: NC OneMap |
| Source date: Tue Nov 7 19:37:02 2006 |
| Timestamp (first layer): none |
|----------------------------------------------------------------------------|
| Map format: native |
|----------------------------------------------------------------------------|
| Type of map: vector (level: 2) |
| |
| Number of points: 0 Number of centroids: 0 |
| Number of lines: 8554 Number of boundaries: 0 |
| Number of areas: 0 Number of islands: 0 |
| |
| Map is 3D: No |
| Number of dblinks: 1 |
| |
| Projection: Lambert Conformal Conic |
| |
| N: 228882.03322323 S: 214637.98658874 |
| E: 645264.23103886 W: 629851.88519177 |
| |
| Digitization threshold: 0 |
| Comment: |
| |
+----------------------------------------------------------------------------+
So it is not clear to me what is not working, but I don't think that it is correct...
follow-up: 4 comment:3 by , 10 years ago
Replying to zarch:
Replying to lucadelu:
Mmh, I'm still not convinced running the code below on NC:
maybe the test_vect_features is wrong, I changed as this
def test_vect_features(vectname):
print(vectname)
with VectorTopo(vectname, mode='r') as vect:
for key in sorted(_NUMOF):
print(" %20s %6d" % (key, vect.number_of(key)))
print(' primitives:')
pprint(vect.num_primitives())
v.info(vectname)
print
this is mine output
schools
areas 0
dblinks 1
faces 0
holes 0
islands 0
kernels 0
lines 167
nodes 0
points 5
updated_lines 0
updated_nodes 0
volumes 0
primitives:
{'area': 0,
'boundary': 0,
'centroid': 0,
'face': 0,
'kernel': 0,
'line': 0,
'point': 167,
'volume': 0}
+----------------------------------------------------------------------------+
| Name: schools |
| Mapset: PERMANENT |
| Location: nc_basic_spm_grass7 |
| Database: /home/lucadelu/grassdata |
| Title: Wake County schools (points map) |
| Map scale: 1:1 |
| Name of creator: helena |
| Organization: NC OneMap |
| Source date: Tue Nov 7 19:34:09 2006 |
| Timestamp (first layer): none |
|----------------------------------------------------------------------------|
| Map format: native |
|----------------------------------------------------------------------------|
| Type of map: vector (level: 2) |
| |
| Number of points: 167 Number of centroids: 0 |
| Number of lines: 0 Number of boundaries: 0 |
| Number of areas: 0 Number of islands: 0 |
| |
| Map is 3D: No |
| Number of dblinks: 1 |
| |
| Projection: Lambert Conformal Conic |
| |
| N: 248159.84441077 S: 203559.01136227 |
| E: 671714.55110786 W: 619215.13388253 |
| |
| Digitization threshold: 0 |
| Comment: |
| |
+----------------------------------------------------------------------------+
streams
areas 0
dblinks 1
faces 0
holes 0
islands 0
kernels 0
lines 8554
nodes 8645
points 5
updated_lines 0
updated_nodes 0
volumes 0
primitives:
{'area': 0,
'boundary': 0,
'centroid': 0,
'face': 0,
'kernel': 0,
'line': 8554,
'point': 0,
'volume': 0}
+----------------------------------------------------------------------------+
| Name: streams |
| Mapset: PERMANENT |
| Location: nc_basic_spm_grass7 |
| Database: /home/lucadelu/grassdata |
| Title: South-West Wake streams (lines map) |
| Map scale: 1:1 |
| Name of creator: helena |
| Organization: NC OneMap |
| Source date: Tue Nov 7 19:37:02 2006 |
| Timestamp (first layer): none |
|----------------------------------------------------------------------------|
| Map format: native |
|----------------------------------------------------------------------------|
| Type of map: vector (level: 2) |
| |
| Number of points: 0 Number of centroids: 0 |
| Number of lines: 8554 Number of boundaries: 0 |
| Number of areas: 0 Number of islands: 0 |
| |
| Map is 3D: No |
| Number of dblinks: 1 |
| |
| Projection: Lambert Conformal Conic |
| |
| N: 228882.03322323 S: 214637.98658874 |
| E: 645264.23103886 W: 629851.88519177 |
| |
| Digitization threshold: 0 |
| Comment: |
| |
+----------------------------------------------------------------------------+
So it is not clear to me what is not working, but I don't think that it is correct...
It seems better, but it is still strange the result of schools map (lines=167,points=5)
follow-up: 5 comment:4 by , 10 years ago
Replying to lucadelu:
It seems better, but it is still strange the result of schools map (lines=167,points=5)
Reading the documentation it is more clear, the description of function Vect_get_num_lines is:
Fetch number of features (points, lines, boundaries, centroids) in vector map
comment:5 by , 10 years ago
Replying to lucadelu:
Replying to lucadelu:
It seems better, but it is still strange the result of schools map (lines=167,points=5)
Reading the documentation it is more clear, the description of function Vect_get_num_lines is:
Fetch number of features (points, lines, boundaries, centroids) in vector map
It seems wrong use of Vect_get_num_line_points function in _NUMOF.
Vect_get_num_line_points: Get number of line points and takes a pointer to line_pnts structure (not a pointer to Map_info struct).
the correct form of _NUMOF shoud be
_NUMOF = {"areas": libvect.Vect_get_num_areas,
"dblinks": libvect.Vect_get_num_dblinks,
"faces": libvect.Vect_get_num_faces,
"holes": libvect.Vect_get_num_holes,
"islands": libvect.Vect_get_num_islands,
"kernels": libvect.Vect_get_num_kernels,
"lines": libvect.Vect_get_num_lines,
"nodes": libvect.Vect_get_num_nodes,
"updated_lines": libvect.Vect_get_num_updated_lines,
"updated_nodes": libvect.Vect_get_num_updated_nodes,
"volumes": libvect.Vect_get_num_volumes}
comment:7 by , 9 years ago
| Milestone: | → 6.4.6 |
|---|
comment:8 by , 8 years ago
| Milestone: | 6.4.6 → 7.0.4 |
|---|
comment:9 by , 8 years ago
These two are wrong:
"lines": libvect.Vect_get_num_lines,
"points": libvect.Vect_get_num_line_points,
Vect_get_num_linesreturns number of all features (points, lines, centroids, boundaries, kernels, and faces)Vect_get_num_line_pointsreturns number of vertices of given feature
For 2D feature types you can use Vect_get_num_primitives
comment:11 by , 8 years ago
| Milestone: | 7.0.4 → 7.0.5 |
|---|
comment:12 by , 8 years ago
| Milestone: | 7.0.5 → 7.0.6 |
|---|
comment:13 by , 6 years ago
| Milestone: | 7.0.6 → 7.0.7 |
|---|
comment:14 by , 6 years ago
| Milestone: | 7.0.7 → 7.4.5 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Already fixed.

Replying to artegion:
Fixed in r61862. If it is correct it should be backported.
Thanks