HOWTO get centroid coordinates

From GRASS-Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Q: I have a vector of polygons and I want to create a vector of points with the centroids of the polygons, with a connected table showing their coordinates. Which is the simplest way to do that?

A: In Grass 6.4.x:

# Extract centroids from polygon map
v.extract in=poly out=centr type=centroid
# If needed convert centroids to points
v.type in=centr out=centr_pts type=centroid,point
# Add attribute table to points
v.db.addtable centr_pts col="x double,y double,z double"
# Insert coords in table
v.to.db TMP_centr_pts option=coor col=x,y,z

In Grass 7:

v.out.ascii in=poly type=centroid