[GRASS-user] Joining vectors by location

Moritz Lennert mlennert at club.worldonline.be
Mon Nov 21 18:21:26 EST 2011

On 21/11/11 19:24, Daniel Lee wrote:
> Alright, I just figured out a way to do it, albeit an unelegant way that
> requires using another program.
> I converted the rasters to vectors as usual. Then I did the following in
> order to preserve the original polygons:
> - Extracted the centroids by using v.select
> - Converted the centroids to points with v.type_wrapper
> - Do a join by location between the polygons in points in QGIS
> That worked, but it is VERY unelegant. Does anyone have a better idea?

You can use v.distance with dmax=0 to do such a "spatial join" between 
polygons and points:

v.db.addcolumn YourCentroids col='poly_cat int'
v.distance from=YourCentroids to=YourPolygons upload=cat column=poly_cat 

This should upload the category values of your polygons to the attribute 
value of your centroids. If you then want to join the two tables, you 
can use v.db.join.


More information about the grass-user mailing list