2

I am using ArcGIS Engine 10.5.1.

I wanted to ask and see if anyone else has encountered this and or found a work around. I have a loop in c# where I am taking a large set of layer files and adding them to the map. I have tried this two ways but both ways seem to be equally slow (~10 minutes for ~180 layers). The contents of the layers files are just shape objects. Not a lot of data. The first way I tried to achieve this is

IGroupLayer groupLayer = new GroupLayer();
foreach(SortedListLayers layer in MySortedListLayers)
{
    ILayerFile layerfile = new LayerFile();
    layerfile.Open(layer.location);
    groupLayer.Add(layerfile.Layer);
    layerfile.Close();
}

On the groupLayer.Add line there is more and more overhead each time the call is made to complete adding the layerfile.Layer to the group even though the group is not yet on the map. My alternative was to use IMapLayers and implement IEnumLayers on my SortedListLayers object (which only contains a sorted list of 'layers' and the location that it belongs to) and use the maplayers.InsertLayersInGroup call to try to diminish looping but that turned out even slower.

8
  • Does it take as long just to loop through the file list and add the layers to a List<ILayer> with no GroupLayer involved? Commented Jun 12, 2018 at 0:50
  • Did you try calling ReleaseComObject on layerfile at the bottom of the loop? Commented Jun 12, 2018 at 0:53
  • I did try both. It takes a good amount of time without the group layer but eventually it needs to go in one, which also takes a fair amount of time. And I did try releasing the object each iteration but it did not seem to have an impact. I even tried to create a single instance of the layer file and just re-use it but that actually ended up bieng slower
    – WezeW
    Commented Jun 12, 2018 at 0:55
  • By "shape objects" do you mean shapefiles? If so, are the shapefiles on a network share folder? If you save the resulting grouplayer to a layerfile, does it take long to load into the map manually? Commented Jun 12, 2018 at 1:00
  • Yes shapefiles with metadata. I hear shapefiles in general are pretty slow working with layerfiles but I couldn't have imagined this. This is all local machine work. I haven't tried that option before though
    – WezeW
    Commented Jun 12, 2018 at 1:02

0