Sunday 23 December 2018

qgis - Filling a field in a layer using a spatial relation with another layer/shapefile?


I want to know how I can fill in a column of a layer based on a certain relation criteria to another layer. In my case I want the column "straat" in my "bomen" shapefile filled in with the value's of "Staatnaam" in the shapefile "straat". However, the value that will be filled in is linked to a certain criteria relation. In this case, since "Bomen" is a point shapefile, each point forms a circle of 36 meters in radius (so 36 meters in every direction). The name for the closest street that intersects/crosses the "circle", needs to be added into the "Bomen" shapefile in the "straat" column.


How do I do this? If you guys can still not understand this what I am asking, here is an illustration. The "Bomen" and Straat shapefiles are the PostGIS layers, but this part is not important.


enter image description here



Answer



Assuming that a point doesn't form a circle of 36 meters (because it is a point), you may try to join the shapefile using a spatial relationship.


As a first step, create a new buffer layer from your point shapefile: this task is simply performed using the Fixed distance buffer algorithm from Processing Toolbox and setting the distance of 36 meters as Distance parameter.



Then, run the Join attributes by location algorithm from Processing Toolbox using these parameters:


enter image description here


The result will be a new layer which stores the same fields of the buffer_layer shapefile, plus the fields from the roads_layer shapefile when there is an intersection between the two layers.


If you want to save the attributes in the original point shapefile, run again the Join attributes by location algorithm, but this time use the point shapefile as Target vector layer and the joined layer as Join vector layer parameter.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...