POST
|
Using Pro I've converted a layers labels to graphics, can they converted graphics be edited, if so how? I know they can be edited if labels are converted to Annotation. I have tried to to edit them in the layout and have tried activating the map frame. This was easily done in Arcmap. Thanks.
... View more
09-07-2022
09:54 AM
|
0
|
2
|
526
|
POST
|
Sorry for the late response. I wasn't sure if you meat separate the two into two separate calculate values, how I was suppose to call the first calculate value to the second calculate value. So I figured why the model didn't stop, FLD_ZONE had some empty attributes. I tried the following it runs but nothing is merged, no errors. fc = r"C:\Temp\FEMA.gdb\FEMA_TempLyrs
def f(fc):
case_fields = ["FLD_ZONE",'ZONE_SUBTY'] # field(s) to group records for merging
sort_field, sort_order = "OBJECTID", "ASC"
shape_field = "SHAPE@"
fields = case_fields + [sort_field, shape_field]
sql_orderby = "ORDER BY {}, {} {}".format(", ".join(case_fields), sort_field, sort_order)
with da.UpdateCursor(fc, fields, sql_clause=(None, sql_orderby)) as cur:
for row in cur:
print (row)
if row[0] == None:
case_func = itemgetter(*range(len(case_fields)))
merged_polys = {
key:reduce(arcpy.Geometry.union, (row[-1] for row in group))
for key, group
in groupby(cur, case_func)
}
cur.reset()
for key, group in groupby(cur, case_func):
row = next(group)
cur.updateRow(row[:-1] + [merged_polys[key]])
for row in group:
cur.deleteRow()
del cur
return fc I also tried separating the operations like you stated but nothing gets merged, with error. Error: ERROR 000539: Traceback (most recent call last): File "<expression>", line 1, in <module> File "<string>", line 38, in fc1 TypeError: 'NoneType' object is not subscriptable import sys, arcpy, os
from arcpy import env
from arcpy import da
from itertools import groupby
from operator import itemgetter
from functools import reduce
fc = r"C:\Temp\FEMA.gdb\FEMA_TempLyrs"
def f(fc):
case_fields = ["FLD_ZONE",'ZONE_SUBTY'] # field(s) to group records for merging
sort_field, sort_order = "OBJECTID", "ASC"
shape_field = "SHAPE@"
fields = case_fields + [sort_field, shape_field]
sql_orderby = "ORDER BY {}, {} {}".format(", ".join(case_fields), sort_field, sort_order)
merged_polys = None
with da.SearchCursor(fc, fields, sql_clause=(None, sql_orderby)) as cur:
case_func = itemgetter(*range(len(case_fields)))
for row in cur:
print (row)
if row[0] == None:
merged_polys = {
key:reduce(arcpy.Geometry.union, (row[-1] for row in group))
for key, group
in groupby(cur, case_func)
}
else:
pass
del cur
with da.UpdateCursor(fc, fields, sql_clause=(None, sql_orderby)) as uCur:
for key, group in groupby(uCur, case_func):
row = next(group)
uCur.updateRow(row[:-1] + [merged_polys[key]])
for row in group:
uCur.deleteRow()
return fc
... View more
09-02-2022
03:11 PM
|
0
|
0
|
289
|
POST
|
Thanks for the reply, I guess I am not understand how to put the code/model together to work. Is there another way that this can be accomplished?
... View more
08-31-2022
08:46 AM
|
0
|
2
|
303
|
POST
|
I know I can do it with Dissolve, but the issue with Dissolve is that it creates a separate layer and I know I can do this a script but I need to in Model Builder. I need the function to merge feature class based on two attributes. Can this be down with Calculate value in model builder? I have tried the following, but it never seems to finish the process. The model function does seem to work, I check the feature class and the feature class features are merged. I have to manually hit stop. Expression: f(fc) Code block: import sys, arcpy, os
from arcpy import env
from arcpy import da
from itertools import groupby
from operator import itemgetter
from functools import reduce
fc = r"C:/TEMP/FEMA.gdb/FEMA_TempLyrs"
def f(fc):
case_fields = ["FLD_ZONE",'ZONE_SUBTY'] # field(s) to group records for merging
sort_field, sort_order = "OBJECTID", "ASC"
shape_field = "SHAPE@"
fields = case_fields + [sort_field, shape_field]
sql_orderby = "ORDER BY {}, {} {}".format(", ".join(case_fields), sort_field, sort_order)
with da.UpdateCursor(fc, fields, sql_clause=(None, sql_orderby)) as cur:
case_func = itemgetter(*range(len(case_fields)))
merged_polys = {
key:reduce(arcpy.Geometry.union, (row[-1] for row in group))
for key, group
in groupby(cur, case_func)
}
cur.reset()
for key, group in groupby(cur, case_func):
row = next(group)
cur.updateRow(row[:-1] + [merged_polys[key]])
for row in group:
cur.deleteRow()
del cur
return fc
... View more
08-29-2022
12:15 PM
|
0
|
4
|
365
|
POST
|
man, totally over looked that one. Got it to work with. Thanks for all the help! for row in cursor:
print (f'checking: {row[1]}')
row[2] = 'PLAT' if row[1] in plats_list else assignName.get(row[1], row[3])
cursor.updateRow(row)
... View more
08-23-2022
04:04 PM
|
0
|
0
|
538
|
POST
|
Jeff, Sorry for the delay. I did remove the "*", after I posted my response but still line 14 won't update the row with the plats_list. Both fields are text fields. I've been trying to figure it out but I can't seem to. Logically line 14 makes sense. Also looking at the data there seems to be some blanks in row 1 "Type" field and if that is the case I would like to update row[2] "Type2" with with field1. Sorry I didn't realize this until I was looking into the Type field to see why line 14 was not being updated. If I can get pasted line 14 not passing the plat_list I can figure out how to update "Type" if "Type" field is empty. ObjectID Type field1 Type2 1 BP Permit BuildingPermit 2 FEMA FEMA_LOMARs 3 PLAT - Preliminary Sub PLAT 4 Sub PLAT 5 Floodway FEMA_Floodway import arcpy
fc = 'C:/Temp/permits.gdb/test'
assignName = {"BP" : "BuildingPermit", "FMEA" : "FEMA_LOMAR", 'PLAT': "Sub"}
#fields = ["OBJECTID", "Type", "Type2"]
#print(assignName)
plats_list = ['PLAT - Preliminary' ,'PLAT - Final', 'PLAT - Short']
cursor = arcpy.da.UpdateCursor(fc,["OBJECTID", "Type", "Type2"])
for row in cursor:
if row[1] in assignName:
print (assignName[row[1]])
row[2] = assignName['PLAT'] if row[1] in plats_list else assignName.get(row[1])
cursor.updateRow(row)
... View more
08-23-2022
12:51 PM
|
0
|
2
|
551
|
POST
|
Thanks for the reply, really appreciate it. That explains why I didn't find anything about wildcards in Dictionaries. I have added your suggestion but field "Type2" doesn't get populated with "Plat". import arcpy
fc = 'C:/Temp/permits.gdb/test'
assignName = {"BP" : "BuildingPermit", "FMEA" : "FEMA_LOMAR", 'PLAT*': "Sub"}
#fields = ["OBJECTID", "Type", "Type2"]
#print(assignName)
plats_list = ['PLAT - Preliminary' ,'PLAT - Final', 'PLAT - Short']
cursor = arcpy.da.UpdateCursor(fc,["OBJECTID", "Type", "Type2"])
for row in cursor:
if row[1] in assignName:
print (assignName[row[1]])
row[2] = assignName['PLAT'] if row[1] in plats_list else assignName.get(row[1])
cursor.updateRow(row)
... View more
08-19-2022
02:18 PM
|
0
|
5
|
618
|
POST
|
I need to update the third row with the second row, the issue is that the entries are not consistent. Field three has entities like so; PLAT - final PLAT -short PLAT -prelim PLAT -Reserved PLAT -asdf PLAT -lkjhh etc. I would like to update row 3 with just Plat. I don't want to write a pair for each one. So can I do a wild card? I tried 'PLAT*' on line 5 but it didn't work. import arcpy
fc = 'C:/Temp/permits.gdb/test'
assignName = {"BP" : "BuildingPermit", "FMEA" : "FEMA_LOMAR", 'PLAT*': "Sub"}
#fields = ["OBJECTID", "Type", "Type2"]
print(assignName)
cursor = arcpy.da.UpdateCursor(fc,["OBJECTID", "Type", "Type2"])
for row in cursor:
if row[1] in assignName:
print (assignName[row[1]])
row[2] = assignName[row[1]]
cursor.updateRow(row)
... View more
08-19-2022
10:40 AM
|
0
|
7
|
652
|
POST
|
I was able to get what I need with the following. My only other question is how do I get the counter to on top of the OBJECTID rows? fields = ["OBJECTID", "PN1"]
where = "PN1 = ' ' OR PN1 IS NULL"
counter = 0
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
for row in cursor:
if row[1]in ["", " ", None]:
counter += 1
print ("OBJECTID {0}".format(row[0]) + "has a NULL value in field")
print ("{} {} records have blank/empty or NULL records".format(row[0],counter)) Results; OBJECTID 44has a NULL value in field OBJECTID 47has a NULL value in field OBJECTID 88has a NULL value in field OBJECTID 106has a NULL value in field OBJECTID 108has a NULL value in field OBJECTID 121has a NULL value in field OBJECTID 130has a NULL value in field OBJECTID 182has a NULL value in field OBJECTID 210has a NULL value in field 210 9 records have blank/empty or NULL records How do i put the "210 9 records have blank/empty or NULL records" on top like so 210 9 records have blank/empty or NULL records. OBJECTID 44has a NULL value in field OBJECTID 47has a NULL value in field OBJECTID 88has a NULL value in field OBJECTID 106has a NULL value in field OBJECTID 108has a NULL value in field OBJECTID 121has a NULL value in field OBJECTID 130has a NULL value in field OBJECTID 182has a NULL value in field OBJECTID 210has a NULL value in field
... View more
08-18-2022
10:51 AM
|
0
|
0
|
588
|
POST
|
I was able to get something printed with the suggestion but it repeats. fields = ["OBJECTID", "PN1"]
for field in fields:
where = "PN1 = ' ' OR PlN1 IS NULL"
try:
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
for row in cursor:
#print("Null value in row {0}".format(row[0], row[1]))
print ("OBJECTID {0}".format(row[0]) + "has a NULL value in field")
## result = arcpy.GetCount_management(fc).getOutput(0)
## print ('{} has {} records'.format(fc, result[0]))
except RuntimeError:
pass
del cursor OBJECTID 44has a NULL value in field
OBJECTID 47has a NULL value in field
OBJECTID 88has a NULL value in field
OBJECTID 106has a NULL value in field
OBJECTID 108has a NULL value in field
OBJECTID 121has a NULL value in field
OBJECTID 130has a NULL value in field
OBJECTID 182has a NULL value in field
OBJECTID 210has a NULL value in field
OBJECTID 44has a NULL value in field
OBJECTID 47has a NULL value in field
OBJECTID 88has a NULL value in field
OBJECTID 106has a NULL value in field
OBJECTID 108has a NULL value in field
OBJECTID 121has a NULL value in field
OBJECTID 130has a NULL value in field
OBJECTID 182has a NULL value in field
OBJECTID 210has a NULL value in field
... View more
08-18-2022
09:59 AM
|
0
|
0
|
591
|
POST
|
I am trying to print empty/blank or Null records with the following but when nothing is printed and there is empty/blank and Null records in the layer. I would also like to print the number of empty/blank or Null records. fc = "C:/Temp/Test.gdb/feature Class"
fields = ["OBJECTID", "PN1"]
for field in fields:
where = field + " IS " " OR NULL"
try:
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
for row in cursor:
print("OBJECTID {0}").format(row[0]) + " has a Empty/ Blank or NULL value in field " + field
except RuntimeError:
pass
del cursor
counter = 0
with arcpy.da.SearchCursor(fc,["OBJECTID","PN1"]) as cursor:
for row in cursor:
if row[1] in ["", " ", None]:
counter += 1
print('{} {} is null {} times'.format(row[0],row[1],counter))
else:
pass
... View more
08-18-2022
08:26 AM
|
0
|
4
|
609
|
POST
|
Adding the print statement give the following error. print (search_feats[upd_row[0]]) error KeyError: <PointGeometry object at 0x3900e790[0x3900e620]>
... View more
08-04-2022
08:58 AM
|
0
|
1
|
579
|
POST
|
apologizes for the delay response, I got busy with something else. The print(search_feats), prints {u'Ros': ()} I have attached the data I am working with, if it helps. I changed the parcel data to City limits to help with the size of the up loaded file. I need to update the pointLayer = EMS points2 SiteCity field with the Parcels = CityLimits1 SiteCity field pointLayer = 'EMS_Points2'
city = 'CityLimits1'
sjpoints = "In_memory\sjpoints"
ptCount = 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 ptCount >= 1:
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(pointLayer, city, sjpoints)
search_feats ={f[0]:(f[0]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
print(search_feats)
## with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
## for upd_row in upd_cur:
## try:
## if search_feats[upd_row[0]][1] == "Sea":
## upd_row[1] = "Seattle"
## elif search_feats[upd_row[0]][1] == "Spo":
## upd_row[1] = "Spokane"
## elif search_feats[upd_row[0]][1] == "Tac":
## upd_row[1] = "Tacoma"
## upd_cur.updateRow(upd_row)
## except:
## continue
place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Ros":"Roslyn"}
with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
for upd_row in upd_cur:
try:
upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
upd_cur.updateRow(upd_row)
except:
continue
... View more
08-04-2022
08:20 AM
|
0
|
0
|
204
|
POST
|
i have tried the following and get this error. Runtime error SyntaxError: can't assign to operator (<string>, line 35) Not sure what that means but one thing I did find out about that field is that there is domains to that field. pointLayer = 'EMS'
parcel = 'Ass_Parcels'
ptCount = 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 ptCount >= 1:
arcpy.SpatialJoin_analysis(pointLayer, parcel, sjpoints)
search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
print(search_feats)
## with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
## for upd_row in upd_cur:
## try:
## if search_feats[upd_row[0]][1] == "Sea":
## upd_row[1] = "Seattle"
## elif search_feats[upd_row[0]][1] == "Spo":
## upd_row[1] = "Spokane"
## elif search_feats[upd_row[0]][1] == "Tac":
## upd_row[1] = "Tacoma"
## upd_cur.updateRow(upd_row)
## except:
## continue
place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Tac":"Tacoma"}
with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
for upd_row in upd_cur:
try:
upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
upd_cur.updateRow(upd_row)
except:
continue
... View more
07-28-2022
08:16 AM
|
0
|
3
|
628
|
POST
|
I did catch that after I posted, but I still get the same thing. No errors but nothing is updated. I did look into the field a little and found that the pointLayer "SiteCity" field has domains, not sure if this has any effect or not.
... View more
07-28-2022
07:45 AM
|
0
|
1
|
634
|
Title | Kudos | Posted |
---|---|---|
1 | 01-08-2024 09:44 AM | |
1 | 03-07-2023 11:46 AM | |
1 | 11-02-2020 08:24 AM | |
1 | 01-19-2022 09:19 AM | |
1 | 01-14-2022 11:41 AM |
Online Status |
Offline
|
Date Last Visited |
01-08-2024
02:04 PM
|