[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                                    
cat|id|x|y|l|r|t|b|x2|y2|x|y|z
1||9.8489673562|47.0568937369|9.0801356183|10.6452349706|47.6779179411|46.4101061965|9.85074274819765|47.0584209060437|9.85074274819765|47.0584209060437|0.0
2||11.8802743895|46.9879350674|11.0347074901|12.7965928607|47.8068606443|46.1987432153|11.8761701610656|46.990400528994|11.8761701610656|46.990400528994|0.0
3||9.7422504597|46.163754262|9.0475885875|10.3944050709|46.4383355922|45.9348643802|9.737413876863|46.16534963624|9.737413876863|46.16534963624|0.0

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
coordinates.

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
vtopo.close()

so it's already in the vector data available, would be nice to have it in
v.to.db.



-----
best regards
Helmut
--
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