Get smallest extent from a list of rasters - different approach

4190
19
Jump to solution
01-22-2016 03:44 AM
Andreas
New Contributor III

Original thread located here: Get smallest extent from a list of rasters

I had issues with that method, if some extents do not overlap, arcgis extent is "empty" while the above minof is (always?) still a rectangle!
In the docs it is said thats minof is the intersection of inputs. But that seems not to be a Intersect_analyst-equivalent. I tried with three extent objects, two do not overlap and one overlaps all other.

Message was edited by: Xander Bakker (branched to new thread)

0 Kudos
19 Replies
XanderBakker
Esri Esteemed Contributor

... or one can use the polygon property of the extent and use the intersect method of the polygon like this:

import arcpy
ext1 = arcpy.Extent(1, 1, 4, 4)
ext2 = arcpy.Extent(2, 2, 5, 5)
print ext1.polygon.intersect(ext2.polygon, 4).extent

which returns:

2,00000190734863 2,00000190734863 4,00000190734863 4,00000190734863 NaN NaN NaN NaN

It will return:

1,#QNAN 1,#QNAN 1,#QNAN 1,#QNAN NaN NaN NaN NaN

... when there is no intersecting polygon.

DanPatterson_Retired
MVP Emeritus

Xander... and to add... make sure there is a defined coordinate system or the extent values will be returned in single precision rather than double as evidenced by your examples.

0 Kudos
Andreas
New Contributor III

This looks really good, thought about something like this, but had no success. Do you think it is "enough", testing the overlaps in a single for-loop? If I understand the code right, you take the first extent and compare to it to the remaining. For example if the first extent in list overlaps all others, but the second does not overlaps the third. Could we somehow "sort" the polygons or should we use a nested for-loop to check every combination. I tend to look inside an open source product to find a similar operation...

0 Kudos
Andreas
New Contributor III

I tried out a few example extents: It works, order seems not to be important.

So, thank you very, very much for contributing your code!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Could you mark the post that answered your question as the correct answer? This way other members will be able to find the answer to similar question more easy. Thank you!

0 Kudos
XanderBakker
Esri Esteemed Contributor

To explain a bit what the loop pretends to do:

  • It takes the first element of the list of extents and uses it as the initial extent
  • Then it starts to loop through the other extents (element 2 until n)
  • if there is overlap between the initial extent and the other extent, it determines the intersecting extent
  • then it continues with the next extent and checks overlap with the intersecting extent
  • and so on.

There is no need to validate overlaps (intersects) between all extents. If in some situation there is no intersect, it will abort the loop and return None (which you should check for).

Andreas
New Contributor III

So true, that's why you store the return of getOverlapExtents in ext, oversawed this... clever!

DanPatterson_Retired
MVP Emeritus

you should then mark Xander's correct ... assumed answered ... is usually used by moderators, not by people who post questions

0 Kudos
Andreas
New Contributor III

I tried before, the only option I had was "richtige Antwort" (correct answer) and then it gets "assumed answered"...

0 Kudos
DanPatterson_Retired
MVP Emeritus

you fixed it...

0 Kudos