I have two layers in different SDE connections, one is Project layer and another one is Rail crossing layer which is very huge(more than 200k records). I have to find out the railcrossing feature for each project under one mile buffer radius of each project to accomplish this I created a loop and iterate through each project feature, create a buffer and then query the railcrossing feature layer using SelectLayerByLocation_management() then I got the result but the problem is in order to use SelectLayerByLocation_management() I have to use MakeFeatureLayer_management() for both railcrossing and projectlocations because SelectLayerByLocation_management() can only perform on layers and I can't use the featureclass paths of them so I have to perform MakeFeatureLayer_management() every time iterating the loop which is hitting performance( taking 10 seconds for railroad crossing layer). Can any one suggest other alternate solution for this to minimize the performance issue. Here is the sample code
arcpy.Buffer_analysis("tempQueryLayer", "bufferOutPut", "1 Miles")
arcpy.MakeFeatureLayer_management("bufferOutPut", "bufferLayer")
arcpy.MakeFeatureLayer_management(RAILCROSSING, "railCrossingTempLayer")
arcpy.SelectLayerByLocation_management( "railCrossingTempLayer","COMPLETELY_WITHIN","bufferLayer" )