|
POST
|
What method are you using when you say you "truncate web layers in a hosted feature service"? It looks like you need to use delete_features(), which could take a while depending on how many records you're working with. This will never match simplicity and performance of a database truncate though. I see there is also an append() method for a FeatureLayer in the ArcGIS API for Python; I didn't know about this. Although, a note on append from the REST API doc: Feature serviceAppendcapabilities must be enabled for theappendoperation to be used by nonadministrative users. Organization administrators, or the service owner, can use theappendoperation without having theAppendcapability enabled on the feature service. TheAppendcapability needs to be added to the service capabilities only if the service owner or organization administrators need to allow nonadministrative users to append data to a feature service. I haven't used the ArcGIS API for Python or hosted feature layers in Portal much so I'm sorry I can't guide you much more. If you have a specific question about deleting features from multiple layers in a feature service, you should create a separate question for that.
... View more
01-05-2024
10:54 AM
|
0
|
0
|
1118
|
|
POST
|
I'm not going to touch the logic you have that calculates offset. You'll need to review that on your own. pt_tbl = "ArcPRO_MasterQuery_EXT_pt"
pt_tbl_fields = ["DISTANCE", "DESCRIPTION_1", "DESCRIPTION_2", "DESCRIPTION_3", "Offset"]
trail_num_sec = ["11-1", "11-2"]
comma_sep_str = ",".join([f"'{i}'" for i in trail_num_sec])
expression = f"NUM_SEC in({comma_sep_str})"
oor = {}
oo = {}
with arcpy.da.UpdateCursor(pt_tbl, pt_tbl_fields, expression) as u_cursor:
for distance, desc_1, desc_2, desc_3, offset in u_cursor:
oo[distance] = oo.get(distance, 0) + 1
if "RHS" in [desc_1, desc_2, desc_3]:
oor[distance] = oor.get(distance, 0) + 1
offset = (oo[distance] - 1) * -1
elif distance in oor:
offset = (oo[distance] - (oor[distance]+1))
else:
offset (oo[distance] - 1)
u_cursor.updateRow([distance, desc_1, desc_2, desc_3, offset])
print("Point Table Offsets Calculated")
... View more
01-04-2024
03:12 PM
|
1
|
1
|
2446
|
|
POST
|
As @DavidPike mentioned, your variable naming makes your code unnecessarily hard to follow. The SearchCursor portion that builds the traillistsortpt list is immediately overwritten with hardcoded values on line 14. Why? You can use enumerate() to count iterations of a thing instead of counting it yourself with i At the very least, use the string format() method instead of the old %s operator. If you're working in ArcGIS Pro (Python 3), use the f-string Declaring cursors outside the loop is more performant because it won't get recreated with every iteration of the loop. Sequence unpacking can sometimes be a convenient way to name the cursor's individual values instead of referring to them by their row index. It gets a bit much if you have more than a handful of fields though, in which case you could make each row a dictionary with field names. You should utilize the where_clause parameter of the UpdateCursor instead of making a selection. Your logic for setting the Offset field value (row[5]) seems flawed. You're checking for a value in oor before you put the value in oor.
... View more
01-04-2024
03:01 PM
|
1
|
2
|
2446
|
|
POST
|
Hi @DarrenSmith, is this what you're looking for? arcgis.features module | ArcGIS API for Python The query method of a FeatureLayer has an out_sr parameter.
... View more
01-03-2024
10:06 AM
|
0
|
1
|
4358
|
|
POST
|
Hi @StuartMoore. Could you please include the code snippet you're running? Are you working in ArcMap or ArcGIS Pro?
... View more
01-03-2024
09:55 AM
|
0
|
3
|
1891
|
|
POST
|
Thank you for contributing to this discussion, @DarrenSmith. Your solution of deleting the objects in the fgdb before trying to delete the fgdb worked for me when I encountered this issue. I used Delete for both the objects and the fgdb. In my case, Compact was not necessary. For reference, I was getting this error when trying to Delete the fgdb: arcgisscripting.ExecuteError: ERROR 000601: Cannot delete And I was getting this error when the Python TemporaryDirectory() was trying to clean up: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process ...which caused the following: NotADirectoryError: [WinError 267] The directory name is invalid
... View more
01-02-2024
03:40 PM
|
1
|
0
|
1255
|
|
POST
|
@StuartMoore, this is a very old thread. I suggest creating a new question with the code you're running and reference the post from @RandyBurton https://community.esri.com/t5/python-questions/merge-with-field-mapping/m-p/560853/highlight/true#M43887
... View more
01-02-2024
08:44 AM
|
1
|
0
|
546
|
|
BLOG
|
@JesseCloutier said: answering others' questions helps those individuals look at problems from different angles and improve their own skills in the process. Indeed! Sometimes the best way to learn something is to teach it.
... View more
12-22-2023
06:11 AM
|
3
|
0
|
1571
|
|
POST
|
I think what you mean to do is a table join. Is there a key id field in "this table" that relates to the same id field in TableR? Once you join the tables based on this id field, you can run calculate field.
... View more
12-21-2023
07:21 AM
|
0
|
0
|
639
|
|
POST
|
If you want to programmatically set the number format of a field, I don't think you can do that with Python.
... View more
12-18-2023
07:17 AM
|
0
|
0
|
1801
|
|
POST
|
Yes. The FieldMappings can be used in any function that has a field map parameter of type "Field Mappings."
... View more
12-15-2023
07:05 AM
|
0
|
0
|
2182
|
|
POST
|
I always have trouble wrapping my brain around field mappings. I recommend using the FieldMappings object whenever possible. It's much easier than trying to parse/manage that giant string. I made this a while back to build a reordered FieldMappings object. Maybe you can adapt it to fit your needs. import arcpy
import os
def reorder_fields(table, out_table, field_order, add_missing=True):
"""
Based on code by Josh Werts, Apr 17th, 2014
http://joshwerts.com/blog/2014/04/17/arcpy-reorder-fields/
Reorders fields in input featureclass/table
:table: input table (fc, table, layer, etc)
:out_table: output table (fc, table, layer, etc)
:field_order: order of fields (objectid, shape not necessary)
:add_missing: add missing fields to end if True (leave out if False)
-> path to output table
"""
existing_field_names = [field.name for field in arcpy.ListFields(table)]
existing_mapping = arcpy.FieldMappings()
existing_mapping.addTable(table)
new_mapping = arcpy.FieldMappings()
def add_mapping(field_name):
mapping_index = existing_mapping.findFieldMapIndex(field_name)
# required fields (OBJECTID, etc) will not be in existing mappings
# they are added automatically
if mapping_index != -1:
field_map = existing_mapping.getFieldMap(mapping_index)
new_mapping.addFieldMap(field_map)
# add user fields from field_order
for field_name in field_order:
if field_name not in existing_field_names:
raise Exception("{0} field doesn't exist in {1}".format(field_name, os.path.split(table)[1]))
add_mapping(field_name)
# add missing fields at end
if add_missing:
missing_fields = [f for f in existing_field_names if f not in field_order]
for field_name in missing_fields:
add_mapping(field_name)
return new_mapping
def main():
inGDB = r"C:\my folder\mydata.gdb"
inTable = os.path.join(inGDB, "TEMP_Line")
outGDB = r"C:\my folder\maybeanother.gdb"
outTable = os.path.join(outGDB, "TEMP_Line_reordered")
new_field_order = [
'NewFieldName',
'SHAPE_Length',
'Note1',
'Note2',
'asdf',
]
new_fieldmappings = reorder_fields(inTable, outTable, new_field_order)
# Do something with the new fieldmappings...
if __name__ == '__main__':
main()
... View more
12-14-2023
09:53 AM
|
0
|
2
|
2201
|
|
POST
|
I use this little function to iterate the rows as a dictionary instead of a tuple. def rows_as_dicts(cursor):
colnames = cursor.fields
for row in cursor:
yield dict(zip(colnames, row))
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
for row in rows_as_dicts(sc):
print row['CITY_NAME']
... View more
12-12-2023
09:20 AM
|
4
|
0
|
1692
|
|
POST
|
Although fairly high-level, I found this ArcGIS Architecture Center, which has a section for Automation.
... View more
12-12-2023
06:14 AM
|
0
|
0
|
4389
|
|
POST
|
Attribute Rules are created with Arcade, which has a FeatureSetByRelationshipName function. So if you're able to register the view with the geodatabase and create a relationship class, maybe you can get to the data from the attribute rules. I'm not sure if it will let you create a relationship class on a db view though.
... View more
12-05-2023
01:01 PM
|
0
|
1
|
1251
|
| 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 |