Select to view content in your preferred language

Run Python Script Tutorial and C# based Geoprocessing

681
3
10-23-2024 07:12 AM
JeffreyThompson2
MVP Regular Contributor

I am attempting to build the Run Analysis Task With Python Tutorial.

https://developers.arcgis.com/documentation/arcgis-pro-sdk/tutorials/analysis-with-python/

I have built the Add-In as instructed but I keep hitting this cannot open file error when running the Python script. The Python script does exist at the specified file path. I have tried moving the script to other file locations and building the file path string in different ways. Each attempt has either lead back to this same error or broken the build entirely. The error in Pro suggests it is adding an extra \ to the file path.

JeffreyThompson2_0-1729689447742.png

This is the value of myCommand in Visual Studio: /c ""C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "C:\temp\RunPython.py""

The Run GP Tool button works as expected. 

Second Question: On a fundamental level, how do geoprocessing tasks get resolved in the Pro SDK? 

I am trying to replace a script written in ArcObjects. I was able to make an arcpy script that got the job done, but it runs in ~4 hours compared to the ~20 minutes the ArcObjects script takes. I am looking into the Pro SDK as an alternative to arcpy, but from what I see geoprocessing is ultimately handled in arcpy anyway. Is there a C# based geoprocessing option in the Pro SDK?

GIS Developer
City of Arlington, Texas
Tags (3)
0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

There is sample how to call python script from ArcGIS Pro. Sample is here: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Geoprocessing/CallScriptFromNet

Another way is to make python tool from your script and call it as geoprocessing tool.

There are differences in arcpy used by ArcMap and ArcGIS Pro. Check Python section for performance issues.

In one of our projects we have found that performance issue could be with using featureclass instead of featurelayer in SelectLayerByLocation method when you call it in calculation cycle. You need to make FeatureLayer from FeatureClass before calculation cycle. 

Data type for  in_layer for SelectLayerByLocation method must be FeatureLayer, but it works and with FeatureClass.

JeffreyThompson2
MVP Regular Contributor

I don't feel like you really answered either question I was trying to ask, but adding the arcpy.managment.MakeFeatureLayer() function to my script just cut my 4 hour processing time down to 2 minutes, so I guess I don't really need to learn the Pro SDK right now. 

GIS Developer
City of Arlington, Texas
0 Kudos
MK13
by
Frequent Contributor

I have the same gripe with geoprocessing being handled by arcpy in the Pro SDK. All the slowest parts of my code are the gp tools. https://community.esri.com/t5/arcgis-pro-sdk-questions/speed-up-geoprocessing-tools/m-p/1548208#M121...

0 Kudos