|
POST
|
This all seems rather arbitrary. How do you know which row in the destination table is for which calculation? If you want to hard code the calculations like your original request, my original code sample should work (again, assuming you have the same number of rows in the destination table as you have calculated values). If you want to read the calculated values from a table and insert them (instead of hard coding the values), you can do that too (again, add error handling in case you have more rows in the destination table than you have calculated values): calcval_table_path = path_to_calcval_table_here
with arcpy.da.SearchCursor(calcval_table_path, ["OBS1", "OBS2", "OBS3", "OBS4"]) as search_cursor:
for row in search_cursor:
lookup_values = row
destination_table_path = path_to_destination_table_here
with arcpy.da.UpdateCursor(destination_table_path, ["Field1", "Another_Field_ifyouwant"]) as update_cursor:
for enum, row in enumerate(update_cursor):
row[0] = lookup_values[enum]
update_cursor.updateRow(row) The SearchCursor portion will make the lookup_values. It'll be whatever is the last row in that calculated values table.
... View more
11-02-2023
08:53 AM
|
0
|
0
|
2779
|
|
POST
|
Do either have these tables have a key id field that links a record from one table to the other?
... View more
11-01-2023
02:14 PM
|
0
|
2
|
2801
|
|
POST
|
Where you access the parameters in the execute portion, get it with the value property instead of valueAsText. From there, you can get the catalogPath from Describe. arcpy.Describe(the_layer_obj).catalogPath Use the catalogPath when you create the cursor. Apologies if this is oversimplified for your use case. I haven't worked with multi-value inputs.
... View more
11-01-2023
02:07 PM
|
1
|
0
|
1202
|
|
POST
|
A basic solution using updateCursor would be like this: lookup_values = ["1","5","3"]
with arcpy.da.UpdateCursor(my_fc_path, ["FirstField", "Another_Field_ifyouwant"]) as update_cursor:
for enum, row in enumerate(update_cursor):
row[0] = lookup_values[enum]
update_cursor.updateRow(row) However, I would recommend not relying on the implicit order of everything like this. You're not guaranteed to go through the rows of data in any predictable order unless you specify a sql_clause parameter and use order by, but that's only supported when working with databases. This will also error if there are more rows in the cursor than you have lookup values in the list. Rather, you should be matching by a key value. You would create a Python dictionary of your lookup values by some primary key id, then for each row in your update cursor, look up the key and get the value to change for that particular row. Turbo Charging Data Manipulation with Python Curso... - Esri Community Can you give some more context to your question so we can give you a more precise answer?
... View more
11-01-2023
11:21 AM
|
2
|
4
|
2842
|
|
POST
|
Yeah, this sounds like it's going down a dark path. Maybe look into creating geoprocessing tools in a Python Toolbox? Or maybe Attribute Rules? Or a custom add-in, if you're willing to step away from Python development. Or heck, maybe you can publish some feature layers and create a web app to edit the data. Either a custom JS app or built with Experience Builder.
... View more
11-01-2023
10:54 AM
|
0
|
3
|
3305
|
|
POST
|
This should technically work, but you have an extra line calling updateRow() that should be removed. I don't know if the logic is what you want to happen though. Can you clarify exactly what happens when it doesn't work? Is there an error message?
... View more
11-01-2023
08:56 AM
|
1
|
1
|
1447
|
|
POST
|
Some operations you can do on a feature class in a geodatabase might not be possible with a feature service. For example, you can't truncate/append, you would have to delete all rows, then insert all rows (for a traditional feature service hosted in standalone ArcGIS Server) and it would take considerably longer compared to a gdb fc. Also, you can't use something like arcpy.Editor or calculate field; although you can do more with GeoAnalytics tools if you have access to that. So, it depends on a lot of different things. I would guess that "pretty complex" scripts have more than just some arcpy cursors making a few data edits. You'd have to find matching capabilities in the ArcGIS API for Python or the ArcGIS REST API directly.
... View more
10-30-2023
03:09 PM
|
0
|
3
|
3168
|
|
POST
|
Can you clarify how the feature services are hosted/accessed? (Standalone ArcGIS Server, hosted in Portal data store, uploaded to ArcGIS Online?)
... View more
10-30-2023
02:40 PM
|
0
|
5
|
3178
|
|
POST
|
So to put it another way, you want to have one tool that can accept inputs of a gdb feature class or feature service and perform the same logic?
... View more
10-30-2023
02:32 PM
|
0
|
7
|
3185
|
|
POST
|
I'm not quite following because you mention wanting to use the API for Python to work with feature services, but you explained only how your scripts use file geodatabases. What do you plan to do with feature services? You could take a look at this thread about modularizing Python Toolboxes for inspiration. I do something similar with our Python scheduled tasks, they import a custom library with commonly used functions. Python Tool Management System - Esri Community
... View more
10-30-2023
12:49 PM
|
0
|
9
|
3255
|
|
POST
|
@JasmineSpring wrote: Thank you so much ! I am trying to test the calculation with the null values already = 1 as below. I get the error NameError: name 'poa_fields_expr ' is not defined The variable on line 11 needs to be renamed. import arcpy
# Get the selected layer
layer = arcpy.GetParameterAsText(0)
# Create a list of field names starting with "poa"
poa_fields = [field.name for field in arcpy.ListFields(layer) if field.name.startswith("poa")]
# Use the Field Calculator to calculate the product
poa_fields_expr = " * ".join([f"!{field}!" for field in poa_fields])
expr = f"my_calc_func({poa_fields_expr})"
# *args allows any number of arguments to be passed into the function.
code = '''def my_calc_func(*args):
result = 1
for poa_value in args:
result = result * poa_value
return 1 - result
'''
arcpy.management.CalculateField(layer,"Product_poa",expr,"PYTHON3",code)
... View more
10-27-2023
07:16 AM
|
1
|
0
|
4731
|
|
POST
|
Yeah, this is pretty close! I haven't dived into the Esri Cartographic Information Model (CIMSymbol) yet. Thank you for this.
... View more
10-26-2023
09:21 AM
|
1
|
0
|
2720
|
|
POST
|
For the calculate field to multiply all the fields together, try this. I'm assuming you're using ArcGIS Pro. This won't work in ArcMap. # Use the Field Calculator to calculate the product
poa_fields_expr = ",".join([f"!{f.name}!" for f in poa_fields])
expr = f"my_calc_func({poa_fields_expr})"
# *args allows any number of arguments to be passed into the function.
code = '''def my_calc_func(*args):
result = 1
for poa_value in args:
result = result * poa_value
return 1 - result
'''
arcpy.management.CalculateField(
in_table=layer,
field="Product_poa",
expression=expr,
expression_type="PYTHON3",
code_block=code
) As for the other part of your code sample wehre you are setting the first field to 1, I recommend using calculate field because it will be consistent with using calculate field for multiplying the fields and you can explicitly name the field you're calculating rather than implicitly expecting the first field to be the one you want to calc. # Set the default value for "the field name here"
arcpy.management.CalculateField(
in_table=layer,
field="the field name here",
expression="1"
) Which brings me to a final point: I see you are setting that field to a string "1" instead of an integer 1. If your other poa fields are strings, you will need to convert them to a number in your code. Here is a final code (untested) that also forces the field values to be a number. import arcpy
# Get the selected layer
layer = arcpy.GetParameterAsText(0)
# Set the default value for "the field name here"
arcpy.management.CalculateField(
in_table=layer,
field="the field name here",
expression="1"
)
# Format the list of fields for calculate field.
poa_fields_expr = [f"!{f.name}!" for f in arcpy.ListFields(layer, wild_card="poa*")]
# Build expression and code block to calculate the Product_poa field.
expr = f"my_calc_func({poa_fields_expr})"
# *args allows any number of arguments to be passed into the function.
code = '''def my_calc_func(*args):
result = 1
for poa_value in args:
result = result * float(poa_value)
return 1 - result
'''
arcpy.management.CalculateField(
in_table=layer,
field="Product_poa",
expression=expr,
expression_type="PYTHON3",
code_block=code
)
... View more
10-26-2023
09:06 AM
|
1
|
2
|
1762
|
|
POST
|
Is there a way to achieve an effect similar to the Animated Flow Renderer using polyline data instead of a magnitude/direction raster? I would like to use an attribute to determine magnitude with the direction of the line geometry. I did some tinkering with the Animated Lines WebGL sample but the triangulation of the lines is giving odd behavior with my data; the lines don't seem to follow the correct path. I'm hoping there is something a little simpler. Even if it's just moving marker symbols along the path of the line features.
... View more
10-24-2023
01:43 PM
|
1
|
4
|
2797
|
|
POST
|
I think you need to define parameter B as GPValueTable and populate the ValueList filter with a list of feature class names. Defining parameters in a Python toolbox—ArcGIS Pro | Documentation
... View more
10-20-2023
02:50 PM
|
0
|
0
|
1668
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2025 03:53 PM | |
| 1 | 3 weeks ago | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM | |
| 1 | 12-01-2025 06:19 AM |