[GRASS-dev] easy way to load x, y (of centroid) and top, bottom, left, right coordinates to attribute table?
mlennert at club.worldonline.be
Sat Jan 28 03:54:57 PST 2017
On 28/01/17 12:19, Helmut Kudrnovsky wrote:
>> For the centroid coordinates:
>> v.db.addcolumn YourMap column="x double precision, y double precision"
>> v.to.db YourMap op=coor col=x,y
> just tried with some vectors in a wgs84 ll location:
> v.report map=testcalculate option=coor
> x and y are the centroid coordinates calculated by QGIS
> x2 and y2 are the centroi coordinates calculated by v.to.db
> and the last (identical to x2 and y2) reported by v.report
> it's interesting that QGIS and GRASS calculates differnt centroid
> any idea?
I don't know which tool you used in QGIS, but GRASS' centroids are not
guaranteed to be the geometrical centroid (aka "center of gravity" which
could sometimes fall outside the polygon). You might want to compare the
results of QGIS with those of the addon v.centerpoint.
>> For the bounding box coordinates, I don't know any easy way. Would be a
>> nice thing to have in v.to.db (see ).
> yes indeed, would be a nice addition to v.to.db. updated the ticket.
> taken from a little script coded some time ago:
> # print bbox of vector layer geometries
> if print_bbox_vector_geometries :
> # open vector
> vtopo = VectorTopo(vector)
> vtopo.open(mode = 'r')
> # loop thru vector geometries
> for i in range(1, vcats_max_plus):
> # get vector geometries area info
> vect_geom_area = Area(v_id = i, c_mapinfo = vtopo.c_mapinfo)
> # get vector geometries bbox info
> vect_geom_bb = vect_geom_area.bbox()
> # bbox north, south, west, east
> bb_north = vect_geom_bb.north
> bb_south = vect_geom_bb.south
> bb_west = vect_geom_bb.west
> bb_east = vect_geom_bb.east
> grass.message("cat %s: north: %s south: %s west: %s east: %s" %(i,
> bb_north, bb_south, bb_west, bb_east))
> # close vector
> so it's already in the vector data available, would be nice to have it in
Yes, there's Vect_get_area_box in the Vlib (box.c), so it shouldn't be
too hard to integrate it.
More information about the grass-dev