POST
|
Below is what prints out. valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
{'2021-0006': ('2957001100', datetime.datetime(2021, 6, 11, 0, 0), None, None, '', None, 'address', 'Active', 'In Progress', None), '2021-0032': ('2957001100', datetime.datetime(2021, 6, 11, 0, 0), None, 'Preliminary Plat', '', None, 'address', 'Active', 'In Progress', None,),
valueDict = {(r[0],r[1]): r for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
{('2021-0006', '2957001100'): ('2021-0006', '2957001100', datetime.datetime(2021, 6, 11, 0, 0), None, None, '', None, 'address', 'Active', 'In Progress', None), ('2021-0032', '2957001100'): ('2021-0032', '2957001100', datetime.datetime(2021, 6, 11, 0, 0), None, 'Preliminary Plat', '', None, 'address', 'Active', 'In Progress', None),
... View more
02-10-2022
07:33 AM
|
0
|
5
|
932
|
POST
|
ok, based on what you are describing I think that is my problem. I guess I am not sure how to iterating loop over the vale sets that match. Do you have an example?
... View more
02-09-2022
04:02 PM
|
0
|
7
|
946
|
POST
|
PermitNum should be the unique identifier but as you can see PermitNum has duplicates because I don't have no other Unique Identifier.
... View more
02-09-2022
03:19 PM
|
0
|
0
|
946
|
POST
|
I thought that's what line 9 was doing? My unique identifers are PermtNum and Par fields, the Apps field is just a date field. Unless I am not understanding the dictionary correctly...? valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
... View more
02-09-2022
12:53 PM
|
0
|
2
|
969
|
POST
|
I have the following script and the issues I am having is that the PermitNum can have multiple Par (par field) numbers but my current script will only populate the Parel field with just one Par attribute, it doesn't transfer each parcel that corresponds with each permit number. How can I adjust my current code to transfer each parcel number? fc_dest = "D:/Temp/Cases"
sourceFC = "D:/Temp/Casestableview"
#Use Dictionary to update fc fileds.
sourceFieldsList = ['PermitNum','Par','AppS','AppT', 'SubT','Desc', 'MainApp', 'PA', 'Status', 'AppStatus', 'DecDate',]#,'ProjectInfo', 'Contractor', 'Subdivision', 'TwnRngSec', 'LivingSpace', 'TotalSqFt', 'Value_', 'Valuation', 'Status']
# Use list comprehension to build a dictionary from a da SearchCursor
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
updateFieldsList = ['PermitNum','Par','AppS','AppT', 'SubT','Descr', 'MainApp', 'PA', 'Status', 'AppStatus', 'DecDate']
with arcpy.da.UpdateCursor(fc_dest, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value of the row being updated in a keyValue variable
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the values stored under the keyValue from the dictionary to the updated fields.
for n in range (1,len(sourceFieldsList)):
updateRow[n] = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
del valueDict
... View more
02-09-2022
10:13 AM
|
0
|
23
|
2169
|
POST
|
my indentation on line 8 was incorrect. with arcpy.da.UpdateCursor(fc, flds) as upd_cur:
for upd_row in upd_cur:
if upd_row[0] in search_feats.keys():
if upd_row[1] in ("", ' ', None):
upd_row[1] = search_feats[upd_row[0]][1]
if upd_row[2] in ("", ' ', None):
upd_row[2] = search_feats[upd_row[0]][0]
upd_cur.updateRow(upd_row)
... View more
01-06-2022
12:39 PM
|
0
|
0
|
465
|
POST
|
Thank you I appreciate the replay. I do have something similar with a arcpy.da.UpdateCurosr. I was trying to see how it would be done with a dictionary key. I was think of adding another "if" but I am not 100% sure if I am understand the dictionary keys right. with arcpy.da.UpdateCursor(fc1,flds) as upd_cur:
for upd_row in upd_cur:
if upd_row[0] in search_feats.keys():
if upd_row[1] == None:
upd_row[1] = search_feats[upd_row[0]][1]
if upd_row[2] == None:
upd_row[2] = search_feats[upd_row[0]][0]
upd_cur.updateRow(upd_row)
... View more
01-06-2022
11:39 AM
|
0
|
1
|
468
|
POST
|
I have the following but It's only works to populate for Field1, I would like to populate Field1 blanks or Nulls with Field2 attributes and Field2 blanks or nulls with Field1. I have the the following but it only works to populate Field1.. Maybe I am going about this the wrong way? flds = ['FID', 'Field1','Field2'] # FID shapefile, OID geodatabase
search_feats = {f[0]:(f[1:]) for f in arcpy.da.SearchCursor(fc1,flds)}
with arcpy.da.UpdateCursor(fc1,flds) as upd_cur:
for upd_row in upd_cur:
if upd_row[0] in search_feats.keys():
if upd_row[1] == None:
upd_row[1] = search_feats[upd_row[0]][1]
upd_cur.updateRow(upd_row)
else:
pass
del upd_cur
... View more
01-05-2022
12:09 PM
|
0
|
3
|
498
|
POST
|
Hopefully this helps someone, not sure if this is the best way but was the only thing I can find. Code below line 8 is by JoshuaBixby. Casenum = arcpy.GetParameterAsText(1)
Splt = str(Casenum.split(";"))
arcpy.AddMessage("Case ={0}".format(Splt))
SP = "SUBJECT"
arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.CalculateField_management(SP, "PermitNo", '"' + Casenum +'"', "PYTHON_9.3")
split_fld = "PermitNo" # Field to split
split_delim = ";"# Delimeter for splitting field
sys_flds = [
'OIDFieldName', 'globalIDFieldName',
'ShapeFieldName', 'areaFieldName', 'lengthFieldName'
]
desc = arcpy.Describe(SP)
sys_fld_names = [
name for name in (getattr(desc, fld, '') for fld in sys_flds) if name
]
usr_fld_names = [
fld.name for fld in desc.fields if fld.name not in [split_fld] + sys_fld_names
]
cur_flds = ["SHAPE@", split_fld] + usr_fld_names
with arcpy.da.Editor(desc.path) as edit:
with arcpy.da.UpdateCursor(SP, cur_flds) as ucur:
with arcpy.da.InsertCursor(SP, cur_flds) as icur:
for row in ucur:
shape = row.pop(0)
split = row.pop(0).split(split_delim)
for i in split[1:]:
icur.insertRow([shape, i] + row)
ucur.updateRow([shape, split[0]] + row)
... View more
11-09-2021
01:56 PM
|
0
|
0
|
467
|
POST
|
I currently coping and pasting features and I haven't been able to find any examples or ideas o how I can accomplish this so any help would be very appreciated.
... View more
11-04-2021
11:20 AM
|
0
|
0
|
481
|
POST
|
I have this but how do I split the GetParameter into two if two parameters(GetParameterAsText(2)) are given and apply one to each Pin? lyr = arcpy.mapping.ListLayers(mxd, "TAXLOTS")[0]
#Parcel numbers
values = arcpy.GetParameterAsText(0)
fieldName = "PIN"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
#selects the parcel numbers and creates Subject property
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.Select_analysis("TAXLOTS", "SUBJECT")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
#AddsPermitNumber
Casenum = arcpy.GetParameterAsText(2)
SP = "SUBJECT"
arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.CalculateField_management(SP, "PermitNo", '"' +Casenum+'"', "PYTHON_9.3") #"!{0}!".format(values)
args = [arcpy.GetParameterAsText(1)for i in range(arcpy.GetArgumentCount())]
#pCount = arcpy.GetArgumentCount(1)
if args == 2: #
dsc = arcpy.Describe(SP)
fields = dsc.fields
#out_fields = [dsc.OIDFieldName]
fieldnames = [field.name for field in fields]
#lstFields = [field.name for field in fields]
with arcpy.da.SearchCursor(SP,fieldnames) as sCur:
with arcpy.da.InsertCursor(SP,fieldnames) as iCur:
for row in sCur:
iCur.insertRow(row)
else:
pass I get the following Pin Permit No 12345 MC2021-0002;CD2021-0005 12346 MC2021-0002;CD2021-0005 But need Pin Permit No 12345 MC2021-0002 12346 CD2021-0005
... View more
10-12-2021
09:22 AM
|
0
|
0
|
507
|
POST
|
I have a script that I am trying to add/ include multiple parameters for multiple features. Parcels can have multiple case numbers associated with them. For example Parcel Pin12345 can have permit MC2021-0001 and CD20201-0001. I want to be able to create two separate parcels\features with the same Pin12345 but different permit numbers but only if I input multiple Parameters. If I just enter one parameter in then I just need one pin with the case I enter. Sometimes case number can have 2 or 10 parcels for that particular case. I am not sure what is the best way to do this but this is what I have and it works great with just one case no. lyr = arcpy.mapping.ListLayers(mxd, "TAXLOTS")[0]
#Parcel numbers
values = arcpy.GetParameterAsText(0)
fieldName = "PIN"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
#selects the parcel numbers and creates Subject property
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.Select_analysis("TAXLOTS", "SUBJECT")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
#AddsPermitNumber
Casenum = arcpy.GetParameterAsText(2)
SP = "SUBJECT"
arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.CalculateField_management(SP, "PermitNo", '"' +Casenum+'"', "PYTHON_9.3") #"!{0}!".format(values)
... View more
10-05-2021
04:11 PM
|
0
|
3
|
564
|
POST
|
The file is a in filegeodata base, I exported out to a shape to test. I restarted my pc and low and behold it worked.
... View more
08-23-2021
02:41 PM
|
0
|
0
|
771
|
POST
|
Sorry about that, I had different variations trying to figure out what the problem is. Even when adding arcpy.MakeFeatureLayer_management it still deletes all the features. TaxPar = r"C:\Temp\TaxParcels1.shp"
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(TaxPar, "Par")
query = "DXF_TEXT LIKE 'Q%' or DXF_TEXT = ' ' or DXF_TEXT IS NULL"
arcpy.SelectLayerByAttribute_management("Par", "NEW_SELECTION", query)
result = arcpy.GetCount_management("Par").getOutput(0)
print ('{} has {} records'.format("Par", result[0]))
if int(arcpy.GetCount_management("Par").getOutput(0)) > 0:
arcpy.DeleteFeatures_management("Par")
... View more
08-23-2021
12:39 PM
|
0
|
0
|
774
|
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 |
01-23-2024
11:04 AM
|