Identifying polygons that intersect with another layer using QGIS? Planned maintenance...
How to bypass password on Windows XP account?
"Seemed to had" is it correct?
How to deal with my PhD supervisors rudely critiquing all my draft papers?
illegal generic type for instanceof when using local classes
ListPlot join points by nearest neighbor rather than order
Do I need a Schengen visa for a direct flight to Amsterdam?
Do I really need recursive chmod to restrict access to a folder?
Is 1 ppb equal to 1 μg/kg?
Were Kohanim forbidden from serving in King David's army?
What would be the ideal power source for a cybernetic eye?
Is there a concise way to say "all of the X, one of each"?
What's the purpose of writing one's academic bio in 3rd person?
Stars Make Stars
When -s is used with third person singular. What's its use in this context?
Bonus calculation: Am I making a mountain out of a molehill?
Sorting numerically
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Dot products and For-loops
Why is "Captain Marvel" translated as male in Portugal?
Did Xerox really develop the first LAN?
iPhone Wallpaper?
what is Samayachara? (I have read it in relation to 'Shri Vidya')
Can an alien society believe that their star system is the universe?
What do you call a phrase that's not an idiom yet?
Identifying polygons that intersect with another layer using QGIS?
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Documentation “Join Attributes by Location” QGIS 2.18Counting attributes from line intersections with polygons on QGIS?Can't find point/polygon intersect using QGIS (Windows only)determining what polygons intersect another layerHow to select only polygons that overlap with another layer?QGIS calculates main soil type of polygons from another polygon layerArcGIS find all polygons that intersect with more that one polygon from another layerHow to only label features in layer 1 that intersect with buffer polygon in layer 2?Intersect polygonsSelect features in a polygon that covered the most by features of another polygon layer QGISClipping polygon layer to another polygon layer based on matching attributes using QGIS?Identifying polygons that intersect with another polygon using ArcGIS Desktop?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Using QGIS, I have two polygon layers, a vegetation layer and a treatment layer. I want to add a field to the attribute layer of the vegetation layer to indicate if any part of the polygon has been treated (overlaps with a treatment layer).

For the above example - I want an attribute table that ends up looking like

I do not want to intersect the two layers - I need to keep the full polygons in the vegetation layer, I just want to know if they've been treated. There are too many polygons to do this manually.
I have looked through the vector tools to try identify one that does this, this was not successful. I've tried to find a workflow via rasters instead of polygons, but cannot figure out what would be needed for this to work. I have searched online but not been able to find anything that answers this question, likely because I do not know what this is called so do not know what terms to search for.
The only solutions I have found are manual, but there are several hundred polygons so I would like to avoid that approach unless there is no other option.
qgis polygon intersection
add a comment |
Using QGIS, I have two polygon layers, a vegetation layer and a treatment layer. I want to add a field to the attribute layer of the vegetation layer to indicate if any part of the polygon has been treated (overlaps with a treatment layer).

For the above example - I want an attribute table that ends up looking like

I do not want to intersect the two layers - I need to keep the full polygons in the vegetation layer, I just want to know if they've been treated. There are too many polygons to do this manually.
I have looked through the vector tools to try identify one that does this, this was not successful. I've tried to find a workflow via rasters instead of polygons, but cannot figure out what would be needed for this to work. I have searched online but not been able to find anything that answers this question, likely because I do not know what this is called so do not know what terms to search for.
The only solutions I have found are manual, but there are several hundred polygons so I would like to avoid that approach unless there is no other option.
qgis polygon intersection
add a comment |
Using QGIS, I have two polygon layers, a vegetation layer and a treatment layer. I want to add a field to the attribute layer of the vegetation layer to indicate if any part of the polygon has been treated (overlaps with a treatment layer).

For the above example - I want an attribute table that ends up looking like

I do not want to intersect the two layers - I need to keep the full polygons in the vegetation layer, I just want to know if they've been treated. There are too many polygons to do this manually.
I have looked through the vector tools to try identify one that does this, this was not successful. I've tried to find a workflow via rasters instead of polygons, but cannot figure out what would be needed for this to work. I have searched online but not been able to find anything that answers this question, likely because I do not know what this is called so do not know what terms to search for.
The only solutions I have found are manual, but there are several hundred polygons so I would like to avoid that approach unless there is no other option.
qgis polygon intersection
Using QGIS, I have two polygon layers, a vegetation layer and a treatment layer. I want to add a field to the attribute layer of the vegetation layer to indicate if any part of the polygon has been treated (overlaps with a treatment layer).

For the above example - I want an attribute table that ends up looking like

I do not want to intersect the two layers - I need to keep the full polygons in the vegetation layer, I just want to know if they've been treated. There are too many polygons to do this manually.
I have looked through the vector tools to try identify one that does this, this was not successful. I've tried to find a workflow via rasters instead of polygons, but cannot figure out what would be needed for this to work. I have searched online but not been able to find anything that answers this question, likely because I do not know what this is called so do not know what terms to search for.
The only solutions I have found are manual, but there are several hundred polygons so I would like to avoid that approach unless there is no other option.
qgis polygon intersection
qgis polygon intersection
edited 2 hours ago
PolyGeo♦
54k1782246
54k1782246
asked 2 hours ago
Esme_Esme_
372516
372516
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can do this using Aggregate function. Add a new field isTreated in the vegetation layer with an expression like below
if(aggregate(
layer:= 'treatment',
aggregate:='count',
expression:=fid,
filter:=intersects($geometry, geometry(@parent))
) > 0, 1, 0)
The aggregate function returns number of features from the treatment layer that are intersecting. As you are only interested whether they intersect at least 1 feature, you can add the if condition to assign 0 or 1.
See my post about aggregate functions in QGIS to learn more https://spatialthoughts.com/2019/04/12/summary-aggregation-qgis/
add a comment |
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in "vegetation" and four in "treatment" accordingly, see image below.

With the following Query, it is possible to achieve the result
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated
FROM vegetation
The output Virtual Layer will maintain initial attributes and geometries and add an additional field representing overlaps.

Additionally, you may extend your output layer as was earlier suggested by @spatialthoughts with several lines
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated,
SUM(st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL) AS Intersections
FROM vegetation, treatment
GROUP BY vegetation.id
Now, the output Virtual Layer will look as following

References:
- Chapter 8. PostGIS Reference | 8.5. Geometry Accessors
- Counting attributes from line intersections with polygons on QGIS?
- Documentation “Join Attributes by Location” QGIS 2.18
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318940%2fidentifying-polygons-that-intersect-with-another-layer-using-qgis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do this using Aggregate function. Add a new field isTreated in the vegetation layer with an expression like below
if(aggregate(
layer:= 'treatment',
aggregate:='count',
expression:=fid,
filter:=intersects($geometry, geometry(@parent))
) > 0, 1, 0)
The aggregate function returns number of features from the treatment layer that are intersecting. As you are only interested whether they intersect at least 1 feature, you can add the if condition to assign 0 or 1.
See my post about aggregate functions in QGIS to learn more https://spatialthoughts.com/2019/04/12/summary-aggregation-qgis/
add a comment |
You can do this using Aggregate function. Add a new field isTreated in the vegetation layer with an expression like below
if(aggregate(
layer:= 'treatment',
aggregate:='count',
expression:=fid,
filter:=intersects($geometry, geometry(@parent))
) > 0, 1, 0)
The aggregate function returns number of features from the treatment layer that are intersecting. As you are only interested whether they intersect at least 1 feature, you can add the if condition to assign 0 or 1.
See my post about aggregate functions in QGIS to learn more https://spatialthoughts.com/2019/04/12/summary-aggregation-qgis/
add a comment |
You can do this using Aggregate function. Add a new field isTreated in the vegetation layer with an expression like below
if(aggregate(
layer:= 'treatment',
aggregate:='count',
expression:=fid,
filter:=intersects($geometry, geometry(@parent))
) > 0, 1, 0)
The aggregate function returns number of features from the treatment layer that are intersecting. As you are only interested whether they intersect at least 1 feature, you can add the if condition to assign 0 or 1.
See my post about aggregate functions in QGIS to learn more https://spatialthoughts.com/2019/04/12/summary-aggregation-qgis/
You can do this using Aggregate function. Add a new field isTreated in the vegetation layer with an expression like below
if(aggregate(
layer:= 'treatment',
aggregate:='count',
expression:=fid,
filter:=intersects($geometry, geometry(@parent))
) > 0, 1, 0)
The aggregate function returns number of features from the treatment layer that are intersecting. As you are only interested whether they intersect at least 1 feature, you can add the if condition to assign 0 or 1.
See my post about aggregate functions in QGIS to learn more https://spatialthoughts.com/2019/04/12/summary-aggregation-qgis/
answered 1 hour ago
spatialthoughtsspatialthoughts
3,6031523
3,6031523
add a comment |
add a comment |
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in "vegetation" and four in "treatment" accordingly, see image below.

With the following Query, it is possible to achieve the result
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated
FROM vegetation
The output Virtual Layer will maintain initial attributes and geometries and add an additional field representing overlaps.

Additionally, you may extend your output layer as was earlier suggested by @spatialthoughts with several lines
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated,
SUM(st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL) AS Intersections
FROM vegetation, treatment
GROUP BY vegetation.id
Now, the output Virtual Layer will look as following

References:
- Chapter 8. PostGIS Reference | 8.5. Geometry Accessors
- Counting attributes from line intersections with polygons on QGIS?
- Documentation “Join Attributes by Location” QGIS 2.18
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
add a comment |
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in "vegetation" and four in "treatment" accordingly, see image below.

With the following Query, it is possible to achieve the result
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated
FROM vegetation
The output Virtual Layer will maintain initial attributes and geometries and add an additional field representing overlaps.

Additionally, you may extend your output layer as was earlier suggested by @spatialthoughts with several lines
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated,
SUM(st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL) AS Intersections
FROM vegetation, treatment
GROUP BY vegetation.id
Now, the output Virtual Layer will look as following

References:
- Chapter 8. PostGIS Reference | 8.5. Geometry Accessors
- Counting attributes from line intersections with polygons on QGIS?
- Documentation “Join Attributes by Location” QGIS 2.18
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
add a comment |
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in "vegetation" and four in "treatment" accordingly, see image below.

With the following Query, it is possible to achieve the result
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated
FROM vegetation
The output Virtual Layer will maintain initial attributes and geometries and add an additional field representing overlaps.

Additionally, you may extend your output layer as was earlier suggested by @spatialthoughts with several lines
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated,
SUM(st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL) AS Intersections
FROM vegetation, treatment
GROUP BY vegetation.id
Now, the output Virtual Layer will look as following

References:
- Chapter 8. PostGIS Reference | 8.5. Geometry Accessors
- Counting attributes from line intersections with polygons on QGIS?
- Documentation “Join Attributes by Location” QGIS 2.18
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume we have three features in "vegetation" and four in "treatment" accordingly, see image below.

With the following Query, it is possible to achieve the result
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated
FROM vegetation
The output Virtual Layer will maintain initial attributes and geometries and add an additional field representing overlaps.

Additionally, you may extend your output layer as was earlier suggested by @spatialthoughts with several lines
SELECT vegetation.*,
(CASE
WHEN vegetation.id IN
(SELECT vegetation.id
FROM vegetation, treatment
WHERE st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL)
THEN '1'
ELSE '0'
END) AS Is_Treated,
SUM(st_intersection(vegetation.geometry, treatment.geometry) IS NOT NULL) AS Intersections
FROM vegetation, treatment
GROUP BY vegetation.id
Now, the output Virtual Layer will look as following

References:
- Chapter 8. PostGIS Reference | 8.5. Geometry Accessors
- Counting attributes from line intersections with polygons on QGIS?
- Documentation “Join Attributes by Location” QGIS 2.18
edited 15 mins ago
answered 52 mins ago
TarasTaras
2,3303729
2,3303729
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
add a comment |
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Nice! Works on QGIS 3.4 too. Always good to learn different ways of accomplishing the same. Would be interesting to see which approach scales better in layers with lots of polygons.
– spatialthoughts
27 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
Definitely. I am also interested in that "comparison". Let's figure it out ))
– Taras
16 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
@spatialthoughts, thank you for testing on QGIS 3.4. I will complete my answer with this note
– Taras
15 mins ago
1
1
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
Yes. @Esme_ please do test both the solutions and let is know which one runs faster.
– spatialthoughts
12 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
thank you for an idea, @Esme_ shall test it then it will be really veridical
– Taras
10 mins ago
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318940%2fidentifying-polygons-that-intersect-with-another-layer-using-qgis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown