|
POST
|
Another option would be to copy the feature class to scratch or memory workspace with only the fields you want to keep their values, truncate the original table, then append back the records and values to keep; everything else will be nulled out.
... View more
06-28-2021
09:01 AM
|
1
|
0
|
6720
|
|
POST
|
Check out the new Calclulate Fields tool introduced in ArcGIS Pro. Edit: You could still use Calculate Field, just put it in a loop of field names.
... View more
06-25-2021
03:54 PM
|
1
|
2
|
6800
|
|
IDEA
|
@JoeBorgione I found a nice summary here. Also see the official documentation that compares the path related tools from os module.
... View more
06-24-2021
02:18 PM
|
0
|
0
|
8312
|
|
POST
|
Thank you both for sharing your thoughts. I have created a new Python Idea. Update arcpy cursors to work with paths constructe... - Esri Community
... View more
06-24-2021
01:48 PM
|
0
|
0
|
3250
|
|
IDEA
|
When using a path created from pathlib, arcpy.da.SearchCursor() returns RuntimeError: 'in_table' is not a table or a featureclass If the path is formatted with str() it works fine. Hopefully there's a way the cursor, and anything else that's relevant, can accept native objects from pathlib. Please see this relevant post Using pathlib with SearchCursor
... View more
06-24-2021
01:47 PM
|
3
|
2
|
8336
|
|
POST
|
I'm trying to switch from using the os module to pathlib.Path for working with file paths. For some reason, when I construct the path to the feature class (or table) with Path, it fails with RuntimeError: 'in_table' is not a table or a featureclass If I simply convert the path to string in the cursor using str(), it works fine. A print() of the path looks normal; not a weird object or something. I get the same behavior with a file geodatabase and Oracle 12c enterprise geodatabase. I also tried using Path.joinpath() instead of the shorthand / but had the same error. Is there a different way I should be constructing paths? from pathlib import Path
egdb_conn = r"C:\GISConnections\[email protected]"
fc_path = Path(egdb_conn) / "schema.tablename"
print(fc_path)
print(arcpy.Exists(fc_path))
with arcpy.da.SearchCursor(fc_path, ["OID@"]) as search_cursor:
for row in search_cursor:
print(row) BTW, I'm on ArcGIS Pro 2.8
... View more
06-24-2021
09:49 AM
|
1
|
3
|
3292
|
|
POST
|
@DuncanHornby wrote: The important message I can leave here is stick to one style when coding and add as many comments as you can to make your code readable to you and others. I agree. Consistency is very important. Even if your code pattern is old/inefficient/dense and you don't realize until half way through, either fix it the same way everywhere or continue the pattern.
... View more
06-24-2021
07:14 AM
|
2
|
0
|
2289
|
|
POST
|
The ObjectID_1 field most commonly happens when you import a feature class that already has an ObjectID field into a geodatabase, which tries to create its own OID field but since the default name is already taken, it names it with _1. Because of the mismatched field names, you would need to create a field mappings object, which is a bit annoying for just one off-named field. You could recreate the feature class with only the one default named OID field so Append would work without field mappings, or use the cursors as you were attempting to do. Here's what I would do for cursors dsc = arcpy.Describe(Source)
target_field_Names = [f.name for f in arcpy.ListFields(Source)]
source_field_Names = [
f.name for f in arcpy.ListFields(Source)
if f.type != "OID"
and f.name in target_field_Names
]
with arcpy.da.SearchCursor(Source,fieldnames) as sCur:
with arcpy.da.InsertCursor(Target,lstFields) as iCur:
for row in sCur:
iCur.insertRow(row) And here's what I would do for using append with field mappings. I created a fuzzy_fieldmap() function that will create field mappings only with fields that exist in both the source and target tables (excluding ObjectID fields). import arcpy
def main():
fieldmappings = fuzzy_fieldmap(sourceTable, targetTable)
arcpy.Append_management(
sourceTable,
targetTable,
"NO_TEST",
fieldmappings
)
print(arcpy.GetMessages())
def fuzzy_fieldmap(input_table, target_table):
input_fields = [
f.name.upper() for f in arcpy.ListFields(input_table)
if f.type != "OID" or f.name != "OBJECTID"
]
target_fields = [
f.name.upper() for f in arcpy.ListFields(target_table)
if f.type != "OID" or f.name != "OBJECTID"
]
# Main FieldMapings object to hold FieldMap objects
fms = arcpy.FieldMappings()
# dictionary for FieldMap objects
fm_vars = {}
for t_field in target_fields:
if t_field in input_fields:
# Create the FieldMap object
fm_vars[t_field] = arcpy.FieldMap()
# Add fields to FieldMap object
# Add target field first so the output gets those field properties
fm_vars[t_field].addInputField(target_table, t_field)
fm_vars[t_field].addInputField(input_table, t_field)
# Add the FieldMap objects to the FieldMappings object
fms.addFieldMap(fm_vars[t_field])
# Optional debugging section to print field mappings
for out_field in fms.fields:
print("{} ({}): {}".format(out_field.name, out_field.aliasName, out_field.type))
return fms
if __name__ == '__main__':
main()
... View more
06-23-2021
10:13 AM
|
2
|
0
|
4725
|
|
POST
|
Do you also need to extrude between the first TIN and the last TIN?
... View more
06-23-2021
08:21 AM
|
0
|
2
|
2316
|
|
POST
|
There's still some redundancy in your code. You can build a list of field names easily this way: fieldnames = [f.name for f in arcpy.ListFields(Source)] But this is getting all the field names. If you want to exclude something, you could do something like: ignore_fields = ["Field1A", "SomethingElse"]
fieldnames = [f.name for f in arcpy.ListFields(Source) if f.name not in ignore_fields] As a final note, it looks like you're just straight copying data; might I recommend Append()?
... View more
06-22-2021
12:06 PM
|
1
|
2
|
3970
|
|
POST
|
I don't know of anything built in, but you could show some kind of basic notification to indicate there's new information outside the map extent. Here's a couple examples. How To Create a Snackbar / Toast (w3schools.com) CSS Tooltip (w3schools.com) Or better yet, maybe have the message stay until the user "acknowledges" it and provide a button that will zoom the map to the extent of the new graphic. You could use the Esri View UI to place a "notification" element with a button that goes away when the button is clicked. Using the view's UI | ArcGIS API for JavaScript
... View more
06-22-2021
07:27 AM
|
0
|
0
|
1014
|
|
POST
|
@2Quiker wrote: So can Field1A be skipped/not included when you pass the InsertCurosr, if so how? Sure, just leave that field out of the field_names parameter when you open the cursor. You only need to pass back values for the fields that you opened the cursor with.
... View more
06-21-2021
03:53 PM
|
0
|
4
|
3991
|
|
POST
|
I concur with @DavidPike . You're trying to reference fields as if there were a join, but there isn't one. Add Join (Data Management)—ArcGIS Pro | Documentation
... View more
06-21-2021
02:03 PM
|
0
|
0
|
4003
|
|
POST
|
I'm on Oracle (12c) and have a similar problem. My solution was to simply put my analyze datasets (and the rebuild indexes) functions in their own try/except where I pass on the error from the views. However, if it's as simple as registering the views as @JohannesLindner mentions, I would rather do that.
... View more
06-21-2021
08:23 AM
|
0
|
0
|
5141
|
|
POST
|
I think in that case you'll need to listen for a click event to capture the coordinate that was clicked, then use the GraphicsLayer to display a TextSymbol of the coordinate value. Graphics in the map are fixed to a certain location and move with the map. You'll also probably want a button on the UI for clearing the GraphicsLayer.
... View more
06-18-2021
07:38 AM
|
0
|
0
|
4782
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM |