|
POST
|
It would be in a geodatabase, I exported it out of the geodatabase for testing sorry about the confusion . If a P_ID has no record in field1 I would like it to populate field1 with what is in field two if there is something in field2. There will be some that don't have anything in field1 and field2 and if that is the case just pass on that records. Field1 and Field2 shouldn't have more than one value.
... View more
10-08-2020
07:31 AM
|
0
|
0
|
1556
|
|
POST
|
Thank you for the response, with the change you provided it looks like it skipped the ones with the same P_ID that had at least one blank/null in Field1 but joined the ones with the same P_ID that had Field1 populated for all those records. Also I just noticed that some Duplicate P_ID don't have anything in Field1 and if that is the case I would like Field1 populated with Field2, for example WI2018-0137. I have attached the data to reference. I really appreciate you help.
... View more
10-07-2020
09:51 AM
|
0
|
2
|
1556
|
|
POST
|
Sorry, they are Null. Correct - If CP0001 has a value of 'Conditional' can there only be 'Blank' or other 'Conditional' values in Field2 for CP001? Correct - Can Field2 have multiple non-empty/blank/null values for a given value of Field1? There are some that are not duplicates, like below. ObjectID Field1 Field 2 --> ObjectID Field1 Field2 01 CP0001 Conditional --> 1 CP0001 Conditional 02 CP0001 Conditional 03 CP0001 Null 04 CP0001 Null 05 CP0003 New ---> 5 CP00003 New 06 CP0009 Old --> 7 CP20009 Old 07 CP0011 AD Decision --> 8 CP0011 AD Decision 08 CP0011 Null 09 CP0011 Null
... View more
10-05-2020
02:01 PM
|
0
|
4
|
1556
|
|
POST
|
I have the following code that was provided by bixb0012 , thank you for the merge code. I need to be able to keep a certain fields attributes/ or transfer them once the merge is done. With the following code some merged features have info in the Field2 but some doesn't. I would like to merge the features that have the same attribute from Field1 but keep/add what is in Field 2 to the new merged Field2. Original features Merged Features ObjectID Field1 Field 2 --> ObjectID Field1 Field2 01 CP0001 Conditional --> 1 CP0001 Conditional 02 CP0001 'Blank' 03 CP0001 'Blank' 04 CP0001 'Blank' 01 CP0014 Relocation --> 2 CP0014 Relocation 02 CP0014 'Blank' 03 CP0014 'Blank' 04 CP0014 'Blank' from arcpy import da
from itertools import groupby
from operator import itemgetter
from functools import reduce
fc = # path to feature class or table
case_fields = ["field1", "field2"] # 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)
kwargs = {"in_table":fc, "field_names":fields, "sql_clause":(None, sql_orderby)}
with da.UpdateCursor(**kwargs) as ucur, da.SearchCursor(**kwargs) as scur:
case_func = itemgetter(*range(len(case_fields)))
ugroupby, sgroupby = groupby(ucur, case_func), groupby(scur, case_func)
for (ukey,ugroup),(skey,sgroup) in zip(ugroupby,sgroupby):
poly = reduce(arcpy.Geometry.union, (row[-1] for row in sgroup))
row = next(ugroup)
ucur.updateRow(row[:-1] + [poly])
for row in ugroup:
ucur.deleteRow()
... View more
10-05-2020
09:40 AM
|
0
|
6
|
1694
|
|
POST
|
Thanks for sharing Randy, The code worked great for the data I attached but after hours it took me a while to figure out that my original data had fields that quite didn't match the taxlots fields. So it's my fault for not providing the correct data I was trying to cut down the data size and I apologize. For example, the points have fieldA, field1, field2, field3 and the point taxlots have field_A, field_1, field_2, field_3. The code works great if I only need those field but like I mentioned I need something that will also include fields that don't match. So for the fields that don't match I need to transfer field_A --> fieldA field_1 --> field1 field_2 --> field1 field_3 --> field1
... View more
10-01-2020
03:20 PM
|
0
|
1
|
1430
|
|
POST
|
Randy, This is very helpful thank you. If you don't mind sharing the spatial join and field mapping code that would be great.
... View more
09-29-2020
07:40 AM
|
0
|
3
|
1430
|
|
POST
|
Randy, I have attached the point and taxlots, I would like to update just the selected well points, maybe one or maybe 50, 100+, not all wells need to be updated just missing ones or the ones I select, some parcel may have more than one well. I am not sure if failed attempt to do it is the best and fastest way, maybe spatial join, also some records can have 0 or null, blanks...? The other question is there a way to update the fields on the points from the taxlots if they exist/match without having to type each field out? Thanks for the help Randy!
... View more
09-25-2020
10:37 AM
|
0
|
0
|
1430
|
|
POST
|
I am having a hard time looping through the selections, I am not sure how to pass it to the rest of my code. Then again I am not sure my approach is the best...? ptCount = int(arcpy.GetCount_management(ptSelection).getOutput(0))
dsc = arcpy.Describe(ptSelection)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
oidList = []
with arcpy.da.SearchCursor(ptSelection, ['SHAPE@','OID@']) as cursor:
for row in cursor:
oidList.append(row[0])
oid = row[1]
arcpy.AddMessage(oid) # does not print anything in window.
del cursor
for OID in oidList:
arcpy.SelectLayerByLocation_management(parcel,"INTERSECT",ptSelection,"OBJECTID = {}".format(str(row[1])))
arcpy.MakeFeatureLayer_management(parcel,"parcel_lyr")
##next??
... View more
09-23-2020
02:44 PM
|
0
|
0
|
1430
|
|
POST
|
Sorry about that. How do I get this to work on multiple selected? It works great with one feature selected but not with multiple.
... View more
09-11-2020
03:44 PM
|
0
|
1
|
1430
|
|
POST
|
I thought I had pasted the code with the indent and when I pasted the code and without the empty list but I didn't, sorry about that. The code does have the the indent and empty list removed. import arcpy,os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'Database Connections\Connection to blah.sde'
ptSelection = "WellPoints"
pointLayer = arcpy.env.workspace + os.sep + "WellPoints"
parcel = 'WellParcels'
ptCount = int(arcpy.GetCount_management(ptSelection).getOutput(0))
dsc = arcpy.Describe(ptSelection)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
arcpy.SelectLayerByLocation_management(parcel,"INTERSECT",ptSelection)
arcpy.MakeFeatureLayer_management(parcel,"parcel_lyr")
fldList = ['WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
fldDict ={}
if int(arcpy.GetCount_management("parcel_lyr").getOutput(0))==1:
for parrow in arcpy.da.SearchCursor("parcel_lyr",fldList):
for w in range(len(fldList)):
fldDict[fldList ]=parrow
del parrow
targetFields = ['W_ID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
with arcpy.da.UpdateCursor(ptSelection, targetFields) as cursor:
for row in cursor:
row.append(fldDict['WellID']
row.append(fldDict['dep']
row.append(fldDict['type']
row.append(fldDict['Geothermal']
row.append(fldDict['GeoWaterUs']
row.append(fldDict['Temp']
row.append(fldDict['TempDate']
rows.updateRow(row)
del row
... View more
09-11-2020
09:42 AM
|
0
|
3
|
1642
|
|
POST
|
Your right I am on 2.7.14. I figured that I was on 3.6.10 because that the version of the shell I am using. 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] 1.5.2 1.9.3 0.17.0
... View more
09-11-2020
08:13 AM
|
0
|
0
|
1642
|
|
POST
|
I was able to find something that works but it currently only works for one feature at a time, I need it to work with one or 10,20,50. How can I get this to work with with multiple selected features? import arcpy,os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'Database Connections\Connection to blah.sde'
ptSelection = "WellPoints"
pointLayer = arcpy.env.workspace + os.sep + "WellPoints"
parcel = 'WellParcels'
sjpoints = "In_memory\sjpoints"
ptCount = int(arcpy.GetCount_management(ptSelection).getOutput(0))
dsc = arcpy.Describe(ptSelection)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
arcpy.SelectLayerByLocation_management(parcel,"INTERSECT",ptSelection)
arcpy.MakeFeatureLayer_management(parcel,"parcel_lyr")
fldList = ['WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
fldDict ={}
if int(arcpy.GetCount_management("parcel_lyr").getOutput(0))==1:
for parrow in arcpy.da.SearchCursor("parcel_lyr",fldList):
for w in range(len(fldList)):
fldDict[fldList ]=parrow
del parrow
targetFields = ['W_ID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
with arcpy.da.UpdateCursor(ptSelection, targetFields) as cursor:
for row in cursor
row = []
row.append(fldDict['WellID']
row.append(fldDict['dep']
row.append(fldDict['type']
row.append(fldDict['Geothermal']
row.append(fldDict['GeoWaterUs']
row.append(fldDict['Temp']
row.append(fldDict['TempDate']
rows.updateRow(row)
del row
... View more
09-11-2020
08:11 AM
|
0
|
5
|
1642
|
|
POST
|
Got it, thanks. So with arcpy.da.UpdateCursor can on be updated with arcpy.da.Editor. I am trying to do this inside Arcmap with an editor session started but it seems as if i use arcpy.da.UpdateCurosr it won't let me.
... View more
09-10-2020
02:25 PM
|
0
|
1
|
1642
|
|
POST
|
Trying to update some well data from another layer. I am trying to do this in Arcmap (10.6) with a tool/script (3.6.10 Python). I need to transfer attributes from WellParcels to WellsPoints. I would like to do this with out starting a Edit session in python if possible as this tends to slow down the process...? I would manual start an edit session in ArcMap then run the tool/script when I have points selected, I currently have the following but error out on line 44. I am not sure this is the best/fastest way of doing it, so if someone has a different idea please share how I would do this with my data. import arcpy,os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'Database Connections\Connection to blah.sde'
ptSelection = "WellPoints"
pointLayer = arcpy.env.workspace + os.sep + "WellPoints"
parcel = 'WellParcels'
sjpoints = "In_memory\sjpoints"
try:
ptCount = int(arcpy.GetCount_management(ptSelection).getOutput(0))
dsc = arcpy.Describe(ptSelection)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
arcpy.SelectLayerByLocation_management(parcel,"INTERSECT",ptSelection)
arcpy.MakeFeatureLayer_management(parcel,"parcel_lyr")
arcpy.SpatialJoin_analysis(ptSelection, "parcel_lyr" , sjpoints)
#sourceFieldsList = 'WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate'
#valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}
fldList = ['WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
fldDict ={}
print (fldDict)
targetFields = ['W_ID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
with arcpy.da.UpdateCursor(ptSelection, targetFields) as cursor:
for row in cursor
row[0] = ['W_ID']
row[1] = ['dep']
row[2] = ['type']
row[3] = ['Geothermal']
row[4] = ['GeoWaterUs']
row[5] = ['Temp']
row[6] = ['TempDate']
#Attributes from Wellparcels
curosr.append(fldDict['Account', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate'])
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print("Line %i" % tb.tb_lineno)
arcpy.AddMessage("Line %i" % tb.tb_lineno)
print(e.message)
arcpy.AddMessage(e.message)
... View more
09-10-2020
11:06 AM
|
0
|
20
|
3700
|
|
POST
|
After your suggestion I am getting error 000539 invalid syntax expression line 1.
... View more
08-31-2020
01:57 PM
|
0
|
1
|
956
|
| 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
|