Quickly find all polygons that overlap with two or more polygons in Shapely The 2019 Stack...
Are there incongruent pythagorean triangles with the same perimeter and same area?
What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?
"as much details as you can remember"
Delete all lines which don't have n characters before delimiter
What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?
Can a flute soloist sit?
What do hard-Brexiteers want with respect to the Irish border?
Did 3000BC Egyptians use meteoric iron weapons?
Who coined the term "madman theory"?
How to obtain Confidence Intervals for a LASSO regression?
Worn-tile Scrabble
Is three citations per paragraph excessive for undergraduate research paper?
Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?
What is the motivation for a law requiring 2 parties to consent for recording a conversation
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
What is the meaning of the verb "bear" in this context?
Why is my custom API endpoint not working?
Does the shape of a die affect the probability of a number being rolled?
What does "fetching by region is not available for SAM files" means?
Aging parents with no investments
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Is there any way to tell whether the shot is going to hit you or not?
What is the closest word meaning "respect for time / mindful"
Quickly find all polygons that overlap with two or more polygons in Shapely
The 2019 Stack Overflow Developer Survey Results Are InHow to find the intersection areas of overlapping buffer zones in single shapefile?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have a code so far that works in the if 1: statement below, but it takes a very long time to run. The code that is in the if 0: statement, runs quickly, but produces an output with some errors. See below for an example of the error.
with fiona.open("Untitled.shp") as layer:
subset=layer
spoof=[]
for n,pol in enumerate(subset):
if type(shape(pol['geometry'])) == shapely.geometry.polygon.Polygon:
spoof.append(shape(pol['geometry']))
elif type(shape(pol['geometry'])) == shapely.geometry.multipolygon.MultiPolygon:
print('theres one here')
tmp=list(shape(pol['geometry']))
for x in tmp:
spoof.append(x)
rings = [LineString(list(pol.exterior.coords)) for pol in spoof]
union = unary_union(rings)
tree = STRtree(spoof)
result = [geom for geom in polygonize(union)]
final=[]
if 1:
for k,item1 in enumerate(result):
count=0
for n,item2 in enumerate(spoof):
if item1.intersection(item2).area >1e-8:
count=count+1
if count>=2:
final.append(item1)
if 0:
for k,item in enumerate(result):
touch=tree.query(item.centroid)
if len(touch)>=2:
final.append(item)
Below, the orange represents all the shapes that I would like to check if they are produced (by unary union in Shapely) by two or more overlaps, the cyan represents the output of the if-statement that works (if 1 in above code), and the pink represents the incorrect selected polygons by the if-statement that doesn't work (if 0 in above code). The top left corners of the text boxes in the pictures represent that point being selected, and as you can see the second picture, the pink area only has one polygon from the STEREO_OBSERVATIONS (which is the set of polygons that are being checked for overlap) so it should not be selected. By contrast, the left adjacent cyan square to the pink square highlighted in the third picture has two polygons from STEREO_OBSERVATIONS and as such is correctly selected by the cyan result. The layering of the polygon layers is shown in the first picture.
What is the best way to query the STRtree structure so as to check to intersection or overlap? I have tried to use the centroid in the code, but that hasn't seemed to produce the correct output.
Fig. 1 (Legend/layering)

Fig 2. (Incorrect selection by fast algorithm [if 0 in code] in pink)

Fig 3. (Correct selection by slow algorithm [if 1 in code]

python polygon shapely fiona
add a comment |
I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have a code so far that works in the if 1: statement below, but it takes a very long time to run. The code that is in the if 0: statement, runs quickly, but produces an output with some errors. See below for an example of the error.
with fiona.open("Untitled.shp") as layer:
subset=layer
spoof=[]
for n,pol in enumerate(subset):
if type(shape(pol['geometry'])) == shapely.geometry.polygon.Polygon:
spoof.append(shape(pol['geometry']))
elif type(shape(pol['geometry'])) == shapely.geometry.multipolygon.MultiPolygon:
print('theres one here')
tmp=list(shape(pol['geometry']))
for x in tmp:
spoof.append(x)
rings = [LineString(list(pol.exterior.coords)) for pol in spoof]
union = unary_union(rings)
tree = STRtree(spoof)
result = [geom for geom in polygonize(union)]
final=[]
if 1:
for k,item1 in enumerate(result):
count=0
for n,item2 in enumerate(spoof):
if item1.intersection(item2).area >1e-8:
count=count+1
if count>=2:
final.append(item1)
if 0:
for k,item in enumerate(result):
touch=tree.query(item.centroid)
if len(touch)>=2:
final.append(item)
Below, the orange represents all the shapes that I would like to check if they are produced (by unary union in Shapely) by two or more overlaps, the cyan represents the output of the if-statement that works (if 1 in above code), and the pink represents the incorrect selected polygons by the if-statement that doesn't work (if 0 in above code). The top left corners of the text boxes in the pictures represent that point being selected, and as you can see the second picture, the pink area only has one polygon from the STEREO_OBSERVATIONS (which is the set of polygons that are being checked for overlap) so it should not be selected. By contrast, the left adjacent cyan square to the pink square highlighted in the third picture has two polygons from STEREO_OBSERVATIONS and as such is correctly selected by the cyan result. The layering of the polygon layers is shown in the first picture.
What is the best way to query the STRtree structure so as to check to intersection or overlap? I have tried to use the centroid in the code, but that hasn't seemed to produce the correct output.
Fig. 1 (Legend/layering)

Fig 2. (Incorrect selection by fast algorithm [if 0 in code] in pink)

Fig 3. (Correct selection by slow algorithm [if 1 in code]

python polygon shapely fiona
add a comment |
I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have a code so far that works in the if 1: statement below, but it takes a very long time to run. The code that is in the if 0: statement, runs quickly, but produces an output with some errors. See below for an example of the error.
with fiona.open("Untitled.shp") as layer:
subset=layer
spoof=[]
for n,pol in enumerate(subset):
if type(shape(pol['geometry'])) == shapely.geometry.polygon.Polygon:
spoof.append(shape(pol['geometry']))
elif type(shape(pol['geometry'])) == shapely.geometry.multipolygon.MultiPolygon:
print('theres one here')
tmp=list(shape(pol['geometry']))
for x in tmp:
spoof.append(x)
rings = [LineString(list(pol.exterior.coords)) for pol in spoof]
union = unary_union(rings)
tree = STRtree(spoof)
result = [geom for geom in polygonize(union)]
final=[]
if 1:
for k,item1 in enumerate(result):
count=0
for n,item2 in enumerate(spoof):
if item1.intersection(item2).area >1e-8:
count=count+1
if count>=2:
final.append(item1)
if 0:
for k,item in enumerate(result):
touch=tree.query(item.centroid)
if len(touch)>=2:
final.append(item)
Below, the orange represents all the shapes that I would like to check if they are produced (by unary union in Shapely) by two or more overlaps, the cyan represents the output of the if-statement that works (if 1 in above code), and the pink represents the incorrect selected polygons by the if-statement that doesn't work (if 0 in above code). The top left corners of the text boxes in the pictures represent that point being selected, and as you can see the second picture, the pink area only has one polygon from the STEREO_OBSERVATIONS (which is the set of polygons that are being checked for overlap) so it should not be selected. By contrast, the left adjacent cyan square to the pink square highlighted in the third picture has two polygons from STEREO_OBSERVATIONS and as such is correctly selected by the cyan result. The layering of the polygon layers is shown in the first picture.
What is the best way to query the STRtree structure so as to check to intersection or overlap? I have tried to use the centroid in the code, but that hasn't seemed to produce the correct output.
Fig. 1 (Legend/layering)

Fig 2. (Incorrect selection by fast algorithm [if 0 in code] in pink)

Fig 3. (Correct selection by slow algorithm [if 1 in code]

python polygon shapely fiona
I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have a code so far that works in the if 1: statement below, but it takes a very long time to run. The code that is in the if 0: statement, runs quickly, but produces an output with some errors. See below for an example of the error.
with fiona.open("Untitled.shp") as layer:
subset=layer
spoof=[]
for n,pol in enumerate(subset):
if type(shape(pol['geometry'])) == shapely.geometry.polygon.Polygon:
spoof.append(shape(pol['geometry']))
elif type(shape(pol['geometry'])) == shapely.geometry.multipolygon.MultiPolygon:
print('theres one here')
tmp=list(shape(pol['geometry']))
for x in tmp:
spoof.append(x)
rings = [LineString(list(pol.exterior.coords)) for pol in spoof]
union = unary_union(rings)
tree = STRtree(spoof)
result = [geom for geom in polygonize(union)]
final=[]
if 1:
for k,item1 in enumerate(result):
count=0
for n,item2 in enumerate(spoof):
if item1.intersection(item2).area >1e-8:
count=count+1
if count>=2:
final.append(item1)
if 0:
for k,item in enumerate(result):
touch=tree.query(item.centroid)
if len(touch)>=2:
final.append(item)
Below, the orange represents all the shapes that I would like to check if they are produced (by unary union in Shapely) by two or more overlaps, the cyan represents the output of the if-statement that works (if 1 in above code), and the pink represents the incorrect selected polygons by the if-statement that doesn't work (if 0 in above code). The top left corners of the text boxes in the pictures represent that point being selected, and as you can see the second picture, the pink area only has one polygon from the STEREO_OBSERVATIONS (which is the set of polygons that are being checked for overlap) so it should not be selected. By contrast, the left adjacent cyan square to the pink square highlighted in the third picture has two polygons from STEREO_OBSERVATIONS and as such is correctly selected by the cyan result. The layering of the polygon layers is shown in the first picture.
What is the best way to query the STRtree structure so as to check to intersection or overlap? I have tried to use the centroid in the code, but that hasn't seemed to produce the correct output.
Fig. 1 (Legend/layering)

Fig 2. (Incorrect selection by fast algorithm [if 0 in code] in pink)

Fig 3. (Correct selection by slow algorithm [if 1 in code]

python polygon shapely fiona
python polygon shapely fiona
asked 2 mins ago
LoonuhLoonuh
1063
1063
add a comment |
add a comment |
0
active
oldest
votes
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%2f318431%2fquickly-find-all-polygons-that-overlap-with-two-or-more-polygons-in-shapely%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f318431%2fquickly-find-all-polygons-that-overlap-with-two-or-more-polygons-in-shapely%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