I am trying find the best way to find the full path of a shapefile, which is open in the active map. Or in other words, I want to find a way to know if the feature layer in the active map is a shapefile or not. I "think" I saw it somewhere in the SDK snippets github pages, but I cannot track it now. Anyway, here is what I did:
- string SelectedShapefileLayer = "Some_feature_in_map";
- string fcLocation = ""; // Location of feature layer: either a FGDB or a folder //
- string fcName = ""; // ACTUAL name of feature layer //
- await QueuedTask.Run(() =>
- {
- var fcLyr = (FeatureLayer)MapView.Active.Map.FindLayers(SelectedFeatureLayer).First();
- Uri fcURI = fcLyr.GetTable().GetDatastore().GetPath();
- fcLocation = fcURI.LocalPath;
- fcName = fcLyr.GetTable().GetDefinition().GetName(); // Displayed name may not be ACTUAL name //
- });
-
- string fcPath = ""; // Full path of feature layer //
- if (Path.GetExtension(fcLocation) == "")
- {
- // If feature layer is a shapefile //
- fcPath = Path.Combine(fcLocation, fcName + ".shp");
- }
- else
- {
- // if feature layer is a FGDB feature class //
- fcPath = Path.Combine(fcLocation, fcName);
- }
I would be grateful if anyone could help me find a better way to do this. Surely, there must be a better way.
In the above code, I have assigned all feature layer WITHOUT an extension as a FGDB feature class, and others as a shapefile. I think that could run into trouble as well.
Many thanks in advance.
Kenny