I'm trying to understand the ArcGIS "Intersect""union" method so I can replicate it with an algorithm using Python and Shapely.
Instead, I want each sub intersection that intersects at least once, repeated how many times it occurs. So in the example image I want ABC returned three times, and AB, AC, and BC returned twice. While the ArcGis method also returns the unique parts A, B, and C that have no intersections, I do not need this.
I've tried just loopingCode
In the ArcGis docs for union, they write that they use a "cracks and intersectingclusters" method, which is likely a low level modification of the intersection/union clipping algorithm. Since I am not implementing the underlying clipping algorithm, I need a different approach.
Here is pseudocode that I will be trying to implement. It basically means for each geometry withfeature i find all other geometriesintersections with others, but this only considers one and one intersection at a timethen recursively find all intersections between the intersecting parts, it seemsadding only the intersection results also"node" parts that have to be intersectedno intersections with all other geometriesintersections (i.e. we have cut it up as much as possible):
def isecs(g, geoms):
for og in geoms:
if og != g:
if og.crosses(g):
yield g.intersection(og)
def process(isecs):
parts = []
for g in isecs:
isecs = getisecs(g, isecs)
if no isecs:
# "node" reached
parts += g
else:
# this is the recursive part
parts += process(isecs)
return parts
for f in features:
top_isecs = isecs(f.geom, features.bbox_overlaps(f.bbox))
parts = process(top_isecs)
for g in parts:
addfeat(g)
Correction
@Vince correctly pointed out that the ArcGis operation is called union, theirinstead of intersection results, and so onas I first wrote. This is where I get confused and where it will possibly become too slownot to be useful.
Hopefully there is a simple logicconfused that im just not realizingwe are looking for geometrical unions, maybeArcGis is simply referring to the fact that they are returning all (hence union) geometrical intersections: "Union calculates the geometric intersection of any number of feature class..." They also allow returning an actual geometrical union through a combination of intersections and differences, or recursive functionsdissolve option.