|
POST
|
Man I could not get the field calculator to work, I kept getting that I have a syntax error. I ended up just using the python window with updatecursor. import arcpy
fc = "layer"
with arcpy.da.UpdateCursor(fc,["SC","SC2"]) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
if row [0] == "GR":
row [1]= "GRAIN"
elif row [0] == "WR":
row [1] = "WRITE"
elif row [0] == "PL":
row [1] = "PLACE"
cursor.updateRow(row)
else:
pass
... View more
01-19-2022
09:19 AM
|
1
|
0
|
543
|
|
POST
|
Using what you posted if SC is not None: but still have me the error "The field is not nullable". So I check the attributes filed and there are some blanks and nulls. I am trying to run this on the how feature class table not just the selected features. def Reclass(SC):
if SC not in [None, "", " "]:
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
01:14 PM
|
0
|
1
|
2657
|
|
POST
|
It was in vbscript, so I though I had it figured out but I guess not. The following only works with one if but when adding more elif I get an error that field is not nullable. How do I handle Nulls and blanks in field calculator? The SC field dose have some nulls and blanks. def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
12:06 PM
|
0
|
3
|
2679
|
|
POST
|
Total rookie mistake, I forgot to check the python parser box.
... View more
01-14-2022
11:41 AM
|
1
|
0
|
2684
|
|
POST
|
I have tried it with quotes and still get the syntax error. def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
if (SC == "WR"):
return "WRITE"
if (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
11:37 AM
|
0
|
0
|
2684
|
|
POST
|
Trying to figure out a simple field calculate but I can't i keep getting syntax error. This is a shapefile. I need to update the updateField field. The updateField is a text field. def Reclass(SC):
if (SC == "GR"):
return = GRAIN
if (SC == "WR"):
return = WRITE
if (SC == "PL"):
return = PLACE
updateField = Reclass(!SC!)
... View more
01-14-2022
11:04 AM
|
0
|
10
|
3253
|
|
POST
|
maybe multivalue= True, aram0 = arcpy.Parameter(
displayName="Input KML/KMZ File",
name="input_kml",
datatype=["GPKMLLayer","DEFile"],
parameterType="Required",
multivalue= True,
direction="Input",
)
... View more
12-22-2021
12:03 PM
|
0
|
0
|
2865
|
|
POST
|
You can create a batch to run a python script, something like below. @echo off
"C:\Python27\ArcGIS10.8\python.exe" "C:\pythonscripts\pythonscript.py"
pause
... View more
12-15-2021
01:48 PM
|
0
|
0
|
1828
|
|
POST
|
Thank you for suggesting the print/add message, seems I always forget to do that. Turns out that line 9 puts extra set of apostrophes in the string , ''Rosedown sub''. I made changes to line 9. Change line 9 from earch_string = ["'{0}'".format(v) for v in search_string] to earch_string = ["{0}".format(v) for v in search_string]
... View more
12-10-2021
08:05 AM
|
0
|
0
|
1308
|
|
POST
|
I have the following basic code, I need to be able to run the script to select either 1 features or multiple features based on what is provided from arcpy.GetParameterAsText(0) I have the arcpy.GetParameterAsText(0) set as 'Any Value' and for the data type parameter properties MultiValue set to 'Yes' but I keep getting the error. I am guessing that my whereClause is incorrect and if so how can I get to work? PLATNAME field is a text field. Error; ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute) Script code; import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
lyr = arcpy.mapping.ListLayers(mxd, "Subs")[0]
search_string = arcpy.GetParameterAsText(0)
search_string = search_string.split(";")
search_string = ["'{0}'".format(v) for v in search_string]
whereClause = "{0} IN ({1})".format("PLATNAME", ",".join(search_string))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION",whereClause )
with arcpy.da.SearchCursor(lyr, ["SHAPE@","PLATNAME"]) as cursor:
for row in cursor:
df.extent = row[0].extent
df.scale = df.scale * 5
arcpy.RefreshActiveView()
... View more
12-08-2021
12:52 PM
|
0
|
2
|
1364
|
|
POST
|
I meant that I need to update Field1 and that Field1 has some attributes and also FieldA sometimes has attributes. dict1 = dict()
with arcpy.da.SearchCursor(fc,['FieldA','COUNT','FieldB']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
dict1.setdefault(row[0],[]).append(str(row[2]))
with arcpy.da.UpdateCursor(fc,['FieldA','COUNT','Field1']) as cursor:
for row in cursor:
if row[2] is None:
if row[0] not in (None, "", " "):
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)
... View more
11-16-2021
01:23 PM
|
0
|
0
|
1548
|
|
POST
|
I need to only update the fields attributes that are blank or Null, there are some attributes in Feilda and I want to skip those but I am not sure how do to do that. I have the following. with arcpy.da.UpdateCursor(fc,['Fielda','COUNT','Field1']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)
... View more
11-16-2021
10:54 AM
|
0
|
4
|
1590
|
|
POST
|
I am still trying how to figure out how do this without the Copymanagment. I was able to do it with the arcpy.da.FeatureClassToNumPyArray but it exported all the fields I need to remove the extra fields like the OID, area and length fields. I have the following but it's still including those extra fields. I get the following error. DescribeData: Method lengthFieldName does not exist selection = "NParcels"
if int(arcpy.GetCount_management(selection).getOutput(0)) > 0:
arcpy.MakeTableView_management(selection, "NP_VIEW")
fc1 ="NP_VIEW"
dsc = arcpy.Describe(fc1)
fields = dsc.fields
out_fields = [dsc.OIDFieldName, dsc.lengthFieldName, dsc.areaFieldName]
fieldnames = [field.name for field in fields if field.name not in out_fields]
nparr = arcpy.da.FeatureClassToNumPyArray(fc1, fieldnames)
arcpy.TableToExcel_conversion(fc1, "C:/temp/Test.xls")
... View more
09-17-2021
08:24 AM
|
0
|
0
|
1817
|
|
POST
|
I was able to get this to work but I had to us the arcpy.CopyFeatures_management which is ok I guess but I would like to skip this part if possible? if int(arcpy.GetCount_management(selection).getOutput(0)) > 0:
arcpy.MakeFeatureLayer_management(selection, "SelectLyr")
arcpy.CopyFeatures_management("SelectLyr", "C:\Temp\Scratchworkspace.gdb\Tempselect")
fc = "C:\Temp\Scratchworkspace.gdb\Tempselect"
desc = arcpy.Describe(fc)
flds = [fld.name for fld in desc.fields]
flds_remove = [desc.OIDFieldName,
desc.shapeFieldName,
desc.areaFieldName,
desc.LengthFieldName]
for fld in flds_remove:
flds.remove(fld)
file = folder = os.path.dirname(mxd.filePath)+ "/" + "tmp_view"
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)
wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'
arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Listing' + OutputExt)
... View more
09-13-2021
02:03 PM
|
0
|
1
|
1848
|
|
POST
|
I did have the following but I kept giving me errors like the following, so I removed them. [desc.shapeFieldName], AttributeError: DescribeData: Method shapeFieldName does not exist [desc.shapeFieldName], AttributeError: DescribeData: Method areaFieldName does not exist [desc.shapeFieldName], AttributeError: DescribeData: Method desc.LengthFieldName does not exist flds_remove = [desc.OIDFieldName,
desc.shapeFieldName,
desc.areaFieldName,
desc.LengthFieldName] I am thinking that the arcpy.MakequeryTable_management is not working because I don't get a list of OID after but I am not sure why.
... View more
09-13-2021
10:48 AM
|
0
|
0
|
1853
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-01-2024 07:19 AM | |
| 1 | 07-26-2024 09:38 AM | |
| 1 | 01-08-2024 09:44 AM | |
| 1 | 03-07-2023 11:46 AM | |
| 1 | 11-02-2020 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
12:36 PM
|