Feature Layer Type. Shape vs Geodatabase vs AGOL/Portal Feature Service Passed to geoprocessing tool

513
2
Jump to solution
04-06-2022 09:33 AM
VastBeta
New Contributor II

I am trying to pass layers on a map to the intersect geoprocessing tool. For local data sources like shapefiles and geodatabase features the script is working fine but when the layer is a feature Service from AGOL or Portal it isn't working unless I use lyr.GetPath().ToString(). Is there a way to pass a layer to a geoprocessing tool regardless of if it is a shp, GDB, or feature service? Or is there a way to tell which ones are feature services so I can pass them in using lyr.GetPath()?

 

 

 

var lyrCrossings = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Parent.ToString() == "Group" && l.IsVisible == true).ToList();
var lyrDatastorePath = await QueuedTask.Run(() => lyr.GetTable().GetDatastore().GetPath());
var lyrPathTableName = await QueuedTask.Run(() => lyr.GetTable().GetName());
string lyrPath = Path.Combine(lyrDatastorePath.LocalPath, lyrPathTableName.ToString());
List<string> inputList = new List<string>();
inputList.Add(lyrPath);
inputList.Add(secondPath);
var args = Geoprocessing.MakeValueArray(inputList, outputPath, "", "", "POINT");
string toolPath = "analysis.Intersect";
var result = await Geoprocessing.ExecuteToolAsync(toolPath, args, environments);

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Use the same approach as in line 8. You can pass to MakeValueArray everything.

var lyrCrossings = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Parent.ToString() == "Group" && l.IsVisible == true).ToList();
var inputList = Geoprocessing.MakeValueArray(lyrCrossings, secondPath);
var args = Geoprocessing.MakeValueArray(inputList, outputPath, "", "", "POINT");
string toolPath = "analysis.Intersect";
var result = await Geoprocessing.ExecuteToolAsync(toolPath, args, environments);

If you want to know what exactly takes geoprocessing tool from your layer then you need to execute geoprocessing directly from ArcGIS Pro and copy Python script from History record.

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Use the same approach as in line 8. You can pass to MakeValueArray everything.

var lyrCrossings = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Parent.ToString() == "Group" && l.IsVisible == true).ToList();
var inputList = Geoprocessing.MakeValueArray(lyrCrossings, secondPath);
var args = Geoprocessing.MakeValueArray(inputList, outputPath, "", "", "POINT");
string toolPath = "analysis.Intersect";
var result = await Geoprocessing.ExecuteToolAsync(toolPath, args, environments);

If you want to know what exactly takes geoprocessing tool from your layer then you need to execute geoprocessing directly from ArcGIS Pro and copy Python script from History record.

0 Kudos
VastBeta
New Contributor II

Thanks. I Used 

lyr.Parent + @"\" + lyr.Name + @" #";

which worked on all layers.

0 Kudos