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!
Solved! Go to Solution.
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
Hi,
Cast the definition retrieved into CIMFeatureLayer. Like this:
var lyrDef = shp_layer.GetDefinition() as CIMFeatureLayer;
Ok, I did that.
Now, How can I get coordination system and the geometry type as string?
Thanks!
Oz
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
Thanks for posting this solution, it was something I needed to do. Have you found any other methods for determining the geometry type of a feature layer? Your posted solution works, BUT it is excruciatingly sloooow - it took over 15 seconds to determine the geometry type for 2 layers...
Sorry, I just saw your message. Probably, there is a better solution for this but for a faster response, you can return after reading one row only. As we know, shapefile geometry should be consistent for all the records on the attribute table. The solution above reads all rows before returning the geometry.
Yes, that is what I was doing, but still molasses slow. But I stumbled upon a solution that works much better: cast your featurelayer to a BasicFeatureLayer which has a ShapeType property. This little snippet creates a list of selected layers that match a specified geometry type. Fore some reason GeoNet doesn't give me the option for inserting "code".
dctLookup = new Dictionary<string, esriGeometryType>();
dctLookup.Add("POINT", esriGeometryType.esriGeometryPoint);
dctLookup.Add("LINE", esriGeometryType.esriGeometryPolyline);
dctLookup.Add("POLYGON", esriGeometryType.esriGeometryPolygon);
selLays = MapView.Active.GetSelectedLayers();
foreach (Layer lay in selLays)
if (lay.MapLayerType == MapLayerType.Operational)
{
pBFL = lay as BasicFeatureLayer;
if (pBFL != null)
{
for (int i = 0; i < lstTypes.Count; i++)
{
if (pBFL.ShapeType == dctLookup[lstTypes[i]])
{
lstLays[i] = lay;
}
}
}
}
return lstLays;