2

I am using QGIS version: 3.10.3-A Coruña. I have two shapefile layers, the first is polygons for world countries and the second is a 1-degree spaced polygon worldwide. I would like to extract which polygon(s) from the second layer intersecting each country from the first layer. I would do it easily with "Extract by Location", BUT my goal is to rename each output following the country's name and not to do it individually.

Here is the log file for one country when I do it individually.

Algorithm 'Extract by location' starting…
Input parameters:
{ 'INPUT' : 'C:/Users/Familie Hammoud/Desktop/ne_50m_admin_0_countries/World 1deg grid.shp', 'INTERSECT' : QgsProcessingFeatureSourceDefinition('ne_50m_admin_0_countries', True), 'OUTPUT' : 'C:/Users/Familie Hammoud/Desktop/Neuer Ordner/Germany.shp', 'PREDICATE' : [0] }

I am thinking if there is Python script to do this mission but sadly I don't know how.

1
  • 1
    but this will be a 1:many relation since one gridcell could intersect more then one country. How do you want to handle this?
    – eurojam
    Mar 2, 2020 at 17:40

1 Answer 1

1

This is not a python solution but you can use the field calculator for this. Just compute a new field (string) for your grid layer with a expression like this one:

 aggregate( 
 layer:='ne_50m_admin_0_countries',
 aggregate:='concatenate',
 expression:= "name",
 filter:=intersects( $geometry, geometry(@parent)),
 concatenator:=',')

enter image description here

enter image description here

1
  • thank you so much for you help! Mar 3, 2020 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.