2

I am using an ArcPy script to add a point feature class to an mxd. The map document will draw this layer very slowly, approximately 50 to 100 points per second. If I remove the layer and add it manually, it draws about 20 times faster. the code I use is:

FeatureClass = "path\to\my\fc.gdb\featureclass"
layer = arcpy.mapping.Layer("FeatureClass")
arcpy.mapping.AddLayer(DataFrame, layer, "BOTTOM")

I use this same code to add a polygon layer and it draws just fine. I've tried using this method in an unrelated mxd with an unrelated layer and it drew fine. I've also tried different symbologies, including the Arc standard, and running this on different computers with the same result.

10
  • It could be something with a specific mxd. Can you reproduce this by opening up a blank mxd and executing that same code?
    – crmackey
    Commented Feb 9, 2017 at 14:29
  • My coworkers and I use this script about 10 times a day, on 3 different computers. I've run it both on my local machine and over our in house server, with the same result every time. And just to be clear, that is with quite a few different mxd's.
    – Craig T
    Commented Feb 9, 2017 at 14:31
  • Gotcha, I think I just spotted what was slowing it down. See my answer below.
    – crmackey
    Commented Feb 9, 2017 at 14:36
  • 1
    If your feature class varies in record count by that much regularly, it could be an index problem or could be the gdb just needs a compress. Both of these could be added separately into your script to test
    – Midavalo
    Commented Feb 11, 2017 at 21:22
  • 1
    @CraigT Please edit your question to include extra information and responses, rather than as comments. Potential answerers don't always see all the comments - all relevant info should be in your question.
    – Midavalo
    Commented Feb 11, 2017 at 21:28

1 Answer 1

2

You actually do not have to use arcpy.MakeFeatureLayer_management() first, you can just create an arcpy.mapping.Layer from the feature class itself:

FeatureClass = "path\to\my\fc.gdb\featureclass"
layer = arcpy.mapping.Layer(FeatureClass)
arcpy.mapping.AddLayer(DataFrame, layer, "BOTTOM")

This should add the layer instantly. Maybe your bottleneck was waiting for the make feature layer command to finish.

2
  • The layer was being added anyway, although now that I try it this way it seems that I don't need that line of code. However, the original problem that the layer draws slowly still exists.
    – Craig T
    Commented Feb 9, 2017 at 14:52
  • That is strange. I misunderstood as I thought you meant there was a delay before it even started drawing (from the make feature layer). I don't know what would be different about the layer once it's in the map when it was added manually vs Python. It should behave the same, regardless of how it was added.
    – crmackey
    Commented Feb 9, 2017 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.