|
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
|
2316
|
|
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
|
2384
|
|
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
|
1385
|
|
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
|
1089
|
|
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
|
1145
|
|
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
|
1117
|
|
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
|
1159
|
|
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
|
1420
|
|
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
|
1451
|
|
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
|
1456
|
|
POST
|
I removed the try block. I get the following error, ERROR 000055: Cannot create a Query Table for this workspace Failed to execute (MakeQueryTable).
... View more
09-10-2021
11:04 AM
|
0
|
2
|
1506
|
|
POST
|
I need to be able to export the selected attributes from Arcmap. I have the following but I get an error on line 32. The first arcpy.Addmessage does print the OID's but not the second Addmessage. My guess is that it's not creating the temp_view. How can I get past this error? error on line 32 ERROR 000732: Input Table: Dataset tmp_view does not exist or is not supported Failed to execute (TableToExcel) selection = "NParcels"
try:
if int(arcpy.GetCount_management(selection).getOutput(0)) > 0:
arcpy.CopyRows_management(selection, "selct")
arcpy.MakeTableView_management("selct","selectionView")
fc = "selectionView"
desc = arcpy.Describe(fc)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
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)
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
except:
pass
wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'
arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Notification' + OutputExt) K
... View more
09-10-2021
08:37 AM
|
0
|
6
|
1519
|
|
POST
|
I need to spatial join only certain feature class with specific names but I am not sure how to pass the list of feature class on arcpy.ListFeatureClasses. There is about 10 feature classes in the geodatabase but like I said just need certain ones. import arcpy
from arcpy import env
env.workspace = r"C:\Temp\Default2.gdb"
env.overwriteOutput=True
#arcpy.CreateFileGDB_management(r"C:\Temp\Test", "test_6.gdb")
lst = ["Wetlands","Current_Panels"] # this is where I was trying to list the spcifice feature classes I need from the geodatabase.
fclist = arcpy.ListFeatureClasses(lst, "polygon")
for fc in fclist:
print (fc)
#fcdesc = arcpy.Describe(fc)
#print (fc)
#arcpy.Union_analysis(fc, "C:\Temp\Test\test_6.gdb")
... View more
08-12-2021
01:03 PM
|
0
|
5
|
2242
|
|
POST
|
I did try the following. workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = os.path.join("***.***.TEST","***.***.Test")
&
workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = "***.***.TEST","***.***.Test" But adding the workspace to the os.path.join is what allowed me to edit. workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = os.path.join(workspace,"***.***.TEST","***.***.Test") #adding workspace worked.
... View more
07-14-2021
10:15 AM
|
0
|
0
|
4857
|
| 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 |
07-14-2025
07:49 AM
|