Select to view content in your preferred language

How to add layer file (.lyrx) to ArcGIS Pro using Pro SDK.Net

1968
3
Jump to solution
02-15-2022 11:02 PM
by Anonymous User
Not applicable

Hi,

I just want to use the ArcGIS Pro SDK to add the two layer files(.lyrx). Could someone please assist me with this?

I attempted to use LayerDocument(), but it would be greatly appreciated if someone could provide a sample for the same.

Wanted to add the layer file on TOC.

 

 

Thanks in advance!

0 Kudos
2 Solutions

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi ,

There are a few examples in this page that can help you: ProSnippets: Map Authoring.

Check out this snippet: create-layer-from-a-lyrx-file 

Thanks!

Uma

View solution in original post

0 Kudos
RobBurke
Occasional Contributor

Hi Shabina,

Have you tried looking at this code snippet?

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-layer-from-a-lyrx-file

I slimmed down that code snippet into fewer lines.  This bit works for me.  Have you confirmed the path to the lyrx file and that the file itself exists?  Also have you enclosed your code in a QueuedTask as shown below?

protected override void OnClick()
{
QueuedTask.Run(() =>
{
var lyrDocFromLyrxFile = new LayerDocument(@"c:\temp\Hurricanes.lyrx");
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();

//create a layer and add it to a map
var lcp = new LayerCreationParams(cimLyrDoc);

var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, MapView.Active.Map);
});
}

Robert Burke

View solution in original post

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi ,

There are a few examples in this page that can help you: ProSnippets: Map Authoring.

Check out this snippet: create-layer-from-a-lyrx-file 

Thanks!

Uma

0 Kudos
RobBurke
Occasional Contributor

Hi Shabina,

Have you tried looking at this code snippet?

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-layer-from-a-lyrx-file

I slimmed down that code snippet into fewer lines.  This bit works for me.  Have you confirmed the path to the lyrx file and that the file itself exists?  Also have you enclosed your code in a QueuedTask as shown below?

protected override void OnClick()
{
QueuedTask.Run(() =>
{
var lyrDocFromLyrxFile = new LayerDocument(@"c:\temp\Hurricanes.lyrx");
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();

//create a layer and add it to a map
var lcp = new LayerCreationParams(cimLyrDoc);

var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, MapView.Active.Map);
});
}

Robert Burke
0 Kudos
by Anonymous User
Not applicable

Thanks a lot @RobBurke I really appreciate your time and effort and yes, it worked pretty well for me.

Thanks @UmaHarano 🙂

0 Kudos