Search code examples
pythonarcgisarcpy

Select by location error in python script : "Fetch Geometries" window


I have a python script used as a source code for a ScriptTool in ArcGIS that is supposed to select road segments from a selection by location with a mask (polygon feature class).Everything worked fine until I modified the code to generate a different mask for the selection tool. It seems that since that modification, the modified code as well as the original code both give me the same executing error for the SelectByLocation tool with the INTERSECT condition.

Here is the specific part of the original code :

import arcpy, os, datetime
from arcpy.sa import *

if __name__ == "__main__":

    inRas = r'path\Raster_for_mask'
    inRR = r'path\roads'
    arcpy.env.overwriteOutput = True

    # Mask creation based on the raster file
    arcpy.CheckOutExtension('Spatial')
    maskZIr = arcpy.Raster(inRas)>-10000
    maskZIs = 'Zone_inondee'
    arcpy.RasterToPolygon_conversion(maskZIr,maskZIs)

    # Road features selections by the mask ############################
    inRRLayer = 'inRRLayer'
    arcpy.MakeFeatureLayer_management(inRR, inRRLayer)
    arcpy.SelectLayerByLocation_management(inRRLayer,"INTERSECT",maskZIs)

And here is the modified code :

import arcpy, os, datetime
from arcpy.sa import *

if __name__ == "__main__":

inRas = r'path\Raster_for_mask'
inRR = r'path\roads'
arcpy.env.overwriteOutput = True

    ## Real mask to select road features that I want
    maskZIr = arcpy.Raster(inRas)
    maskZIr2 = SetNull(maskZIr,maskZIr,"VALUE = 0") # Erase the error zones of the raster before conversion to polygon
    maskZIr3 = Int(maskZIr2)
    maskZIr4 = 'Zone_inondee_multipart'
    arcpy.RasterToPolygon_conversion(maskZIr3,maskZIr4)
    maskZIs = 'Zone_inondee'
    arcpy.Dissolve_management(maskZIr4,maskZIs) # Singlepart polygon mask
    ##################################

    # Road features selections by the mask ############################
    inRRLayer = 'inRRLayer'
    arcpy.MakeFeatureLayer_management(inRR, inRRLayer)
    arcpy.SelectLayerByLocation_management(inRRLayer,"INTERSECT",maskZIs)

(The paths for the files are fake ones just for demonstration purposes)

Concerning the error, a small window named "AddList" appears with only "FetchGeometries" written in it, along with an OK button. When clicked, I get an function execution error for the SelectByLocation_management tool (unknown 999999 Error). This happens too if I run my unmodified code, that worked fine before. I verified both files used to run the selection tool but they are both in the right format (shapefile, polygon type for the mask and lines for the roads) and populated right. I looked up everywhere on the internet and it appears that nobody had that problem before...

Check a screen shot of the issue : https://i.sstatic.net/f7Yiu.jpg.

The problem isn't that much the code itself because it worked fine before but I just can't trace back the source of that error. The code blocks just indicate the context in which the error occured. My guts suggest that something went wrong at some point with the MakeFeatureLayer_management tool. Also, using the source file for the roads without making a feature layer gives an error for non valid parameters for the selection tool.

So my question here is : have you ever seen this error ? And if so, was it with the same geoprocessing tool and how do you get rid of it ?

Thank you guys.


For info I just started learning python and arcpy two months ago for an internship. This is my first ever post here so I apologize in advance if my problem is unclear to some of you.


Solution

  • I am also relatively new to the ArcPy environment, and had the exact same problem on Arc 10.3.

    The issue seems to be that ArcMap loses permission to access the personal geodatabase (MDB) that I was working with and could no longer read from or write to it. I do not have this problem with file geodatabases (GDB) or a folder full of shapefiles on the Windows filesystem.

    Until this is resolved by Esri, it seems the best bet is to avoid personal geodatabases if you can.