The larger goal with this code is to create a temporary polygon based on the calculated coordinates (which it does), then to see if the polygon intersects with the "unobscured_FC". After I run the select by location the polygon will be deleted, and all sorts of other hilarity will ensue. I only need the temporary polygon for the select.
Now, I've read that you can't run arcpy.SelectLayerByLocation_management() on shapefiles or feature classes, which is why I tried to make feature layers from the two. However, despite that, I'm getting this error:
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).
I've searched thoroughly for an answer to this problem, and they all appear to be telling me that I need to do exactly what I'm already doing.
How am I failing here to make both of these into feature layers?
Code below...
unobscured_FC = r"C:\example.gdb\example_FC"
arcpy.MakeFeatureLayer_management(unobscured_FC, "unobscured_lyr")
#These coordinates are calculated above in a code block I've excluded...
coordList = [[[Xmax,Ymax], [Xmin,Ymax], [Xmin,Ymin], [Xmax,Ymin]]]
point = arcpy.Point()
array = arcpy.Array()
featureList = []
for feature in coordList:
for coordPair in feature:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
array.add(array.getObject(0))
polygon = arcpy.Polygon(array)
array.removeAll()
featureList.append(polygon)
tempShape = os.path.join(sys.path[0], "temp.shp")
arcpy.CopyFeatures_management(featureList, tempShape)
arcpy.MakeFeatureLayer_management(tempShape, "tempShape_lyr")
arcpy.SelectLayerByLocation_management("unobscured_lyr", "INTERSECT", "tempShape_lyr", "", "NEW_SELECTION")
MakeFeatureLayer_management
will work on shapefiles. Can you copy your temp polygon into a temp GDB instead?