Example #1
0
    def delete(self, feature_id):
        """Remove a feature by its id

        :param feature_id: the id of the feature
        :type feature_id: int
        """
        if libvect.Vect_rewrite_line(self.c_mapinfo, feature_id) == -1:
            raise GrassError("C function: Vect_rewrite_line.")
Example #2
0
    def rewrite(self, line, geo_obj, attrs=None, **kargs):
        """Rewrite a geometry features
        """
        if self.table is not None and attrs:
            attr = [
                line,
            ]
            attr.extend(attrs)
            self.table.update(key=line, values=attr)
        elif self.table is None and attrs:
            print("Table for vector {name} does not exist, attributes not"
                  " loaded".format(name=self.name))
        libvect.Vect_cat_set(geo_obj.c_cats, self.layer, line)
        result = libvect.Vect_rewrite_line(self.c_mapinfo, line, geo_obj.gtype,
                                           geo_obj.c_points, geo_obj.c_cats)
        if result == -1:
            raise GrassError("Not able to write the vector feature.")

        # return offset into file where the feature starts
        geo_obj.offset = result
    def rewrite_obj(self, obj, attrs):
        """Return
        """
        self.polygon.open('rw', self.layer, with_z=True)
        cat = attrs[0]

        if obj.gtype == 1:
            vtype = 'points'
        elif obj.gtype == 2:
            vtype = 'lines'
        elif obj.gtype == 3:
            vtype = 'boundary'
        elif obj.gtype == 4:
            vtype = 'centroid'

        line = self.polygon.cat(cat, vtype, self.layer)[0]

        if self.polygon.table is not None and attrs:
            self.polygon.table.update(key=line.cat, values=attrs[1:])
        elif self.polygon.table is None and attrs:
            print("Table for vector {name} does not exist, attributes not"
                  " loaded".format(name=self.name))
        # libvect.Vect_cat_set(obj.c_cats, self.layer, line.cat)

        result = libvect.Vect_rewrite_line(self.polygon.c_mapinfo,
                                           line.id, obj.gtype,
                                           obj.c_points,
                                           line.c_cats)
        if result == -1:
            raise GrassError("Not able to write the vector feature.")

        # return offset into file where the feature starts
        obj.offset = result

        self.polygon.table.conn.commit()
        self.polygon.close()
Example #4
0
    def rewrite(self, geo_obj, cat, attrs=None, **kargs):
        """Rewrite a geometry features

            >>> cols = [(u'cat',       'INTEGER PRIMARY KEY'),
            ...         (u'name',      'TEXT')]

        Generate a new vector map

            >>> test_vect = VectorTopo('newvect_2')
            >>> test_vect.open('w', tab_name='newvect_2', tab_cols=cols,
            ...                overwrite=True)

        import a geometry feature ::

            >>> from grass.pygrass.vector.geometry import Point

        create two points ::

            >>> point0 = Point(0, 0)
            >>> point1 = Point(1, 1)
            >>> point2 = Point(2, 2)

        then write the two points on the map, with ::

            >>> test_vect.write(point0, cat=1, attrs=('pub',))
            >>> test_vect.write(point1, cat=2, attrs=('resturant',))
            >>> test_vect.table.conn.commit()  # save changes in the DB
            >>> test_vect.table_to_dict()
            {1: [1, u'pub'], 2: [2, u'resturant']}
            >>> test_vect.close()

        Now rewrite one point of the vector map: ::

            >>> test_vect.open('rw')
            >>> test_vect.rewrite(point2, cat=1, attrs=('Irish Pub',))
            >>> test_vect.table.conn.commit()  # save changes in the DB
            >>> test_vect.close()

        Check the output:

            >>> test_vect.open('r')
            >>> test_vect[1] == point2
            True
            >>> test_vect[1].attrs['name'] == 'Irish Pub'
            True
            >>> test_vect.close()
            >>> test_vect.remove()
        """
        if self.table is not None and attrs:
            self.table.update(key=cat, values=attrs)
        elif self.table is None and attrs:
            print("Table for vector {name} does not exist, attributes not"
                  " loaded".format(name=self.name))
        libvect.Vect_cat_set(geo_obj.c_cats, self.layer, cat)
        result = libvect.Vect_rewrite_line(self.c_mapinfo,
                                           cat, geo_obj.gtype,
                                           geo_obj.c_points,
                                           geo_obj.c_cats)
        if result == -1:
            raise GrassError("Not able to write the vector feature.")

        # return offset into file where the feature starts
        geo_obj.offset = result
Example #5
0
 def delete(self, feature_id):
     if libvect.Vect_rewrite_line(self.c_mapinfo, feature_id) == -1:
         raise GrassError("C funtion: Vect_rewrite_line.")
Example #6
0
 def rewrite(self, geo_obj):
     result = libvect.Vect_rewrite_line(self.c_mapinfo, geo_obj.id,
                                        geo_obj.gtype, geo_obj.c_points,
                                        geo_obj.c_cats)
     # return offset into file where the feature starts
     geo_obj.offset = result