|
POST
|
Line # 18 is saying: if the name of the feature class is the same as the name of the table: T{tableNum} then, join them. But as you can see above the name of the feature class is T11, T12, T13 etc... and the name on the tables start with NAL and then have the number. Whenever the number matches, then the join must happen. I am not sure if this is what the code says.
... View more
03-31-2020
01:47 PM
|
0
|
1
|
4248
|
|
POST
|
Thank you Joe for your help! I am internally fixing something I found before I am able to run the script. I have two questions in regards to the script: 1. Line 16: You created a variable called tableNum = table [3:7]. Arcpy recognizes that everytime you write table that is in fact calling a table in GIS? How does python know that we are in fact calling a table in GIS? 2. what do the \\ do to the f' strings?
... View more
03-31-2020
01:28 PM
|
0
|
1
|
4248
|
|
POST
|
Hello, I need help to create a script that would allow me to loop through multiple tables in a geodatabase and join them to the correct feature class in another geodatabase. There are in total 77 tables and 77 feature classes. I would tell GIS to join those where a portion of the table name matches a portion of the Feature class name. For example: Table Name 1: "NAL11F201901" Feature class 1: "T11" Table Name 2: "NAL12F201901 Feature Class 2: "T12" Important: All of the tables and the feature classes have the same unique field name. I need to join all of the fields. The join needs to be permanent. I am not sure if Add join is better to use or if I should use Join field. I don't really know what to do next. I would really appreciate any help with this. Thanks! import arcpy
in_features = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Florida_Parcels_Per_County_Final.gdb"
join_tables = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Florida_Property_Data_Per_County.gdb"
list_infeatures = arcpy.ListFeatureClasses()
list_join_tables = arcpy.ListTables(*NAL)
UniqueField = "CO_PARCELID"
for fc in list_infeatures:
arcpy.AddJoin_management()
... View more
03-31-2020
10:39 AM
|
0
|
12
|
5444
|
|
POST
|
thank you I will edit my script to change each statement individually. I can be totally wrong but in my mind it could work? Every statement will be True just once. Not sure how to explain what I am thinking
... View more
03-25-2020
09:41 AM
|
0
|
1
|
6294
|
|
POST
|
My logic behind this is: 1. The for loop statement selects one feature class at a time. 2. It then goes through all the if /elif statements for that one feature class. 3. Once it finds the one where the name of the field matches the name of that particular feature class it will assign the correct number. 4. The for loop then selects another feature class and goes through the same process. Not sure if I am thinking correctly...
... View more
03-25-2020
08:45 AM
|
0
|
3
|
6294
|
|
POST
|
Hello, I am trying to use UpdateCursor to update a field value by evaluating the value of another field. I have to do this in about 70 feature classes. For this reason I am using For Loop as well. This is the script: import arcpy
arcpy.env.workspace = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Test.gdb"
arcpy.env.overwriteOutput = True
List_dissolve_fc = arcpy.ListFeatureClasses("*Dissolve") # get a list of feature classes that end with "Dissolve"
fields = ["CO_NO", "COUNTY_NAME"] # List of fields in test.gdb
for fc in List_dissolve_fc: # Loop through each feature class in the list
with arcpy.da.UpdateCursor(fc, fields) as cursor: # Loop through each feature
for row in cursor:
if (row[1] == "{}".format(fc[:-17])): # if COUNTY_NAME equals the name of the feature class without the last 17 characters, assign 74 to field CO_NO
row[0] = 11
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 12
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 13
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 14
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 15
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 16
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 17
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 18
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 19
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 20
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 21
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 22
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 23
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 24
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 25
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 26
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 27
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 28
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 29
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 30
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 31
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 32
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 33
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 34
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 35
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 36
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 37
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 38
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 39
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 40
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 41
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 42
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 43
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 44
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 45
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 46
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 47
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 48
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 49
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 50
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 51
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 52
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 53
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 54
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 55
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 56
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 57
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 58
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 59
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 60
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 61
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 62
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 63
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 64
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 65
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 66
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 67
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 68
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 69
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 70
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 71
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 72
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 73
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 74
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 75
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 76
elif (row[1] == "{}".format(fc[:-17])):
row[0] = 77
else:
row[0] = None
cursor.updateRow(row) Expected behavior: With the String format() method I am trying to do the following: For every feature class whenever row[1] matches the name of the feature class minus the last 17 characters, assign the specified number to row[0]. I am expecting every feature class to only have one match and as a result one number will be assigned to row[0]. Actual Behavior: I am getting the expected behavior but only in the last feature class on the list "List_dissolve_fc". I know there is something very obvious to all of this but I cannot have a clear picture of what it is. How could I solve this? Thank you, Natalia
... View more
03-25-2020
08:10 AM
|
0
|
13
|
7381
|
|
POST
|
Than you Joe for sharing the link. There's very good info.
... View more
03-25-2020
07:03 AM
|
0
|
0
|
2712
|
|
POST
|
import arcpy
arcpy.env.workspace = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Test.gdb"
List_dissolve_fc = arcpy.ListFeatureClasses("*Dissolve") # get a list of feature classes that end with "Dissolve"
fields = ["CO_NO", "COUNTY_NAME"] # List of fields in test.gdb
for fc in List_dissolve_fc: # Loop through each feature class in the list
with arcpy.da.UpdateCursor(fc, fields) as cursor: # Loop through each feature
for row in cursor:
row[1] = "{[-17]}".format(fc) # Update each feature in field [1] "COUNTY_NAME" using the name of the feature class without the last 17 characters. For example: walton_2019pin_Dissolve would be walton.
cursor.updateRow(row)
Hello, I need to loop through feature classes and in each feature class I need to update the field "COUNTY_NAME" with the name of the feature class. The problem is, that the name of the feature class is too long and I don't need to include the last 17 characters. For example: "walton_2019pin_Dissolve" is the name of one feature class and I only want to use "walton" in the field names. As you can see in the script this is written in line 12. This method is not working. How could I do this? Thank you, Natalia
... View more
03-24-2020
04:33 PM
|
0
|
4
|
2825
|
|
POST
|
Hi Joshua, Randy and David, Thanks for your help! I did need to add a new field for each loop in the Search Cursor. This is the code that ended up working. I am sharing it just in case anyone needs it. I had to fix some of the raw data for it to work correctly. I had to modify the names of the cell values to have underscores instead of spaces. Import arcpy
# Set two geoprocessing environments
arcpy.env.workspace = r"D:\APRX_MXDS\Geo_Engine_Zoning_Project\Austin_Geo_Engine.gdb"
arcpy.env.overwriteOutput = True
# List of fields in Merged_Ovelays FC
fields = ["OBJECTID", "zoning_ove"]
# Convert austin_parcels feature class to feature layer
arcpy.MakeFeatureLayer_management("austin_parcels", "austin_parcels_layer")
# Convert Merged_Overlays feature class to feature layer
arcpy.MakeFeatureLayer_management("Merged_Overlays", "Merged_Overlays_Layer")
# arcpy.da.SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
with arcpy.da.SearchCursor("Merged_Overlays_Layer", fields) as cursor:
for row in cursor:
select = "OBJECTID = {}".format(row[0])
# SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})
arcpy.management.SelectLayerByAttribute("Merged_Overlays_Layer", "NEW_SELECTION", select)
# SelectLayerByLocation(in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})
arcpy.management.SelectLayerByLocation("austin_parcels_layer", "HAVE_THEIR_CENTER_IN", "Merged_Overlays_Layer","","NEW_SELECTION")
# Syntax: AddField(in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
arcpy.management.AddField('austin_parcels_layer', "Overlay_{}".format(row[1]), "TEXT")
# CalculateField(in_table, field, expression, {expression_type}, {code_block}, {field_type})
arcpy.management.CalculateField("austin_parcels_layer", "Overlay_{}".format(row[1]), "'Overlay_{}'".format(row[1]), "PYTHON_3")
arcpy.management.SelectLayerByAttribute("Merged_Overlays_Layer", "CLEAR_SELECTION") # clear any selections
arcpy.management.SelectLayerByAttribute("austin_parcels_layer", "CLEAR_SELECTION")
... View more
03-06-2020
09:18 AM
|
2
|
0
|
3058
|
|
POST
|
Hello, I have a layer with Zoning Overlays. I have a layer with parcels. I need to iterate through zoning Overlay, select the parcels falling inside, add a new field to the parcels Feature class and add some text to the selected fields, then repeat for the next zoning overlay. The loop works, insofar but it stops with a particular error that is not specific enough. The code runs until it has to assign the values to the second field. Please see below for more details. Here's my code: Import arcpy
# Set two geoprocessing environments
arcpy.env.workspace = r"D:\APRX, MXDS\Geo_Engine_Zoning_Project\Austin_Geo_Engine.gdb"
arcpy.env.overwriteOutput = True
# List of fields in Merged_Ovelays FC
fields = ["OBJECTID", "zoning_ove"]
# Convert austin_parcels feature class to feature layer
arcpy.MakeFeatureLayer_management("austin_parcels", "austin_parcels_layer")
# Convert Merged_Overlays feature class to feature layer
arcpy.MakeFeatureLayer_management("Merged_Overlays", "Merged_Overlays_Layer")
# arcpy.da.SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
with arcpy.da.SearchCursor("Merged_Overlays_Layer", fields) as cursor:
for row in cursor:
select = "OBJECTID = {}".format(row[0])
# SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})
arcpy.management.SelectLayerByAttribute("Merged_Overlays_Layer", "NEW_SELECTION", select)
# SelectLayerByLocation(in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})
arcpy.management.SelectLayerByLocation("austin_parcels_layer", "HAVE_THEIR_CENTER_IN", "Merged_Overlays_Layer","","NEW_SELECTION")
# Syntax: AddField(in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
arcpy.management.AddField('austin_parcels_layer', "Overlay_{}".format(row[1]), "TEXT")
# CalculateField(in_table, field, expression, {expression_type}, {code_block}, {field_type})
arcpy.management.CalculateField("austin_parcels_layer", "Overlay_{}".format(row[1]), '"Overlay_{}".format(row[1])') I am getting the following error and I am not sure how to fix it: Traceback (most recent call last): File "<string>", line 24, in <module> File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 4230, in CalculateField raise e File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 4227, in CalculateField retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block), True))) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. Invalid pointer Failed to execute (CalculateField). Is it something with my line of code that is not working? arcpy.management.CalculateField("austin_parcels_layer", "Overlay_{}".format(row[1]), '"Overlay_{}".format(row[1])') My goal is to: Copy the text from the selected feature below: and put it into the newly created field. I would really appreciate your help, Thank you so much! Natalia
... View more
03-05-2020
03:34 PM
|
0
|
11
|
3767
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-15-2018 02:42 PM | |
| 2 | 03-06-2020 09:18 AM | |
| 2 | 11-15-2018 03:02 PM |
| Online Status |
Offline
|
| Date Last Visited |
12-14-2020
03:44 PM
|