|
POST
|
Huh, it just prints out the time for me... t = timeit(lambda: arcpy.management.SelectLayerByAttribute("Parcels", "NEW_SELECTION", "ParcelNumber = '72'"), number=100)
print(t)
... View more
08-31-2022
01:22 AM
|
1
|
1
|
5063
|
|
POST
|
Your ParcelNumber is probably a text field. SelectLayerByManagement takes a SQL where clause. In SQL, you have to enclose text values with single quotes: timeit(lambda: arcpy.management.SelectLayerByAttribute("Parcels", "NEW_SELECTION", "ParcelNumber = '72'"), number=100)
... View more
08-30-2022
08:30 AM
|
1
|
3
|
5074
|
|
POST
|
You're telling your DBMS to use the literal SQL query "ID = $feature.ID". This isn't a valid where clause and so it fails. What you want to do is store the $feature.ID in a variable and use the @ notation of Filter() to take care of the type formatting for you. Also, you aren't looping over the filtered feature set, but over the whole table... var Land = FeatureSetByName($datastore, "Land", [ "Location", "Name", "County", "School_District", "ID"]);
var id = $feature.ID
var related = Filter(Land,"ID=@id")
var location = First(related)
if(location == null) {
// no related features found -> return a default value
return null
}
// else return the related feature's ID
return location.ID
... View more
08-30-2022
08:26 AM
|
1
|
0
|
2099
|
|
POST
|
This is a way you could handle a split. // Attribute Rule
// field: ParcelID
// triggers: Insert
// Exclude from Application Evaluation
// An Insert can be a "normal" insert or a Split operation
var id = $feature.ParcelID
var gid = $feature.GlobalID
// no ParcelID -> normal insert, create and return a new ParcelID
if(id == null) {
var new_id = NextSequenceValue("SequenceParcelID")
return new_id
}
var other_parcels = Filter($featureset, "ParcelID = @ID AND GlobalID <> @gid")
// no other parcels with the same ParcelID -> normal Insert.
if(Count(other_parcels) == 0) {
return id
}
// else, it's a Split operation
// create and fill an array of updates to the other split parts
var updates = []
var i = 2 // this $feature gets id 1
for(var op in other_parcels) {
var new_id = op.ParcelID + "_" + Text(i++, "00")
Push(updates, {globalID: op.GlobalID, attributes: {ParcelID: new_id}})
}
return {
result: $feature.ParcelID + "_01", // the new ParcelID of this feature
edit: [{className: "TestPolygons", updates: updates}] // apply the edits to the other split parts !!! CHANGE THE CLASSNAME !!!
} I have looked for a way to detect merges, but I haven't fond one, yet. You could just add this Attribute Rule: // Attribute Rule
// field: ParcelID
// triggers: Update
var id = $feature.ParcelID
if(id == null) {
var new_id = NextSequenceValue("SequenceParcelID")
return new_id
}
return id And then delete the ParcelID in the Merge dialog:
... View more
08-30-2022
08:16 AM
|
0
|
1
|
1560
|
|
POST
|
Just had another look at the docs: Number() also supports a format string. So if the part after the underscore is the same for all features, here is another possibility: Number(Split($feature.RouteName, "_")[1], "####KM") + " km"
... View more
08-30-2022
05:34 AM
|
1
|
0
|
5081
|
|
POST
|
It supports string addition and iterating through a string. You can implement isdigit yourself. This would be a literal translation: var a = "XXXX_0045KM"
var digits = []
for(var i in a) {
var ai = Text(Number(a[i]))
if(ai != "NaN") {
Push(digits, ai)
}
}
return Number(Concatenate(digits, "")) + " km" This would be a good (albeit lengthy) way to extract all digits. In this case, the relevant digits are in defined positions. This would actually return wrong results if there are digits in the XXXX part.
... View more
08-30-2022
05:32 AM
|
1
|
0
|
5081
|
|
POST
|
FeatureSet() needs a json string, not a dictionary. Try this: return FeatureSet(Text(joinedDict));
... View more
08-30-2022
02:37 AM
|
0
|
0
|
1459
|
|
POST
|
If your values are all formatted the same way, you can also use the Mid() function: var num = Number(Mid($feature.RouteName, 5, 4))
return num + " km" If you have differing formats (eg also routes with 5 or 3 digits), you can use the Replace() function: var txt = Split($feature.RouteName, "_")[1]
var num = Number(Replace(txt, "KM", ""))
return num + " km"
... View more
08-30-2022
01:39 AM
|
2
|
1
|
5087
|
|
POST
|
The field type is string, so your SQL filter expression should look for string values. You have to enclose your tableID with single quotes: for (var p in Filter(DTS, "FEEDERID = '"+tableID+"'")){
//...
} Better yet, let Arcade handle the types: for (var p in Filter(DTS, "FEEDERID = @tableID")){
//...
}
... View more
08-30-2022
01:30 AM
|
0
|
2
|
1468
|
|
POST
|
My apologies, I really fudged that up... I know that limiting what you load can speed scripts up, so that was the first thing I tried. I got a huge speed boost and left it at that without checking the result or diving deeper into your script. And I must have some confusion about loading geometries and Intersects(). Could have sworn you didn't need the geometries, but obviously that's wrong. At least loading only the needed fields really gives a significant (although not 33 seconds...) speed boost: loading time in seconds
boundaries, all fields: 0.641
boundaries, spec fields: 0.002
nno, all fields: 0.312
nno, spec fields: 0.003 Anyway, I did a quick profiling of your script. Turns out the loading (esp. with only needed fields) and Intersecting is quite fast. What's dragging the speed down is the Count() and Sum() functions. They seem to be implemented as simple for loops, and they take a long time, especially for large nnoint. In this profile, I measured the time to do both Count and Sum, they took roughly the equal amount of time each. Load 1: 0.009
Load 2: 0.001
boundary 0
Intersects: 0
Count & Sum: 4.3629999999999995
total: 4.367
boundary 1
Intersects: 0
Count & Sum: 2.787
total: 2.791
boundary 2
Intersects: 0
Count & Sum: 0.864
total: 0.866
boundary 3
Intersects: 0
Count & Sum: 1.081
total: 1.085
boundary 4
Intersects: 0.001
Count & Sum: 1.321
total: 1.325
boundary 5
Intersects: 0
Count & Sum: 0.947
total: 0.949
boundary 6
Intersects: 0
Count & Sum: 0.484
total: 0.486
boundary 7
Intersects: 0
Count & Sum: 0.894
total: 0.895
boundary 8
Intersects: 0
Count & Sum: 1.155
total: 1.157
boundary 9
Intersects: 0
Count & Sum: 0.668
total: 0.67
boundary 10
Intersects: 0
Count & Sum: 0.544
total: 0.547
boundary 11
Intersects: 0.001
Count & Sum: 0.509
total: 0.512
boundary 12
Intersects: 0
Count & Sum: 0.594
total: 0.595
boundary 13
Intersects: 0
Count & Sum: 0.469
total: 0.471
boundary 14
Intersects: 0
Count & Sum: 0.512
total: 0.513
boundary 15
Intersects: 0
Count & Sum: 0.538
total: 0.54
boundary 16
Intersects: 0
Count & Sum: 0.788
total: 0.791
boundary 17
Intersects: 0.001
Count & Sum: 0.595
total: 0.598
boundary 18
Intersects: 0
Count & Sum: 0.641
total: 0.644
boundary 19
Intersects: 0
Count & Sum: 0.845
total: 0.847
boundary 20
Intersects: 0
Count & Sum: 0.533
total: 0.535
boundary 21
Intersects: 0
Count & Sum: 0.532
total: 0.533
boundary 22
Intersects: 0
Count & Sum: 0.505
total: 0.507
boundary 23
Intersects: 0
Count & Sum: 0.711
total: 0.713
boundary 24
Intersects: 0
Count & Sum: 0.657
total: 0.659
boundary 25
Intersects: 0
Count & Sum: 0.542
total: 0.544
boundary 26
Intersects: 0
Count & Sum: 0.53
total: 0.531
boundary 27
Intersects: 0
Count & Sum: 0.466
total: 0.467
boundary 28
Intersects: 0
Count & Sum: 0.924
total: 0.925
boundary 29
Intersects: 0
Count & Sum: 0.523
total: 0.523
boundary 30
Intersects: 0
Count & Sum: 0.648
total: 0.649
boundary 31
Intersects: 0
Count & Sum: 0.512
total: 0.513
boundary 32
Intersects: 0
Count & Sum: 0.501
total: 0.502
boundary 33
Intersects: 0
Count & Sum: 0.658
total: 0.659
total: 29.769 As Count() and Sum() are implemented as for loops under the hood, you can speed things up by writing the code yourself, using only one for loop to calculate both sum and count: for (var boundary in boundaries) {
var nnoint = Intersects(boundary,nno)
var nnocount = 0
var nnosum = 0
for(var nnoi in nnoint) {
nnocount ++
nnosum += nnoi.Expected_Attendance
}
// append feature
} This speeds up the script by about 50%, which is obvious, because we cut 50% of the loops. Load 1: 0.007
Load 2: 0.002
boundary 0
Intersect: 0
Count & Sum: 2.073
Append feature: 0
total: 2.075
boundary 1
Intersect: 0
Count & Sum: 1.004
Append feature: 0.001
total: 1.007
boundary 2
Intersect: 0
Count & Sum: 0.745
Append feature: 0
total: 0.748
boundary 3
Intersect: 0
Count & Sum: 0.517
Append feature: 0
total: 0.52
boundary 4
Intersect: 0
Count & Sum: 0.544
Append feature: 0
total: 0.547
boundary 5
Intersect: 0
Count & Sum: 0.71
Append feature: 0.001
total: 0.713
boundary 6
Intersect: 0
Count & Sum: 0.497
Append feature: 0
total: 0.499
boundary 7
Intersect: 0
Count & Sum: 0.537
Append feature: 0
total: 0.539
boundary 8
Intersect: 0
Count & Sum: 0.759
Append feature: 0
total: 0.761
boundary 9
Intersect: 0
Count & Sum: 0.326
Append feature: 0
total: 0.329
boundary 10
Intersect: 0
Count & Sum: 0.573
Append feature: 0
total: 0.577
boundary 11
Intersect: 0
Count & Sum: 0.317
Append feature: 0.001
total: 0.319
boundary 12
Intersect: 0
Count & Sum: 0.289
Append feature: 0
total: 0.292
boundary 13
Intersect: 0
Count & Sum: 0.241
Append feature: 0
total: 0.243
boundary 14
Intersect: 0
Count & Sum: 0.229
Append feature: 0
total: 0.231
boundary 15
Intersect: 0
Count & Sum: 0.261
Append feature: 0
total: 0.262
boundary 16
Intersect: 0
Count & Sum: 0.469
Append feature: 0
total: 0.472
boundary 17
Intersect: 0.001
Count & Sum: 0.249
Append feature: 0
total: 0.253
boundary 18
Intersect: 0
Count & Sum: 0.288
Append feature: 0
total: 0.291
boundary 19
Intersect: 0
Count & Sum: 0.395
Append feature: 0
total: 0.398
boundary 20
Intersect: 0
Count & Sum: 0.231
Append feature: 0
total: 0.234
boundary 21
Intersect: 0
Count & Sum: 0.245
Append feature: 0
total: 0.247
boundary 22
Intersect: 0
Count & Sum: 0.205
Append feature: 0
total: 0.206
boundary 23
Intersect: 0
Count & Sum: 0.284
Append feature: 0
total: 0.285
boundary 24
Intersect: 0
Count & Sum: 0.225
Append feature: 0
total: 0.228
boundary 25
Intersect: 0
Count & Sum: 0.254
Append feature: 0.001
total: 0.259
boundary 26
Intersect: 0
Count & Sum: 0.256
Append feature: 0
total: 0.261
boundary 27
Intersect: 0
Count & Sum: 0.244
Append feature: 0
total: 0.25
boundary 28
Intersect: 0
Count & Sum: 0.386
Append feature: 0.001
total: 0.389
boundary 29
Intersect: 0
Count & Sum: 0.27
Append feature: 0
total: 0.274
boundary 30
Intersect: 0.001
Count & Sum: 0.273
Append feature: 0
total: 0.275
boundary 31
Intersect: 0
Count & Sum: 0.248
Append feature: 0.001
total: 0.25
boundary 32
Intersect: 0
Count & Sum: 0.235
Append feature: 0
total: 0.238
boundary 33
Intersect: 0
Count & Sum: 0.321
Append feature: 0
total: 0.322
total: 15.649000000000001 Sadly, I don't see a way to speed it up further.
... View more
08-30-2022
01:02 AM
|
0
|
1
|
2485
|
|
POST
|
Hey, can you please post more info? What Arcade profile are you working in (Popup, Attribute Rule, Dashboard, etc)? your code the error message (with line number)
... View more
08-29-2022
11:54 PM
|
0
|
0
|
3044
|
|
POST
|
This expression didn't work (and it also doesn't work in a popup), because you were trying to intersect two FeatureSets. Intersect() either works with two Features/Geometries (returning a Boolean) or with a FeatureSet and a Feature/Geometry (returning a FeatureSet). What you were trying just isn't implemented in the language. Glad I could help you. Please mark my answer as solution, so this question gets shown as answered.
... View more
08-29-2022
07:13 AM
|
0
|
3
|
2496
|
|
POST
|
You could use marker layers. create a marker layer, delete the stroke layers Choose this form rotation: 90°, Placement = Along line, check Angle to line play with the other parameters eg: Line width = 1pt, Size = 15pt, Placement template = 30 Copy the layer. in the copy: rotation = 0°, change line width, size, and Perpendicular offset to match eg: Line width = 3pt, Size = 7pt, Perpendicular offset = 3pt
... View more
08-29-2022
07:05 AM
|
1
|
0
|
2176
|
|
POST
|
Indexes speed up everything that uses WHERE statements. I don't know if the search feature does that, it's possible that you won't get a speed boost here. But there is a noticeable difference in selecting a record (table from a fgdb, can't test in an egdb right now): from timeit import timeit
timeit(lambda: arcpy.management.SelectLayerByAttribute("TestTable", "NEW_SELECTION", "IntegerField = 172649"), number=100)
#301.5261236000006
timeit(lambda: arcpy.management.SelectLayerByAttribute("TestTable", "NEW_SELECTION", "OBJECTID = 172649"), number=100)
#244.7347675000001 A query on the non-indexed field took 3.01 seconds on average. On the indexed field it took 2.44 seconds, that's a 20% speedup.
... View more
08-29-2022
06:45 AM
|
2
|
5
|
5111
|
|
POST
|
Short, non-technical answer: Indexes on a field make queries based on that field faster. ArcGIS takes care of most of the indexes (e.g. on OBJECTID fields and on fields used in relationship classes). More explanation: Database Indexes Explained - Essential SQL
... View more
08-29-2022
03:39 AM
|
2
|
0
|
5246
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|