How to access to layer properties with C# and ArcGIS Pro SDK?

908
3
Jump to solution
03-03-2020 09:31 AM
OguzSariyildiz
Occasional Contributor

I created the layer but also I would like to retrieve layer properties such as geometry type, coord system etc. 

System.Uri shp_filepath = new System.Uri(@shp_path);
QueuedTask.Run(() =>
{
var shp_layer = LayerFactory.Instance.CreateLayer
(shp_filepath, MapView.Active.Map, indexNumber, shp_path.Substring(16));

//Get the active map view.
var mapView = MapView.Active;
var layerDescription = shp_layer.GetDefinition().Description; //This gives only the name but I need other properties too

if (mapView == null)
return Task.FromResult(false);
else
{
var selectedLayer = mapView.GetSelectedLayers()[0];

return mapView.ZoomToAsync(selectedLayer);
}
});

Thanks!

0 Kudos
1 Solution

Accepted Solutions
OguzSariyildiz
Occasional Contributor

Projection info can be accessed by 

var layer_projection = active_Layer.GetSpatialReference();
projection_name = layer_projection.Name;

For the vector type, I just search through the Shape field in the attribute table. 


using (ArcGIS.Core.Data.Table shp_table = (active_Layer as FeatureLayer).GetTable())
{
   using (RowCursor rowCursor = shp_table.Search())
   {
      while (rowCursor.MoveNext())
      {
         using (ArcGIS.Core.Data.Row row = rowCursor.Current)
         {
            if (row["Shape"] != null && row["Shape"].ToString() != " ")
            {
               geometry_type = (string)row["Shape"].ToString();
            }
         }
      }
   }
}

This method still cannot help to distinguish between polygon and polygon ZM

View solution in original post

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi,

Cast the definition retrieved into CIMFeatureLayer. Like this:

var lyrDef = shp_layer.GetDefinition() as CIMFeatureLayer;
0 Kudos
OguzSariyildiz
Occasional Contributor

Ok, I did that. 

Now, How can I get coordination system and the geometry type as string? 

Thanks!

Oz

0 Kudos
OguzSariyildiz
Occasional Contributor

Projection info can be accessed by 

var layer_projection = active_Layer.GetSpatialReference();
projection_name = layer_projection.Name;

For the vector type, I just search through the Shape field in the attribute table. 


using (ArcGIS.Core.Data.Table shp_table = (active_Layer as FeatureLayer).GetTable())
{
   using (RowCursor rowCursor = shp_table.Search())
   {
      while (rowCursor.MoveNext())
      {
         using (ArcGIS.Core.Data.Row row = rowCursor.Current)
         {
            if (row["Shape"] != null && row["Shape"].ToString() != " ")
            {
               geometry_type = (string)row["Shape"].ToString();
            }
         }
      }
   }
}

This method still cannot help to distinguish between polygon and polygon ZM

View solution in original post

0 Kudos