Select to view content in your preferred language

feature to polygon python script working but not working when called from dotnet arcgis pro sdk

1028
4
02-15-2022 11:01 AM
edlaanil
Emerging Contributor

feature to polygon python script working but not working when called from dotnet arcgis pro sdk

 

edlaanil_0-1644951437618.png

edlaanil_1-1644951475258.png

 

 

 

0 Kudos
4 Replies
RobBurke
Occasional Contributor

Hi

Just a few ideas here:

On line 73, it looks like you are creating a list of layers, but the FeatureToPolygon tool in the management toolbox seems to require a single FeatureLayer as input.  Are you saying that when you call the same tool in Python you are passing in a List of layers to the tool?  Could you show the value of input4layers variable before it gets passed into the tool?  Also could you attempt to run the tool, with only the ElectricLine layer?

Robert Burke
0 Kudos
edlaanil
Emerging Contributor

here my complete code for the Geoprocessing tool to run in the dotnet arcpro sdk

await QueuedTask.Run(async () =>
{
try
{
MapView mapvView = MapView.Active;
FeatureLayer layer1 = mapvView.Map.GetLayersAsFlattenedList().
OfType<FeatureLayer>().FirstOrDefault(l => l.Name == "ElectricLine");
FeatureLayer layer2 = mapvView.Map.GetLayersAsFlattenedList().
OfType<FeatureLayer>().FirstOrDefault(l => l.Name == "ElectricLine_temp");
string FLPath1 = layer1.GetFeatureClass().GetDatastore().GetPath().AbsolutePath;
var FLPathCombine1 = System.IO.Path.GetFullPath(FLPath1);
string infc1 = System.IO.Path.Combine(FLPathCombine1, layer1.Name);
string infc2 = System.IO.Path.Combine(FLPathCombine1, layer2.Name);

string input1layers = "[" + infc1;
string commainputlayers = ",";
string input2layers = infc2 + "]";
string input4layers = input1layers + commainputlayers + input2layers;

string Outputpoly = System.IO.Path.Combine(FLPathCombine1, "temppolyoutput");

string cluster_tolerance = "";
string attributes = "NO_ATTRIBUTES";
string label_features = "";

var environments1 = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
var parameters1 = Geoprocessing.MakeValueArray(input4layers, Outputpoly, cluster_tolerance, attributes, label_features);
var gpResult1 = await Geoprocessing.ExecuteToolAsync("FeatureToPolygon_management", parameters1, environments1);
Geoprocessing.ShowMessageBox(gpResult1.Messages, "GP Messages", gpResult1.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Error);

}
catch (Exception exc)
{
// Catch any exception found and display in a message box
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to run GP tool: " + exc.Message);
return;
}
});

 

it will be great if you help me , thanks in advance

0 Kudos
RobBurke
Occasional Contributor

That is a lot of code to attempt to debug.  Could you narrow it down, by answering a few questions.  Could you set a break point, to then show us the value of the input4layers variable before it gets passed into the tool?  Also could you attempt to run the tool with only the ElectricLine layer and let us know the results?  I don't think that tool takes a list of layers, did you find a reference in the help showing the tool processing a list or array?

 

Robert Burke
0 Kudos
edlaanil
Emerging Contributor

edlaanil_0-1645059334732.png

i got the output with same code running no issues  one layer-, thank you can we run for both layers as mentioned below in the python code which is running for both layers

 

ElectricLine_Temp = "C:\\Users\\anile\\OneDrive\\Desktop\\ANIL_INVANTGE\\1.DATA\\working_DB\\Test.gdb\\ElectricLine_Temp"
ElectricLine = "C:\\Users\\anile\\OneDrive\\Desktop\\ANIL_INVANTGE\\1.DATA\\working_DB\\Test.gdb\\ElectricLine"

# Process: Feature To Polygon (Feature To Polygon) (management)
polytemp123 = "C:\\Users\\anile\\OneDrive\\Desktop\\ANIL_INVANTGE\\1.DATA\\working_DB\\Test.gdb\\polytemp14"
arcpy.management.FeatureToPolygon(in_features=[ElectricLine_Temp, ElectricLine], out_feature_class=polytemp123, cluster_tolerance="", attributes="ATTRIBUTES", label_features="")

in  string input4layers = input1layers + commainputlayers + input2layers;

value is  [ElectricLine_Temp, ElectricLine]

please kindly help me 

 

0 Kudos