ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / LayerFactory Class / CreateLayers Method / CreateLayers(BulkLayerCreationParams,ILayerContainerEdit) Method
A BulkLayerCreationParams object.
A map or group layer where the Layers will be added.
Example

In This Topic
    CreateLayers(BulkLayerCreationParams,ILayerContainerEdit) Method
    In This Topic
    Creates a readonly list of new Layer instances using the specified BulkLayerCreationParams and adds it to a container such as a map. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    layerParams
    A BulkLayerCreationParams object.
    container
    A map or group layer where the Layers will be added.

    Return Value

    A Readonly list of Layer.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    layerParams or container is null.
    An elevation surface layer cannot be used as a container for bulk layer creation.
    Unable to bulk create layers with a combination of standard and custom items.
    Unable to bulk create layers with data supplied as a mixture of Uris, Items and data connections.
    Unable to bulk create layers with the supplied child LayerCreationParams.
    Remarks
    The bulk layer creation process creates the layers it is able to per the data supplied. If invalid Uris, data connections or Items exist amongst valid data, then there may be a mismatch in the number of layers created compared to the number of data items supplied. For example, 5 Uris are supplied, but only 4 layers are created because one of the Uris points to a dataset that does not exist. LayerFactory.CreateLayers will return the layers added, but no information regarding the invalid dataset. The only exception to this is if all datasets are invalid (and no layers are created); in this scenario an System.ArgumentException will be thrown.

    See the BulkLayerCreationParams.RollbackBehavior for information about rollback options with bulk layer creation when the BulkLayerCreationParams object is created with a set of LayerCreationParams objects.

    Example
    Create multiple layers with BulkLayerCreationParams 1
    var uriShp = new Uri(@"c:\data\roads.shp");
    var uriSde = new Uri(@"c:\MyDataConnections\MySDE.sde\Census");
    var uri = new Uri(@"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0");
    
    var uris = new List<Uri>() { uriShp, uriSde, uri }; ;
    
    // set the index and visibility
    var blkParams = new BulkLayerCreationParams(uris);
    blkParams.MapMemberPosition = MapMemberPosition.Index;
    blkParams.MapMemberIndex = 2;
    blkParams.IsVisible = false;
    
    var layers = LayerFactory.Instance.CreateLayers(blkParams, MapView.Active.Map);
    Create multiple layers with BulkLayerCreationParams 2 - invalid
    var uriShp = new Uri(@"c:\data\roads.shp");
    var lcpShp = new FeatureLayerCreationParams(uriShp);
    lcpShp.Name = "Roads";
    lcpShp.IsVisible = false;
    lcpShp.DefinitionQuery = new DefinitionQuery("shpQuery", "OBJECTID > 10");
    
    var lcpItem = new FeatureLayerCreationParams(Item);
    lcpItem.Name = "Census Polygons";
    lcpItem.IsVisible = true;
    
    // list contains a Uri data source and an Item data source
    // LayerFactory.Instance.CreateLayers will throw an ArgumentException
    var lcps = new List<FeatureLayerCreationParams>();
    lcps.Add(lcpShp);
    lcps.Add(lcpItem);
    
    var blkParams = new BulkLayerCreationParams(lcps);
    
    // LayerFactory.Instance.CreateLayers will thrown an ArgumentException
    // because the LayerCreationParams are created using different 
    // types of data sources (1 Uri and 1 Item)
    var layers = LayerFactory.Instance.CreateLayers(blkParams, MapView.Active.Map);
    Create multiple layers with BulkLayerCreationParams 2 - Valid
    var uriShp = new Uri(@"c:\data\roads.shp");
    var uriSde = new Uri(@"c:\MyDataConnections\MySDE.sde\Census");
    var uri = new Uri(@"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0");
    
    var lcpShp = new FeatureLayerCreationParams(uriShp);
    lcpShp.Name = "Roads";
    lcpShp.IsVisible = false;
    lcpShp.DefinitionQuery = new DefinitionQuery("shpQuery", "OBJECTID > 10");
    
    var lcpSde = new FeatureLayerCreationParams(uriSde);
    lcpSde.Name = "Census Polygons";
    lcpSde.IsVisible = true;
    
    var lcpService = new FeatureLayerCreationParams(uri);
    lcpService.Name = "Shelters";
    lcpService.IsVisible = true;
    // set some renderer here ...
    //lcpService.RendererDefinition = ...
    
    var lcps = new List<FeatureLayerCreationParams>();
    lcps.Add(lcpShp);
    lcps.Add(lcpSde);
    lcps.Add(lcpService);
    
    var blkParams = new BulkLayerCreationParams(lcps);
    // set the positioning on the BulkLayerCreationParams
    blkParams.MapMemberPosition = MapMemberPosition.Index;
    blkParams.MapMemberIndex = 0;
    
    var layers = LayerFactory.Instance.CreateLayers(blkParams, MapView.Active.Map);
    Create multiple layers with BulkLayerCreationParams - Using RollbackBehavior
    var uriShp = new Uri(@"c:\data\roads.shp");
    var uriSde = new Uri(@"c:\MyDataConnections\MySDE.sde\Census");
    var uri = new Uri(@"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0");
    
    var lcpShp = new FeatureLayerCreationParams(uriShp);
    lcpShp.Name = "Roads";
    lcpShp.IsVisible = false;
    lcpShp.DefinitionQuery = new DefinitionQuery("shpQuery", "OBJECTID > 10");
    
    var lcpSde = new FeatureLayerCreationParams(uriSde);
    lcpSde.Name = "Census Polygons";
    lcpSde.IsVisible = true;
    
    var lcpService = new FeatureLayerCreationParams(uri);
    lcpService.Name = "Shelters";
    lcpService.IsVisible = true;
    // set some renderer here ...
    //lcpService.RendererDefinition = ...
    
    var lcps = new List<FeatureLayerCreationParams>();
    lcps.Add(lcpShp);
    lcps.Add(lcpSde);
    lcps.Add(lcpService);
    
    var blkParams = new BulkLayerCreationParams(lcps);
    // set the positioning on the BulkLayerCreationParams
    blkParams.MapMemberPosition = MapMemberPosition.Index;
    blkParams.MapMemberIndex = 0;
    
    // set the rollback behavior
    // - rollback if one or more layers cannot be created due to an invalid data source
    blkParams.RollbackBehavior = LayerCreationRollbackBehavior.RollbackOnMissingLayers;
    
    var layers = LayerFactory.Instance.CreateLayers(blkParams, MapView.Active.Map);
    Add a GeoPackage to the Map
    string pathToGeoPackage = @"C:\Data\Geopackage\flooding.gpkg";
    //Create lists to hold the URIs of the layers and tables in the geopackage
    var layerUris = new List<Uri>();
    var tableUris = new List<Uri>();
    //Create an item from the geopackage
    var item = ItemFactory.Instance.Create(pathToGeoPackage, ItemFactory.ItemType.PathItem);
    var children = item.GetItems();
    //Collect the table and spatial data in the geopackage
    foreach (var child in children)
    {
      var childPath = child.Path;
    
      if (child.TypeID == "sqlite_table")
        tableUris.Add(new Uri(childPath));
      else
        layerUris.Add(new Uri(childPath));
    }
    //Add the spatial data in the geopackage using the BulkLayerCreationParams
    if (layerUris.Count > 0)
    {
      BulkLayerCreationParams bulklcp = new BulkLayerCreationParams(layerUris);
      LayerFactory.Instance.CreateLayers(bulklcp, MapView.Active.Map);
    }
    // add the tables separately
    foreach (var tableUri in tableUris)
    {
      StandaloneTableFactory.Instance.CreateStandaloneTable(tableUri, MapView.Active.Map);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.4 or higher.
    See Also