|
POST
|
Dan/Anyone else interested, So Dan showed a numpy approach which was blisteringly fast. Ouch! But resisting the pull of numpy (because my brain does not think like that) it got me thinking about a different way of approaching this simple problem of overcoming the ever increasing slowness of the SelectLayerByLocation tool when called within a loop. My updated script which I show below burns through the same task now in 7 seconds, nice! It requires ArcPro 3.2 and above and makes use of the improved SearchCursor that can take a geometry as a spatial filter. import arcpy, os
import time
arcpy.SetLogHistory(False)
arcpy.SetLogMetadata(False)
fp = os.path.abspath(__file__)
dir = (os.path.dirname(fp))
lyrPoints = dir + r"\Test.gdb\testpoints"
lyrPolygons = os.path.join(dir + r"\Test.gdb\testpoly")
print(lyrPoints) # Prove to myself I actually have the full path to featureclass
# Grab the polygon from layer, there is only one polygon in the layer
with arcpy.da.SearchCursor(lyrPolygons, "SHAPE@") as cursor:
for row in cursor:
geom = row[0]
print("Polygon obtained! Area is: " + str(geom.area))
d=dict()
start_time = time.time()
for i in range(1,3000):
print("Step " + str(i))
# Use polygon as a spatial filter
with arcpy.da.SearchCursor(lyrPoints, ["id"], None, None, False, None, None, spatial_filter=geom, spatial_relationship="INTERSECTS") as cursor:
x = 0
for row in cursor:
x += 1 # Count rows in cursor
d[i] = x
end_time = time.time()
elapsed_time = end_time - start_time
print(f" Elapsed time: {elapsed_time:.2f} seconds")
... View more
11-04-2024
08:28 AM
|
1
|
0
|
1461
|
|
POST
|
I've come across this issue so it makes using the Add Spatial Join tool impossible to use in modelbuilder as you cannot predict that number. I think its a bug and have reported it to ESRI. But I suspect it won't get fixed. The Add Spatial Join tool was added to Arcpro 3.2. Consider not using that tool and using the classic spatial join tool. The key difference is that this tool creates an output and does not have that field qualification.
... View more
10-31-2024
08:14 AM
|
0
|
0
|
859
|
|
POST
|
Dan, Can you share your modification of my original code so I can study how you script a spatial query with a numpy array? I'm less familiar with coding with numpy and your test runs are obviously superior to using the arcpy tool. Duncan
... View more
10-31-2024
03:35 AM
|
1
|
0
|
1521
|
|
POST
|
Dear developers, I have a script that loops over a dozen to may be several thousand overlapping polygons selecting data and counting the selections. This is all running OK except that over time it just gets slower and slower. I've narrowed it down to the Select layer by Location tool. Attached to this question is a zip file containing a folder with an arcpro project, two very simple dummy layers and a script that reproduces the problem with the supplied dummy data. If you run the script (testscript.py) in IDLE or VSCode, then initially its rocket fast but after about 1000 iterations is begins to slow down. As you will see in the script it is simply repeating itself so I would have expect the select tool to run at a constant speed. So my question why is it not and can it be fixed? I provide this example so that the user community can test what I'm saying and the developers behind arcpro have a real example of data/code that reproduces this issue. This is all happening on arcpro 3.3.2 on a machine with 16GB ram and SSD for a c:\ drive. Is it some sort of bug in the tool? Duncan
... View more
10-30-2024
02:02 PM
|
0
|
6
|
1588
|
|
POST
|
Sounds like you want to create a parameter that has a dependency to a layer parameter and that it takes multiple values. This is easy to set up. The basics are shown below. This will give the user experience of allowing you to select multiple fields:
... View more
10-28-2024
07:28 AM
|
0
|
0
|
562
|
|
POST
|
The summarize within tool is one of those python script tools created by esri. A deep dive into that code suggest common is a folder it imports from. Not sure why it would suddenly error and why it would suddenly take hours to process.
... View more
10-16-2024
04:18 AM
|
0
|
0
|
800
|
|
POST
|
Looking at your log it seems to me it errors when the tool tries to distribute the work across the cores of your CPU. How about running the code with parallel processing turned off?
... View more
10-15-2024
05:02 AM
|
0
|
0
|
891
|
|
POST
|
It's not possible to answer this question as you do not show what you do at the line "performing add join". I'm guessing that what ever you are doing there is creating a corrupted definition object which is the input to lblClass.setDefinition() and causes the script to catastrophically fail. I believe a limitation of accessing CIM is that there is no validation of the parameter, unlike tools you call in arcpy. So if you are not super careful in how you alter the definition object then you feed into CIM something that syntactically invalid and having by-passed any sort of validation you kill the script/application.
... View more
10-15-2024
04:51 AM
|
0
|
0
|
519
|
|
POST
|
You need to share your code as no one has a chance in answering this question. For a start the error is pointing to a module called common, did you create that, where is it? Also code that was running fine one day but now slowly the next strongly suggests its not the code that's changed its your input dataset. You need to provide detail on that too.
... View more
10-15-2024
04:30 AM
|
0
|
1
|
821
|
|
POST
|
I don't believe that blue message area is exposed to arcpy. Or if it is, it is an undocumented capability. May be in some future release ESRI will allow developers to put a piece of text into it? What you can do is validate on each parameter of a python script tool you are building. So you could for example check if an input layer has a specific field, if it does not then you return an error message and the tool will not be allow to run. This ensures all parameters are valid for the code they are about to feed into.
... View more
10-15-2024
04:24 AM
|
1
|
0
|
1167
|
|
POST
|
I don't tend to process data drawn down from a feature service but may be you could explore the Python API as an alternative way of grabbing that online data? Have a look here.
... View more
10-11-2024
10:15 AM
|
0
|
0
|
475
|
|
POST
|
Use the Append tool. You can also tweak the field map to match FROM to TO fields.
... View more
10-11-2024
10:01 AM
|
2
|
0
|
1309
|
|
POST
|
You would use arcpy to manipulate the contents of a map, search help for code examples on addDataFromPath().
... View more
10-10-2024
11:38 AM
|
0
|
0
|
498
|
|
POST
|
I can take a polygon layer representing the UK and clip out the UK from a bounding rectangle, as shown in my video, so not sure what you are doing wrong because it can be done. If you are processing whole layers, because until you showed your UK example you had not actually told anyone that this was the case which seems like quite an important bit of information to miss out... then consider using the ERASE geoprocessing tool instead.
... View more
10-07-2024
04:31 AM
|
0
|
1
|
4425
|
|
POST
|
Sounds like you have not got the sequence right, here is a video to show you how to create a polygon with a hole which you can then use to shade/mask data outside the polygon of interest. Click on it to enlarge.
... View more
10-04-2024
04:55 AM
|
0
|
3
|
4507
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a month ago | |
| 1 | a month ago | |
| 1 | a month ago | |
| 1 | 12-02-2025 07:05 AM | |
| 1 | 11-21-2025 06:54 AM |
| Online Status |
Offline
|
| Date Last Visited |
a week ago
|