AnsweredAssumed Answered

Magical, non-existent numbers appear when copying extent

Question asked by MollyKFoley on Oct 31, 2018
Latest reply on Oct 31, 2018 by MollyKFoley

I have a script that creates an extent based on multiple layers' extents. This is so the resulting map fits all the layers and doesn't cut any of them off. I've cobbled together the final extent by comparing XMax, YMax, XMin, and YMin values of all the layers' extents for maximums/minimums. After doing that, I copy the data frame to a variable as it says to do in the documentation, make my changes to the variable, then I set the data frame extent (df.extent) to the new extent. When I use a print statement to compare the built extent to the final extent, there are magical numbers that appear out of nowhere. These numbers never appear anywhere except in that final extent, they are never an XMax, YMax, XMin, or YMin value for any of the layers' extents. I don't know why it's occurring and it's driving me crazy. I have checked that the data frame and all the layers have the same spatial reference; they do.

 

The script with an obnoxious amount of print statements:

#Get specific cip and find it's extent
cipLyr = arcpy.mapping.ListLayers(mxd, "FocalReferenceAreas", df)[0]
print "starting df.extent: {0}".format(df.extent)
print "---------"
expression = "StateID = '"+state+"' AND Name = '"+cipArea+"'"
arcpy.SelectLayerByAttribute_management(cipLyr, "NEW_SELECTION", expression)
#Store extent numbers to compare later and select the largest extent that will encompass all layers
x_Min = []
y_Min = []
x_Max = []
y_Max = []

#Find the extent
cipExtent = cipLyr.getSelectedExtent()
print "cipExtent: {0}".format(cipExtent)
print "---------"
x_Min.append(cipExtent.XMin)
y_Min.append(cipExtent.YMin)
x_Max.append(cipExtent.XMax)
y_Max.append(cipExtent.YMax)


for layer in mapLyrs:
    #Determine if the all the patches are contained in the current extent if the patches layer is visible
    if layer.name == "Patches":
        if layer.visible:
            #Select all the patches polygons within 300 meters of the focal/reference area
            arcpy.SelectLayerByLocation_management(layer, "WITHIN_A_DISTANCE", cipLyr, "300 Meters", "NEW_SELECTION")
            #Get the patches layer extent
            patchExtent = layer.getSelectedExtent()
            print "patchExtent: {0}".format(patchExtent)
            x_Max.append(patchExtent.XMax)
            x_Min.append(patchExtent.XMin)
            y_Max.append(patchExtent.YMax)
            y_Min.append(patchExtent.YMin)
            arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
    elif layer.name == "Protective Cover":
        if layer.visible:
            #Select all the protective cover polygons within 300 meters of the focal/reference area
            arcpy.SelectLayerByLocation_management(layer, "WITHIN_A_DISTANCE", cipLyr, "300 Meters", "NEW_SELECTION")
            #Get the protective cover layer extent
            pcExtent = layer.getSelectedExtent()
            print "pcExtent: {0}".format(pcExtent)
            x_Max.append(pcExtent.XMax)
            x_Min.append(pcExtent.XMin)
            y_Max.append(pcExtent.YMax)
            y_Min.append(pcExtent.YMin)
            arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
    elif layer.name == "MgmtTracts":
        if layer.visible:
            #Select all the habitat management tracts that intersect the focal/reference area
            arcpy.SelectLayerByLocation_management(layer, "INTERSECT", cipLyr)
            #Get the habitat managment tracts layer extent
            tractsExtent = layer.getSelectedExtent()
            print "tractsExtent: {0}".format(tractsExtent)
            x_Max.append(tractsExtent.XMax)
            x_Min.append(tractsExtent.XMin)
            y_Max.append(tractsExtent.YMax)
            y_Min.append(tractsExtent.YMin)
            arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
    elif layer.name == "MgmtLines":
        if layer.visible:
            #Select all the habitat management lines that intersect the focal/reference area
            arcpy.SelectLayerByLocation_management(layer, "INTERSECT", cipLyr)
            #Get the habitat management lines layer extent
            linesExtent = layer.getSelectedExtent()
            print "linesExtent: {0}".format(linesExtent)
            x_Max.append(linesExtent.XMax)
            x_Min.append(linesExtent.XMin)
            y_Max.append(linesExtent.YMax)
            y_Min.append(linesExtent.YMin)
            arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(cipLyr, "CLEAR_SELECTION")
#Set the extent to contain all the layers
print "---------"
print "extent BEFORE copying df.extent to newExtent: {0}".format(df.extent)
print "---------"
newExtent = df.extent
print "extent AFTER copying df.extent to newExtent: {0}".format(df.extent)
print "---------"
print "x_Min comparison list: {0}".format(x_Min)
print "y_Min comparison list: {0}".format(y_Min)
print "x_Max comparison list: {0}".format(x_Max)
print "y_Max comparison list: {0}".format(y_Max)
print "---------"
print "minimum XMin value in list: " + str(min(x_Min))
print "minimum YMin value in list: " + str(min(y_Min))
print "maximum XMax value in list: " + str(max(x_Max))
print "maximum YMax value in list: " + str(max(y_Max))
print "---------"
newExtent.XMin = min(x_Min)
newExtent.YMin = min(y_Min)
newExtent.XMax = max(x_Max)
newExtent.YMax = max(y_Max)
print "Below values should match above minimums and maximums:"
print "newExtent XMin: " + str(newExtent.XMin)
print "newExtent YMin: " + str(newExtent.YMin)
print "newExtent XMax: " + str(newExtent.XMax)
print "newExtent YMax: " + str(newExtent.YMax)
print "---------"
print "newExtent final: {0}".format(newExtent)
print "---------"
df.extent = newExtent
print "Final extent: {0}".format(df.extent)

 

This is the output from all the print statements. Notice the "new extent" and "final extent" at the end of the statements...there are numbers in the "final extent" that don't exist anywhere else (I've bolded them).

starting df.extent: 1533861.54511675 426555.628626971 1541100.91356032 434570.97195742 NaN NaN NaN NaN
---------
cipExtent: 1535017.21765266 427201.261152659 1540133.20164734 433957.569247342 NaN NaN NaN NaN
---------
linesExtent: 1534796.93235266 429153.130752659 1536887.21244734 432384.864647341 NaN NaN NaN NaN
tractsExtent: 1533828.42795266 428220.355552659 1536553.66684734 430424.343547342 NaN NaN NaN NaN
pcExtent: 1535099.09656317 428464.435363164 1539795.25313683 433982.943636835 NaN NaN NaN NaN
patchExtent: 1534893.23131053 428462.935110533 1539815.37038947 434098.184889468 NaN NaN NaN NaN
---------
extent BEFORE copying df.extent to newExtent: 1533861.54511675 426555.628626971 1541100.91356032 434570.97195742 NaN NaN NaN NaN
---------
extent AFTER copying df.extent to newExtent: 1533861.54511675 426555.628626971 1541100.91356032 434570.97195742 NaN NaN NaN NaN
---------
x_Min comparison list: [1535017.2176526603, 1534796.9323526586, 1533828.4279526586, 1535099.096563166, 1534893.2313105324]
y_Min comparison list: [427201.26115265896, 429153.1307526589, 428220.35555265885, 428464.4353631643, 428462.93511053256]
x_Max comparison list: [1540133.2016473408, 1536887.212447341, 1536553.6668473403, 1539795.253136834, 1539815.3703894683]
y_Max comparison list: [433957.56924734224, 432384.8646473415, 430424.343547342, 433982.9436368345, 434098.1848894685]
---------
minimum XMin value in list: 1533828.42795
minimum YMin value in list: 427201.261153
maximum XMax value in list: 1540133.20165
maximum YMax value in list: 434098.184889
---------
Below values should match above minimums and maximums:
newExtent XMin: 1533828.42795
newExtent YMin: 427201.261153
newExtent XMax: 1540133.20165
newExtent YMax: 434098.184889
---------
newExtent final: 1533828.42795266 427201.261152659 1540133.20164734 434098.184889468 NaN NaN NaN NaN
---------
Final extent: 1533828.42795266 427159.437495633 1540133.20164734 434140.008546494 NaN NaN NaN NaN

Outcomes