[GRASS-dev] Vect_cidx_find_all unexpected result and boundary right/left

Pietro peter.zamb at gmail.com
Mon Sep 28 09:16:36 PDT 2015


Dear devs,

I'm playing with vector features and categories. I'm creating a vector
map for testing, almost a copy and paste from Soeren's function, the
main differenceis that I added different categories for each geometry
feature.

Then If I'm looking for feature with the category number == 8, and I ask for:
- a libvect.GV_AREA, the Vect_cidx_find_all function return an Ilist
that contains 3, but 3 is a point with cat == 3 and not 8!
- a libvect.GV_CENTROID, everything it is fine

Why if I'm using libvect.GV_AREA Vect_cidx_find_all return 3 and not
an empty ilist?
What is it the meaning of the returned value?

Then If I play with the Boundary instance both sides (left and right)
are 0, Instead I'm expecting the right side shouldn't be empty.

Do you have any ideas?

Pietro

Bellow is reported a sample of code to reproduce it.


{{{
import grass.lib.vector as libvect

from grass.pygrass.vector import VectorTopo
from grass.pygrass.vector.geometry import Point, Line, Centroid, Boundary
from grass.pygrass.vector.basic import Ilist


def create_test_vector_map2(map_name="test_vector2", overwrite=False):
    """This functions creates a vector map layer with points, lines, boundaries,
       centroids, areas, isles and attributes for testing purposes

       This should be used in doc and unit tests to create location/mapset
       independent vector map layer. This map includes 3 points, 3 lines,
       11 boundaries and 4 centroids. The attribute table contains cat, name
       and value columns.

        param map_name: The vector map name that should be used



                                  P1 P2 P3
           6                       *  *  *
           5
           4    _______ ___ ___   L1 L2 L3
        Y  3   |A1___ *|  *|  *|   |  |  |
           2   | |A2*| |   |   |   |  |  |
           1   | |___| |A3 |A4 |   |  |  |
           0   |_______|___|___|   |  |  |
          -1
            -1 0 1 2 3 4 5 6 7 8 9 10 12 14
                           X
    """
    cols = [(u'cat', 'INTEGER PRIMARY KEY'),
            (u'name','varchar(50)'),
            (u'value', 'double precision')]
    with VectorTopo(map_name, mode='w', tab_name=map_name,
                    tab_cols=cols, overwrite=overwrite) as vect:

        # Write 3 points
        vect.write(Point(10, 6), cat=1, attrs=("point", 1))
        vect.write(Point(12, 6), cat=2)
        vect.write(Point(14, 6), cat=3)
        # Write 3 lines
        vect.write(Line([(10, 4), (10, 2), (10,0)]), cat=4, attrs=("line", 2))
        vect.write(Line([(12, 4), (12, 2), (12,0)]), cat=5)
        vect.write(Line([(14, 4), (14, 2), (14,0)]), cat=6)
        # boundaries 1 - 4
        vect.write(Boundary(points=[(0, 0), (0,4)]))
        vect.write(Boundary(points=[(0, 4), (4,4)]))
        vect.write(Boundary(points=[(4, 4), (4,0)]))
        vect.write(Boundary(points=[(4, 0), (0,0)]))
        # 5. boundary (Isle)
        vect.write(Boundary(points=[(1, 1), (1,3), (3, 3), (3,1), (1,1)]))
        # boundaries 6 - 8
        vect.write(Boundary(points=[(4, 4), (6,4)]))
        vect.write(Boundary(points=[(6, 4), (6,0)]))
        vect.write(Boundary(points=[(6, 0), (4,0)]))
        # boundaries 9 - 11
        vect.write(Boundary(points=[(6, 4), (8,4)]))
        vect.write(Boundary(points=[(8, 4), (8,0)]))
        vect.write(Boundary(points=[(8, 0), (6,0)]))
        # Centroids, all have the same cat and attribute
        vect.write(Centroid(x=3.5, y=3.5), cat=7, attrs=("centroid7", 7))
        vect.write(Centroid(x=2.5, y=2.5), cat=8, attrs=("centroid8", 8))
        vect.write(Centroid(x=5.5, y=3.5), cat=9, attrs=("centroid9", 9))
        vect.write(Centroid(x=7.5, y=3.5), cat=10, attrs=("centroid10", 10))

        vect.table.conn.commit()

        vect.organization = "Thuenen Institut"
        vect.person = "Soeren Gebbert"
        vect.title = "Test dataset"
        vect.comment = "This is a comment"
        vect.close()


TMPVECT = 'test_vector2'
CAT = 8

create_test_vector_map2(TMPVECT, overwrite=True)

with VectorTopo(TMPVECT, mode='r') as tv:
    features = [f for f in tv]
    print(features[-3].cat == CAT, features[-3], features[-3].id)

    ilist = Ilist()
    libvect.Vect_cidx_find_all(tv.c_mapinfo, 1, libvect.GV_AREA, CAT,
ilist.c_ilist)
    print('area', libvect.GV_AREA, [(i, tv[i].cat) for i in ilist])

    libvect.Vect_cidx_find_all(tv.c_mapinfo, 1, libvect.GV_CENTROID,
CAT, ilist.c_ilist)
    print('centroid', libvect.GV_CENTROID, [(i, tv[i].cat) for i in ilist])

    b0 = features[6]
    print(b0, b0.left_area_id, b0.right_area_id)
    print()
}}}


More information about the grass-dev mailing list