ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / LayerFactory Class / CreateLayers Method / CreateLayers(IEnumerable<Uri>,ILayerContainerEdit,Int32) Method
The set of URIs that represent the path to a set of datasets.
A map or group layer where the Layers will be added.
The position of the first Layer in the map or group layer. 0 represents the top most position.
Example

In This Topic
    CreateLayers(IEnumerable<Uri>,ILayerContainerEdit,Int32) Method
    In This Topic
    Creates a readonly list of new Layer instance for each of the specified dataset paths and adds them to a container such as a map. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    layerUris
    The set of URIs that represent the path to a set of datasets.
    container
    A map or group layer where the Layers will be added.
    index
    The position of the first Layer in the map or group layer. 0 represents the top most position.

    Return Value

    A Readonly list of Layer.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    layerUris or container is null.
    An elevation surface layer cannot be used as a container for bulk layer creation.
    Remarks

    Some sample paths to:

    A FeatureClass in a FileGeodatabase C:\Data\MyFileGDB.gdb\Census
    A shape file in a folder \\Machine\SharedFolder\MySpatialData.dbf
    A RasterDataset in a FileGeodatabase C:\Data\MyFileGDB.gdb\DEM
    A FeatureClass from a SDE C:\Connections\MySDEConnection.sde\Roads
    An image file in a folder \\Machine\SharedFolder\Imagery.tif
    A .lyrx or .lpkx file \\Machine\SharedFolder\Fires.lyrx
    A map service layer http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer
    A feature layer off a map or feature service http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0

    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, there will 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 created, 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.
    Example
    Create multiple layers
    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 };
    
    var layers = LayerFactory.Instance.CreateLayers(uris, MapView.Active.Map);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.4 or higher.
    See Also