|
POST
|
It does but I am looking to delete rows with just hash tag and apostrophe.
... View more
05-18-2020
10:33 AM
|
0
|
3
|
1501
|
|
POST
|
I have a feature class table that i need to delete the rows with special characters of # , ' or other certain special characters. I have tried the following but nothing happens so I am not coding it correctly, I am in need of some help please. A2 = "ArcSDE Personal Server/featureclass"
# sql SubName LIKE '%#'
with arcpy.da.UpdateCursor(A2 , ["OBJECTID","Field"]) as cursor:
for row in cursor:
if row[1] in ["'", "#"]:
print ("Deleting record: 'OBJECTID' = {}".format(row[0]))
cursor.deleteRow()
... View more
05-18-2020
09:56 AM
|
0
|
7
|
1584
|
|
POST
|
I wanted to do select multiple values and tried the following but it seems like it just selects "Active" ones. I need to select "Active" & "Existing", fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)
#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"
where_clause = "Status IN ('Active%','Existing%')"
arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr", where_clause)
arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")
... View more
04-28-2020
07:00 AM
|
0
|
2
|
1500
|
|
POST
|
I am trying to update a feature class with points that have "Active" in the "Status" field. I have tried "Status LIKE 'Active%'" & "\"Status\" LIKE 'Active%'" for the query but no matter what it appends all of the points. fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)
#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"
arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr")
arcpy.SelectLayerByAttribute_management("CCAP1_lyr", "NEW_SELECTION", "Status LIKE 'Active%'") #"\"Status\" LIKE 'Active%'"
arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")
... View more
04-27-2020
10:35 AM
|
0
|
4
|
1592
|
|
POST
|
I am getting an error and " The field BUFF_DIST is a double, file is a shapefile. Runtime error Traceback (most recent call last): File "<string>", line 24, in <module> File "<string>", line 22, in <dictcomp> RuntimeError: A column was specified that does not exist Never mind I forgot to change OBJECTID to FID, since it's a shapefile. Everything works, thanks for sharing.
... View more
02-11-2020
02:24 PM
|
0
|
1
|
3209
|
|
POST
|
After trying the delete Identical like you suggested i was still getting duplicates. I found that it was due to fact that i had the delete duplicates before the arcpy.CalculateField_management to making the field all upper case, once i put the delete duplicate block after arcpy.CalculateField_management it was fine. Some of the tables had lower case while others had lower case. I didn't think that would make a difference if they were lower vs upper case.
... View more
02-10-2020
10:59 AM
|
0
|
1
|
1274
|
|
POST
|
I am trying to delete duplicates form a table but the issues is the part where I try to delete the duplicates. The script merges table together then delete the duplicates. After the script runs i noticed that there were still duplicates so i ran just the delete duplicates part of the script in a stand alone script and it removes totally different duplicates so i am confused as to why the delete duplicates part removes duplicates differently. Any ideas? If i run the following import arcpy
from datetime import datetime as d
import logging, os
startTime = d.now()
start_time = time.time()
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\\Users\\***\\AppData\\Roaming\\Esri\\ArcGISPro\\Favorites\\***.sde"
# Get a list of all the tables.
tableListA = arcpy.ListTables('DSD.DBO.SubdivisionList')
# Loop through the list and run truncate
for tableA in tableListA:
arcpy.TruncateTable_management(tableA)
#SDE tables and feature classes
tableA = r'C:\\Users\\SubdivisionList' #table that gets updated from ORN and Centerline
tableB = r'C:\Users\\Subdivision_boundaries'
tableC = r'C:\Users\PreliminarySubs'
tableD = r"C:\Users\Official_Subdivision_Names"
####Compare and inject missing street names from ORN table
tableAList = []
with arcpy.da.SearchCursor(tableA, ['PLAT_NAME']) as cursor:
for row in cursor:
tableAList.append(row[0])
del cursor
#list of fields whose will need to be imported into tableA
fields = ['PLAT_NAME']
#list of values from tableA to inject into tableC
ids = []
with arcpy.da.SearchCursor(tableC, ['SUBNAME']) as cursor:
for row in cursor:
if row[0] not in tableAList:
ids.append(row[0:])
del cursor
#create insert cursor variable
insertCursor = arcpy.da.InsertCursor(tableA,fields)
#loop through items in ids list and insert into table
for i in ids:
insertCursor.insertRow(i)
del insertCursor
del ids
###Compare and inject missing street names and Status field from centerline
tableAList = []
with arcpy.da.SearchCursor(tableA, ['PLAT_NAME', 'Year']) as cursor:
for row in cursor:
tableAList.append(row)
del cursor
#list of fields whose will need to be imported into tableA
fields = ['PLAT_NAME', 'Year']
#list of values from tableB to inject into tableA
ids = []
with arcpy.da.SearchCursor(tableB, ['PLAT_NAME', 'Year']) as cursor:
for row in cursor:
if row[0] not in tableAList:
ids.append(row)
del cursor
#create insert cursor variable
insertCursor = arcpy.da.InsertCursor(tableA,fields)
#loop through items in ids list and insert into table
for i in ids:
insertCursor.insertRow(i)
del insertCursor
del ids
print ("Finihsed Comparing and inject missing street names from Preliminary Plats")
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
###### Compare replicated Subnames From SDE
######
table1List = []
with arcpy.da.SearchCursor(tableA, ['PLAT_NAME', 'Year']) as cursor:
for row in cursor:
table1List.append(row[0])
del cursor
#list of fields whose will need to be imported into table1
fields = ['PLAT_NAME', 'Year']
#list of values from table1 to inject into table3
ids = []
with arcpy.da.SearchCursor(tableD, ['PLAT_NAME', 'Year']) as cursor:
for row in cursor:
if row[0] not in table1List:
ids.append(row[0:])
del cursor
#create insert cursor variable
insertCursor = arcpy.da.InsertCursor(tableA,fields)
#loop through items in ids list and insert into table
for i in ids:
insertCursor.insertRow(i)
del insertCursor
del ids
print ("Finihsed Comparing and inject missing Subs names from replicated Subnames From SDE")
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
#Deletes duplicate records after merging centerline and ONR
fc = r'C:\\Users\\SubdivisionList'
fields1 = ['OBJECTID', 'PLAT_NAME']
table_rows = []
with arcpy.da.UpdateCursor(fc, fields1) as cursor1:
for row in cursor1:
if row[1:] in table_rows:
print ("Deleting record: OBJECTID = {}".format(row[0]))
cursor1.deleteRow()
else:
table_rows.append(row[1:])
del table_rows
del cursor1
It removes only these Deleting record: OBJECTID = 1817 Deleting record: OBJECTID = 1883 Deleting record: OBJECTID = 1938 Deleting record: OBJECTID = 1939 Deleting record: OBJECTID = 2150 Deleting record: OBJECTID = 2151 Deleting record: OBJECTID = 2152 Deleting record: OBJECTID = 2153 Deleting record: OBJECTID = 2154 Deleting record: OBJECTID = 2155 Deleting record: OBJECTID = 2156 Deleting record: OBJECTID = 2157 Deleting record: OBJECTID = 2158 Deleting record: OBJECTID = 2159 Deleting record: OBJECTID = 2160 Deleting record: OBJECTID = 2161 Deleting record: OBJECTID = 2162 Deleting record: OBJECTID = 2163 Deleting record: OBJECTID = 2164 Deleting record: OBJECTID = 2165 Deleting record: OBJECTID = 2166 Deleting record: OBJECTID = 2167 If I just run the deleterows after the above script it deletes more. The delete row in the above script should delete all the duplicates..? import arcpy
fc = r'C:\\Users\\SubdivisionList'
fields = ['OBJECTID', 'PLAT_NAME']
table_rows = []
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[1:] in table_rows:
print ("Deleting record: OBJECTID = {}".format(row[0]))
cursor.deleteRow()
else:
table_rows.append(row[1:])
del table_rows It deletes Deleting record: OBJECTID = 2 Deleting record: OBJECTID = 11 Deleting record: OBJECTID = 311 Deleting record: OBJECTID = 419 Deleting record: OBJECTID = 545 Deleting record: OBJECTID = 640 Deleting record: OBJECTID = 945 Deleting record: OBJECTID = 976 Deleting record: OBJECTID = 1003 Deleting record: OBJECTID = 1076 Deleting record: OBJECTID = 1103 Deleting record: OBJECTID = 1286 Deleting record: OBJECTID = 1518 Deleting record: OBJECTID = 1705 Deleting record: OBJECTID = 1884 Deleting record: OBJECTID = 1951 Deleting record: OBJECTID = 2069 Deleting record: OBJECTID = 2071
... View more
02-10-2020
09:24 AM
|
0
|
3
|
1348
|
|
POST
|
Xander, Thanks for the reply and code, after running your example i noticed that the result is the same as my script. I thought i posted pics of my code results but i guess i didn't. It seems as both your and my code cuts out the over lapping polygons. I forgot to mention that there are some over lapping poygons.
... View more
01-22-2020
08:11 AM
|
0
|
5
|
3208
|
|
POST
|
At this point i would like to just merge the features without the attributes.
... View more
01-21-2020
09:26 AM
|
0
|
7
|
3208
|
|
POST
|
Correct this is would not be a result of buffering, i don't wan to recreate a new feature class and I want to merge the attributes similar to the what you do in Arcmap when you select features,start editing, click editor tool bar- merge. This would all take place in ArcMap's Python not stand alone. I came close to this with the code i posted but i can't get it correct. Thanks for the reply.
... View more
01-13-2020
01:49 PM
|
0
|
0
|
3208
|
|
POST
|
I appreciate the info but I was trying to find a way to do this with out so many process.
... View more
01-13-2020
10:08 AM
|
0
|
2
|
6076
|
|
POST
|
sorry but i am not sure how i can incorporate what you posted into my code to do what i need it to do.
... View more
01-10-2020
08:14 AM
|
0
|
4
|
6076
|
|
POST
|
The lyr just happened to be one that I was testing try to see how I can accomplish the task. The real layer i have is a different layer. I tried the following with SHAPE@ and get the following. The other issue with this code is that none of the attributes get transferred, there is only OID, Shape in the new temp layer. array = arcpy.Array()
with arcpy.da.SearchCursor(lyr, ['SHAPE@']) as rows:
for r in rows:
for part in r[0]:
array.append(part)
poly = arcpy.Polygon(array, sr)
arcpy.management.CopyFeatures(poly, r'in_memory\multipart_poly_merge')
... View more
01-09-2020
01:28 PM
|
0
|
6
|
6076
|
| 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
|