[GRASS-dev] easy way to load x, y (of centroid) and top, bottom, left, right coordinates to attribute table?

Helmut Kudrnovsky hellik at web.de
Sat Jan 28 03:19:15 PST 2017

>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?

>For the bounding box coordinates, I don't know any easy way. Would be a 
>nice thing to have in v.to.db (see [1]).

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

best regards
View this message in context: http://osgeo-org.1560.x6.nabble.com/easy-way-to-load-x-y-of-centroid-and-top-bottom-left-right-coordinates-to-attribute-table-tp5305135p5305175.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

More information about the grass-dev mailing list