ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / LayerDocument Class
Members Example

In This Topic
    LayerDocument Class
    In This Topic
    Represents the content of a .lyrx file that contains one or more layers, all their properties including binary references etc.
    Object Model
    LayerDocument ClassCIMLayerDocument Class
    Syntax
    public class LayerDocument : Document 
    Public Class LayerDocument 
       Inherits Document
    Example
    Create FeatureLayer and add to Map using LayerCreationParams
    //Note: Call within QueuedTask.Run()
    var layerDoc = new LayerDocument(@"E:\Data\SDK\Default2DPointSymbols.lyrx");
    var createParams = new LayerCreationParams(layerDoc.GetCIMLayerDocument());
    LayerFactory.Instance.CreateLayer<FeatureLayer>(createParams, MapView.Active.Map);
    Create layer from a lyrx file
    var lyrDocFromLyrxFile = new LayerDocument(@"d:\data\cities.lyrx");
    var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
    
    //modifying its renderer symbol to red
    var r = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMSimpleRenderer;
    r.Symbol.Symbol.SetColor(new CIMRGBColor() { R = 255 });
    
    //optionally save the updates out as a file
    lyrDocFromLyrxFile.Save(@"c:\data\cities_red.lyrx");
    
    //get a json representation of the layer document and you want store away...
    var aJSONString = lyrDocFromLyrxFile.AsJson();
    
    //... and load it back when needed
    lyrDocFromLyrxFile.Load(aJSONString);
    cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
    
    //create a layer and add it to a map
    var lcp = new LayerCreationParams(cimLyrDoc);
    var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, map);
    Apply Symbology to a layer from a Layer file
    //Note: Run within QueuedTask.Run
    //Get the Layer Document from the lyrx file
    var lyrDocFromLyrxFile = new LayerDocument(layerFile);
    var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
    
    //Get the renderer from the layer file
    var rendererFromLayerFile = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMUniqueValueRenderer;
    
    //Apply the renderer to the feature layer
    //Note: If working with a raster layer, use the SetColorizer method.
    featureLayer?.SetRenderer(rendererFromLayerFile);
    Create a Lyrx file
    LayerDocument layerDocument = new LayerDocument(layer);
    layerDocument.Save(@"c:\Data\MyLayerDocument.lyrx");
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Mapping.Document
          ArcGIS.Desktop.Mapping.LayerDocument

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also