[GRASS-user] Centroid coordinates to database

Markus Neteler neteler at osgeo.org
Sun Sep 27 05:34:36 EDT 2009


2009/9/27 Szabó Balázs <szabobaa at gmail.com>:
> Hi!
>
> It is possible to extract the centroid coordinates into the database?

Yes.

> (Sorry about my english, I try to explain my probleme). I have a vector
> grass polygon data with mysql database connection. But I want use just
> the mysql database with the polygons centroid. So that's why I need
> upload to the mysql database (like a column) their centroids
> coordinates. So it is possible to get this coordinates in Grass??

I would do (untested):

# add new columns
v.db.addcol mymap col="centr_x double precision, centr_y  double precision"
# transform coordinates to attributes:
v.to.db mymap type=centroid option=coor col=centr_x,centr_y
# check
v.db.select mymap

This will fail if a category (i.e. attribute row in the table) points to
more than one polygon. In that case, you could add a new table
as layer=2 and populate it with unique values for each polygon
first. Then do above on layer=2 to upload the centroid coodinates
there.

See:
http://grass.osgeo.org/grass64/manuals/html64_user/v.to.db.html

Hope this helps,
Markus


More information about the grass-user mailing list