|
POST
|
Hello python gurus I'm hoping to get a little guidance on best practise. So I'm developing a fairly extensive set of geoprocessing tools in a toolbox (atbx) using python. For my own sanity I have decided to improve the readability of my code by employing hinting in my function parameters. Here is a short article that covers the topic. I have looked at a few of the system script tools and ESRI developers don't seem to employ hinting so there are no examples to work from, hence me coming here. This is not something I have done before in python and coming from a VB background seems to me like a very useful improvement to my code. I've always preferred strongly typed languages when coding. So I'm happy with setting basic built-in types for example in the past I might have done: def mytest(age, name):
text = "Hello " + name + ", you are" + str(age)
return text But with hinting used I now write my function as: def mytest(age: int, name: str) -> str:
text = "Hello " + name + ", you are" + str(age)
return text So my question is how do I hint for arcpy objects, say for a layer, spatial reference or polyline? Imagine I had some function like this: def dostuff(mylayer, sr, arr):
# Nonsene example showing the variety of arcpy objects I might pass into a function
arcpy.AddField_management(mylayer, "SiteID", "LONG")
myPolyline = arcpy.Polyline(arr, sr, False, True)
return myPolyline
What would be the correct hinting syntax to be used for my dostuff() function which is passing in arcpy objects or even a class object I might have created?
... View more
04-22-2023
08:30 AM
|
1
|
4
|
3239
|
|
IDEA
|
@LeonS your example is a good addition to the issues of entering enumerated domain information. I have to say I have found those warning messages next to useless. As you say you don't know which field they are warning you about and they provide no advice on what the values should be and under what scenario they should be used.
... View more
04-20-2023
08:48 AM
|
0
|
0
|
3589
|
|
IDEA
|
@ShaunWalbridge Thanks for the advice and pleased to here its a bug that will get resolved. I have to admit I prefer to use the package manager in ArcPro, because its so convenient but I mastered the art of using pip to install a new module into the python environment. Typically I open up a command line window, navigate it into the folder with pip, in my case it be would C:\Users\hornbydd\AppData\Local\ESRI\conda\envs\arcgispro-py3_Cloned\Scripts then use pip. How would one run conda create -n pro-shapely-2 arcpy=3.1 shapely=2 is that within the command line window, if so does it require to be run from a folder as with pip? I'm asking simply because I'm not familiar with the approach you suggest and it would be good for me to understand it.
... View more
04-12-2023
02:16 AM
|
0
|
0
|
5783
|
|
IDEA
|
For the record I simply installed shapely into the cloned python environment using "pip install shapely" and I have seen no other issues manifest.
... View more
04-04-2023
04:30 AM
|
0
|
0
|
5821
|
|
POST
|
You have set the parameters to the model variables but you have not set the model variables, I know this as they are grey. Right click on them, open them in your model and set them to the actual dataset. Also looking at your code you have hard wired the SQL where clause to event_id, so why offer it up as a parameter?
... View more
04-03-2023
08:18 AM
|
0
|
0
|
2386
|
|
POST
|
You Script tool (so not model) code takes 4 parameters, in your image you are not connecting in Event_id, the 3rd of 4. Event_id = arcpy.GetParameterAsText(2) # Event_ID Which suggests your current parameters are potentially linking to the wrong input parameter as well as not providing all four required parameters?
... View more
04-03-2023
08:00 AM
|
0
|
2
|
2399
|
|
POST
|
OK, without seeing what "SearchCursor" is no one can answer this question. I suspect the inputs are the wrong data type that they are feeding into. Share that portion of the model with some sample data?
... View more
04-03-2023
07:53 AM
|
0
|
1
|
2412
|
|
POST
|
Are you saying in the image you have uploaded that "SearchCursor" is a model? Also the inputs to "SearchCursor" are all grey, they have not been set, so not surprising that "SearchCursor" is not running. There is little point setting them as Parameters if you intend to run the model within modelbuilder.
... View more
04-03-2023
07:39 AM
|
0
|
3
|
2423
|
|
IDEA
|
Interesting issue. Agree, the cross would seem to suggest a problem. But it only appears when you hover over the parameter. Using the tool you demonstrate the issue with, if you click in the next row of input features the cross disappears and moves into the row you just clicked in. It's tool tip, like other icons that appear on a parameter, does say Remove and does not say anything like you have a problem.
... View more
04-03-2023
07:35 AM
|
0
|
0
|
2722
|
|
IDEA
|
Although adding a shape solves the problem, it does feel a bit clunky. A layout page colour as a property would be more intuitive as @Laura is suggesting.
... View more
04-03-2023
05:07 AM
|
0
|
0
|
893
|
|
IDEA
|
ArcPro 3.1.0 makes it easy for the non-technical to install additional python modules through the Package Manger. Love it! Currently the version of shapely that the package manager can install is 1.8.4. Version 2.0.1 is available and has better support for precision and no doubt other functionality. My idea is that ESRI makes it a priority to support shapely 2.0.1 through the Package Manager. Yes I know it can be installed manually but that's a route that will put off non-technical users.
... View more
04-03-2023
04:56 AM
|
1
|
6
|
5864
|
|
POST
|
The ArcMap tool RivEX can sample the river network in a fixed distance or randomly, check the help file out here. It is designed to over the branching issue you are attempt to deal with.
... View more
04-01-2023
01:18 PM
|
0
|
0
|
4886
|
|
POST
|
That goes for dropbox too. I've had issues with read/writing data directly from dropbox.
... View more
04-01-2023
01:11 PM
|
0
|
0
|
1232
|
|
POST
|
I'm going to stick my neck out and say yes. I base that opinion on my experience. If the input dataset to a select by location is a shapefile without it's spatial index I often observe poor performance. Add a spatial index and I see significant improvement with such tools. I've never used SDE so I'm assuming that would behave the same as I see that as a superior storage format.
... View more
04-01-2023
01:10 PM
|
1
|
2
|
2065
|
|
POST
|
Hi Dan, Thanks for your time. I understand your suggestion of moving the Add field tool into the script, but I do not want that. I simply used the Add Field as an example of chaining tools in model builder, it could have been any other tool that takes a table as input. Spurred on by you I did some further searching with Google and finally came across a thread back in 2019 by @NealBanerjee who was having the same issue as me, the output is derived, built completely within the script and essentially is independent to any of the input parameters. Now I may be wrong but I'm getting the impression one cannot create a derived output and set its schema when the derived output is not dependent on any input parameter. Unless I'm missing some subtle bit of code I cannot create a derived output and say "this is going to be a table with the following fields"? The examples in the help file show derived outputs that are dependent upon one of the input parameters. Clear as mud? 🙂 So unless some ESRI modelbuilder/python scripter guru says otherwise I thinks its not possible? I'm more than happy to be shot down in flames at this point, if someone could show me otherwise. I should emphasize I'm developing script tools and not a python toolbox. Now that all said the thread offered up a solution that is workable, it's a bit of a faff but when I tested it does actually work. You connect the derived output as a precondition to a Calculate Value tool which simply states what the output type is. Then the Add Field tool validates and the whole model runs correctly. The Calculate tool was set up as:
... View more
04-01-2023
05:19 AM
|
0
|
0
|
2543
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-03-2026 07:31 AM | |
| 3 | 06-29-2026 05:17 AM | |
| 1 | 02-15-2023 05:45 AM | |
| 1 | 06-16-2026 02:37 AM | |
| 1 | 06-15-2026 08:29 AM |
| Online Status |
Offline
|
| Date Last Visited |
a month ago
|