POST
|
I have two feature classes "Par" which is the large boundary(Red line) and "Par1" which is just parcels (black lines). The issues is I only get one single parcel populated with my current code. In the example attached, there are 6 parcels within the red boundary and I need all 6 of those parcels to be in the "PARCELS" field. I have the following code and on line 23 I have indicated that I want to use the Join as the merge rule. The "PARCEL" field on line 23 is the Data source field in Par1 that has each parcel. As far as the map options I have tried, INTERSECT, HAVE_THEIR_CENTER_IN, CONTAINS, WITHIN and it's the same results. I am assuming I am over looking something but I am not sure what it is... import sys, arcpy, os, fnmatch
from arcpy import env
from datetime import datetime as d
startTime = d.now()
start_time = time.time()
print ('Started')
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
arcpy.env.workspace = r"C:\Temp\Scratchworkspace.gdb"
fc_Delete = ["BlahTest"]
Par = "C:/Temp/Diss_Par.shp"
Par1 = "C:/Temp/Parcels.shp"
FieldMapString = '''
PIN "PIN" true true false 13 Text 0 0 ,First,#, {0}, PIN,-1,-1;
ACRES "ACRES" true true false 4 Double 0 0 ,First,#, {0}, ACRES,-1,-1;
PARCELS "PARCELS" true true false 200 Text 0 0 ,Join,#, {0}, PARCEL,-1,-1
'''
def Layers1(Par1):
fieldmappings = arcpy.FieldMappings()
fieldmappings.loadFromString(FieldMapString)
return fieldmappings
def main(args=None):
if args is None:
args = sys.argv
arcpy.SpatialJoin_analysis(Par, Par1, "BlahTest", "JOIN_ONE_TO_ONE", "KEEP_ALL",Layers1(Par1), "HAVE_THEIR_CENTER_IN")
print (" Spatial Join Finished")
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
... View more
07-22-2020
08:18 AM
|
0
|
7
|
964
|
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
|
597
|
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
|
680
|
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
|
631
|
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
|
723
|
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
|
1609
|
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
|
450
|
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
|
524
|
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
|
1608
|
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
|
1608
|
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
|
1608
|
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
|
2850
|
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
|
2850
|
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
|