|
POST
|
I have the following code and i am getting an error on line 76 with the arcpy.da.UpdateCursor that update feature attributes to proper case . I am unsure why. I would really appreciate some help please? Thanks. # Import arcpy module
import arcpy
from arcpy import env
# Allow overwrite
arcpy.env.overwriteOutput = True
# Script user input parameters
polygonLayer = "TaxParcels1" #Taxparcels
pointLayer = "CCAP8" #Point Layer
arcpy.env.workspace = r"Database Servers\15_SQLEXPRESS.gds\CCAPTEST (VERSION:dbo.DEFAULT)" #arcpy.env.workspace = r"Database Servers\15_SQLEXPRESS.gds\TEST (VERSION:dbo.DEFAULT)"
poly = "ACCOUNT_1"
Pnt = "Account"
sjpoints = "In_memory\sjpoints"
parcelsCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))
dsc = arcpy.Describe(pointLayer)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif parcelsCount >= 1:
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(pointLayer, polygonLayer, sjpoints)
# define the field list from the spatial join
sourceFieldsList = ["TARGET_FID", poly,"SiteAddress",'SiteNum_1', 'SiteStreet_1','SiteNumSfx_1','Predir_1','SiteStreet_1','Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1', 'StreetType_1'] #,'StreetType_1'
# define the field list to the original points
updateFieldsList = ["OID@", Pnt,"SiteAddres", 'SiteNum', 'StreetName','SiteNumSfx','Predir','SiteStreet', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName', 'StreetType'] #, 'StreetType'
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
manualFields = ["FacltyType","GIS_STEW", "StructType", "Verified", "Status", "StructCat", "APA_CODE",'StreetName'] #,'StreetName'
with arcpy.da.UpdateCursor(pointLayer, manualFields) as rows:
for row in rows:
row[0] = ("Single Family Home")
row[1] = ("Canyon")
row[2] = ("Primary, Private")
row[3] = ("Yes, GRM, TA")
row[4] = ("Active")
row[5] = ("Residential")
row[6] = ("1110")
row[7] = (sourceFieldsList[4] + " " + sourceFieldsList[12])
rows.updateRow(row)
del row
del rows
# populate the dictionary from the polygon
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}
with arcpy.da.UpdateCursor(pointLayer, updateFieldsList) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in valueDict:
for n in range (1,len(sourceFieldsList)):
updateRow = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
del updateRows
del updateRow
#Update feature attributes to proper case
fields1 = ["StreetName", "SiteStreet","SiteAddres","OwnerName","StreetType"]#,'StreetType'
with arcpy.da.UpdateCursor(pointLayer, fields1) as cursor:
for row in cursor:
row[0] = row[0].title()
row[1] = row[1].title()
row[2] = row[2].title()
row[3] = row[3].title()
row[4] = row[4].title()
cursor.updateRow(row)
# Stop the edit operation.
#edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
arcpy.RefreshActiveView()
#arcpy.Delete_management(sjpoints)
... View more
12-18-2015
10:00 AM
|
1
|
20
|
11275
|
|
POST
|
currently have a code that i would like to update a certain field based off of two other fields but i am getting a error. Error:TypeError: list indices must be integers, not str. on line : row[7] = (sourceFieldsList['SiteStreet_1'] + " " + sourceFieldsList['StreetType_1']) The only difference in the fields is that some have different lengths, the fields are 'String' fields so i am not sure what's going on other then the lengths. Do the fields have to be the same lengths? Any help would be great, thanks! # define the field list from the spatial join
sourceFieldsList = ["TARGET_FID", poly,"SiteAddress",'SiteNum_1', 'SiteStreet_1','SiteNumSfx_1','Predir_1','SiteStreet_1', 'Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1','StreetType_1'] #
# define the field list to the original points
updateFieldsList = ["OID@", Pnt,"SiteAddres", 'SiteNum', 'StreetName', 'SiteNumSfx','Predir','SiteStreet', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName' 'StreetType']
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
manualFields = ["FacltyType","GIS_STEW", "StructType", "Verified", "Status", "StructCat", "APA_CODE",'StreetName'] #]
with arcpy.da.UpdateCursor(pointLayer, manualFields) as rows:
for row in rows:
row[0] = ("Single Family Home")
row[1] = ("Canyon")
row[2] = ("Primary, Private")
row[3] = ("Yes, GRM, TA")
row[4] = ("LM")
row[5] = ("Residential")
row[6] = ("1110")
row[7] = (sourceFieldsList['SiteStreet_1'] + " " + sourceFieldsList['StreetType_1'])
rows.updateRow(row)
... View more
11-25-2015
09:42 AM
|
0
|
3
|
3582
|
|
POST
|
does the UPPER() only for the first word or for more then one word? The feature class attributes are like the following Desert Hills Road,Desert Wolf Lane etc.
... View more
11-05-2015
09:38 AM
|
0
|
2
|
2309
|
|
POST
|
thanks for the reply. getting error on expression = "UCASE(FENAME)LIKE '%{}%'".format(pu.upper()) Traceback (most recent call last): File "C:\GIS\Python Scripts\ZoomTo\ZoomToRoad.py", line 13, in <module> arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression
... View more
11-05-2015
09:26 AM
|
0
|
4
|
2309
|
|
POST
|
I have a script that works good but only if the first letter of the input has the first letter upper case. Currently every road name starts with an upper case letter. How can I format the expression to allow for either upper or lower case inputs. Thanks. import arcpy
arcpy.AddMessage("Starting")
pu = arcpy.GetParameterAsText(0)
arcpy.AddMessage(pu)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Roads", df)[0]
pu = arcpy.GetParameterAsText(0)
arcpy.AddMessage(lyr.name)
expression = "FENAME LIKE '%{}%'".format(pu)
arcpy.AddMessage(expression)
arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression)
df.extent = lyr.getSelectedExtent()
arcpy.RefreshActiveView()
arcpy.AddMessage("Completed")
... View more
11-05-2015
09:15 AM
|
0
|
6
|
5256
|
|
POST
|
There is already a tool that lets you find x,y. it's called "Go To X,Y".
... View more
11-03-2015
03:19 PM
|
0
|
0
|
1011
|
|
DOC
|
Lara, That worked! thank you. Robert, Love the widget!
... View more
11-02-2015
01:19 PM
|
1
|
0
|
6453
|
|
DOC
|
nice to hear some one else is having this issue. Can you give a little more detail on how you swop the http for https? are you referring to the App Registration Application URL: or the Redirect URI:?
... View more
11-02-2015
12:01 PM
|
0
|
0
|
6453
|
|
DOC
|
I did see that, so after i got the error i closed out of Web builder and restarted it. At first when i input the search url it looks fine but once i click on Add Expression Value and see that i can't create the expression i hit cancel then i get the red explanation. So i again closed out of web appbuilder and restarted the program but this time i click on edit "Louisville Zoning" layer i get the same error... I have delete the arcgis-web-appbuilder-1.2 folder and re-down loaded arcgis-web-appbuilder-1.2 zip and the and unzip it and placed the enhanced search widget 1.2.05 in the \client\stemapp\widgets folder after all that i still have this issue...
... View more
11-02-2015
10:33 AM
|
0
|
0
|
6453
|
|
DOC
|
I have downloaded the new version of Web App builder and placed the enhanced search widget 1.2.05 in the \client\stemapp\widgets folder of arcgis-web-appbuilder-1.2. I start a new app and and when i try to configure the enhanced search widget i get errors. when i add my search URL the update search layer prompt looks ok, when i get to to add expression value popup i can't make the expression value it's just blank. I can't click on the box for a drop down. I am i missing something or doing something wrong?
... View more
11-02-2015
09:54 AM
|
0
|
0
|
6453
|
|
POST
|
Jake the code you posted worked but it truncated the "zero's" like so Bld4, Bld5, Bld4. etc. How can get them to be like so Bld00004, Bld00005, Bld00003, Bld001069?
... View more
09-10-2015
11:13 AM
|
0
|
1
|
1793
|
|
POST
|
The list shouldn't be empty, there are features that have a bld00001, bld00002, etc numbering in the Bld_ID field. thanks for the reply.
... View more
09-10-2015
10:13 AM
|
0
|
1
|
1793
|
|
POST
|
I have two layers with building footprints I need to update one of them. After merging layers I have some features with an sequential number in the field Bld_ID field but some don't. So i need to update the Bld_ID with sequential number and they start with "Bld": example bld000001, bld00002, bld00003, etc. So some how i need to find the last highest sequential number in the field Bld_ID then add 1 to that and use that to update the buildings i have selected. I have a code i used for something similar but i am running into the an error with this any help would be appreciated: Runtime error Traceback (most recent call last): File "<string>", line 30, in <module> IndexError: list index out of range import arcpy, sys, re, os
from arcpy import env
import string
arcpy.env.qualifiedFieldNames = False
arcpy.env.overwriteOutput = True
Bld = "BuildingFootprints" #target point feature class
BldCount = int(arcpy.GetCount_management(Bld).getOutput(0))
dsc = arcpy.Describe(Bld)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif BldCount >= 1:
#Gets the highest AddressID and calculates new point to assign new highest AddressID
Bld_list = []
with arcpy.da.SearchCursor(Bld, ["Bld_ID"]) as cursor:
for row in cursor:
try:
if "Bld" in row[0]:
Bld_list.append(int(row[0].strip("Bld")))
except TypeError:
pass
del cursor
Bld_list.sort()
Bld_ID = Bld_list[-1] + 1
Bld_ID = 'Bld' + str(Bld_ID)
with arcpy.da.UpdateCursor(Bld, "Bld_ID") as rows:
for row in rows:
row[0] = Bld_ID
rows.updateRow(row)
del row
del rows
... View more
09-10-2015
09:13 AM
|
0
|
6
|
4536
|
|
POST
|
if i ran the script in ArcMap python window i had to use the arcpy.Delete_management to delete the "NOTIFBUF1" right after the MultipleRingBuffer_analysis becaue it would add a new "NOTIFBUF1". if i didn't i would remove the broken layer from mxd. I ran the same script in a tool script and i did not have to use the Delete_management because it did not remove the layer from the mxd and it updated the broken layer just fine. Interesting findings.
... View more
08-28-2015
09:35 AM
|
0
|
0
|
1703
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2022 11:37 AM | |
| 1 | 10-31-2023 10:16 AM | |
| 1 | 02-16-2023 01:50 PM | |
| 1 | 08-11-2021 11:13 AM | |
| 1 | 01-06-2021 10:45 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-10-2024
10:42 AM
|