arcpy.MakeFeatureLayer_management performance issue

711
3
01-24-2020 07:26 AM
pramodmandali
New Contributor

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" )

 

Tags (2)
0 Kudos
3 Replies
DavidPike
MVP Frequent Contributor

Hi,

There shouldn't be a need to create the buffers as the sb location tool has a 'within x distance' option. I also think only the data being selected has to be turned into a layer.

A spatial join may be faster, then clean up the data after (or use a one to many join with delimiters) or you could use the describe() object for your features to look for coincident geometries.

Good luck

0 Kudos
pramodmandali
New Contributor

Hi David,

Thanks for you're reply. I am using "Completely Within" .  sb_location tool will not take that parameter if it is "completely within" .

0 Kudos
DavidPike
MVP Frequent Contributor

Hi Pramod,

I see, I'm unsure but that may be a more intensive operation, maybe use within with a large xy tolerance to first subset the selection, the run completely within on that subset? Good luck!

0 Kudos