|
POST
|
I think you copied your code wrong, but just in case: The first line is incomplete (closing paranthesis and "as cursor:") row[1]==Region_dic.get(row[0])
# You're using two equal signs, which compares row[1] to Region_dic[row[0]];
# this line will compute to True or False, but it won't set row[1].
# what you want is this:
row[1] = Region_dic.get(row[0]) You actually don't need the manual check for the key, you can just catch the KeyError: keyRegion = 'directory pathway'
with arcpy.da.UpdateCursor(keyRegion, ["Region","ID"]) as cursor:
for r, i in cursor:
try:
i = Region_dic[r]
cursor.updateRow([r, i])
except KeyError:
print("{} was not found.".format(r))
... View more
08-11-2021
05:10 AM
|
0
|
0
|
2448
|
|
POST
|
The expression seems to be OK, it worked for me in a Popup. So either it doesn't work in an Attribute Rule (which I doubt) or it's not the expression that causes the error.
... View more
08-11-2021
03:49 AM
|
0
|
4
|
2658
|
|
POST
|
The error is in this line: var fromPointGeometry = g.paths[0][0]; What this does is take the first point of the first segment of a line feature. It works in the first expression, because you run it on a line feature. It doesn't work in the second expression, because you run it on a point feature and those don't have the path variable. This should work: var g = Geometry($feature)
var fsLine = FeatureSetByName($datastore, "ssGravityMain", ["UPELEV"], true)
var fromLine = First(Intersects(fsLine , g))
if (fromLine == null) { return }
return $feature.RIMELEV - fromLine.UPELEV
... View more
08-11-2021
03:39 AM
|
1
|
3
|
3699
|
|
POST
|
It should be possible. I guess you edited the code given in the original question rather heavily. Could you please post the code you're using right now? Expand the comment toolbar, click on "Insert/Edit code sample", choose Javascript as language.
... View more
08-11-2021
02:01 AM
|
0
|
4
|
2300
|
|
POST
|
I provided a python script for a similar question earlier this year, maybe it can help you: https://community.esri.com/t5/geoprocessing-questions/replace-update-geometry-and-some-attributes-but/m-p/1046434
... View more
08-11-2021
12:59 AM
|
0
|
0
|
4199
|
|
POST
|
I'm not really sure what you're asking. You want to create a relationship class with Python? That is possible, take a look at pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-relationship-class.htm . If you need help with your script, please post the relevant sections (expand the comment toolbar, click "Insert/Edit code sample", choose Python as language) and tell us at what line the error occurs.
... View more
07-28-2021
02:48 AM
|
0
|
0
|
2028
|
|
POST
|
It's pretty hard to guess at the problem when we don't have the code. Can you please post the relevant section? Expand the comment toolbar, select "Insert/Edit Code Sample" and choose Javascript as language.
... View more
07-27-2021
01:03 AM
|
0
|
1
|
4055
|
|
POST
|
I know it works when publishing to the Portal. But I don't work with AGO, so I don't know if will work there.
... View more
07-26-2021
11:41 PM
|
0
|
0
|
4505
|
|
POST
|
# same goes for python, except you can use and/or/not
TrapType = !TrapType!
return 'Possum' if TrapType == 'Trapinator' or TrapType == 'Timms' or TrapType == 'Set & forget' else 'Rat'
# easier:
return 'Possum' if TrapType in ['Trapinator', 'Timms', 'Set & forget'] else 'Rat'
... View more
07-20-2021
12:46 AM
|
2
|
1
|
2438
|
|
POST
|
// test for equal with ==
// Aracade doesn't have and/or/not, it uses &&/||/!
// test for equality has to be repeated
var TrapType = $feature.Trap_type;
IIf(TrapType == "Trapinator" || TrapType == "Timms" || TrapType == "Set & forget" , 'Possum', 'Rat');
// easier:
IIF(Includes(['Trapinator', 'Timms', 'Set & forget'], TrapType), 'Possum', 'Rat');
... View more
07-20-2021
12:43 AM
|
3
|
2
|
2440
|
|
POST
|
try:
from tkinter import filedialog
except ImportError:
import tkFileDialog as filedialog
import csv
def interpolate(xy, x):
"""Linear interpolation
xy: list of given data points as [(x, y)]
x: x-value of unknown data point
Returns the y-value as a linear interpolation between the given data points
"""
xy = sorted(xy, key=lambda p: p[0]) # sort list by x
x0, y0 = [p for p in xy if p[0] <= x][-1] # get data point with next smaller x
x1, y1 = [p for p in xy if p[0] >= x][0] # get data point with next larger x
y = y0 + (y1 - y0) / (x1 - x0) * (x - x0) # linear interpolation
return y
def interpolate_empty_values(xy):
"""Fills empty x or y values by linear interpolation using the known data points.
xy: list of data points as [(x, y)], x OR y can be null
Returns a list with interpolated values
"""
known_xy = [(x, y) for x, y in xy if not (x is None or y is None)]
known_yx = [(y, x) for x, y in known_xy]
filled_xy = []
for x, y in xy:
if not (x is None or y is None) or (x is None and y is None):
filled_xy.append((x, y))
elif x is None:
# Be very careful when interpolating x!
# Interpolating x for things like relief plots, time series,
# quadratic functions, etc. will give unintended results.
x_ = interpolate(known_yx, y)
filled_xy.append((x_, y))
elif y is None:
y_ = interpolate(known_xy, x)
filled_xy.append((x, y_))
return filled_xy
# load your csv file
csv_file = filedialog.askopenfile(title="Select csv file")
# generate [(x, y)]
csv_data = [line for line in csv.reader(csv_file)]
csv_file.close()
header = csv_data[0]
csv_data = csv_data[1:]
xy = []
for d in csv_data:
x = None if d[0] in ['', ' '] else float(d[0])
y = None if d[1] in ['', ' '] else float(d[1])
xy.append((x, y))
# run interpolate_empty_values
new_xy = interpolate_empty_values(xy)
# write the result into a new csv file
new_csv_file = filedialog.asksaveasfile(title="Save csv file")
writer = csv.writer(new_csv_file)
writer.writerow(header)
for xy in new_xy:
writer.writerow(xy)
new_csv_file.close() Paste that code into a script and run the script. You don't need arcpy or ArcGIS at all. In fact, expect errors or crashes when using the tkinter methods (filedialog.*) in the ArcGIS python window.
... View more
07-19-2021
06:24 AM
|
0
|
0
|
4081
|
|
POST
|
Attribute Rules can do that. https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm // Calculation Attribute Rule
// Feature class, field FeatureKey (the field that relates the tables to the fc)
// Triggers: Insert
// Get the new feature's key value
var key = $feature.FeatureKey
// If key is null, return early, don't create entries in the related tables
if(IsEmpty(key) || key == null) { return key }
// create an array of the related tables
var edits = []
// fill it
Push(edits, {"className": "Table1", "adds": [{"attributes": {"FeatureKey": key}}]})
// repeat for each related table
// return the key field and edit the related tables
return {
"result": key,
"edit": edits
} // you could also write out the complete return block
return {
"result": key,
"edit": [
{
"className": "Table1",
"adds": [
{"attributes": {"FeatureKey": key, "AnotherAttribute": null}}
]
},
{
"className": "Table2",
"adds": [
{"attributes": {"FeatureKey": key}}
]
}
// etc
]
}
... View more
07-19-2021
03:46 AM
|
0
|
4
|
4568
|
|
POST
|
// Arcade expects if and for blocks to be enclosed in curly brackets.
// if(condition) {
// then do this
// }
// for(var f in feature_set) {
// do this
// }
// So your line 8 should look like this:
if(count(bfPoint) == 0) {return $feature.field;}
... View more
07-02-2021
12:16 AM
|
0
|
0
|
1961
|
|
POST
|
Putting code in a specially formatted box makes it much more readable. Expand the toolbar in the comment window, then click on "Inserd/Edit code sample": Arcade has no way to know that you defined the variables in Python. # If you want to define the variables in the Arcade code, do this:
expression = """
var a = 1.51
var b = 1.48
var c = 5.03
when($feature.gridcode == 1, a, $feature.gridcode == 2, b, $feature.gridcode == 3, c, 0)
"""
arcpy.CalculateField_management(Image_classified, "Dens", expression, "ARCADE")
# If you want to define the variable in Python, do this:
a = 1.51
b = 1.48
c = 5.03
expression = "when($feature.gridcode == 1, {}, $feature.gridcode == 2, {}, $feature.gridcode == 3, {}, 0)".format(a, b, c)
arcpy.CalculateField_management(Image_classified, "Dens", expression, "ARCADE")
... View more
07-01-2021
11:56 PM
|
1
|
1
|
3049
|
|
POST
|
That's weird... I have a similar situation: Gewässer: table with data of rivers and ditches Gewässersegmente: feature class containing the river axes Gewässerflächen: feature class containing polygons of the water area Bauwerke: feature class containing buildings along the river When I enable that option in the table (Gewässer) and select a river there, ArcGIS automatically selects everything linked to that river. Are you sure you checked the option "Select related records"? It sounds like you tried the "Related Data" menu above it, which indeed lets you only choose one related feature class.
... View more
06-29-2021
11:01 PM
|
0
|
1
|
1957
|
| 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
|