|
POST
|
I have the following, i am trying to select and delete all the empty and null attributes but when i run the code the output feature class is empty. I am not sure what i am doing wrong, the SelectLayerByAttribute_management works in Arcmap python window. # Process: Make Feature Layer
TAX1 = "in_memory\TaxPar"
arcpy.MakeFeatureLayer_management(Taxparcels, TAX1)
#Delets Parcels that are blank, NULL or start with Q
query = "DXF_TEXT LIKE 'Q%' or DXF_TEXT = ' ' or DXF_TEXT IS NULL"
arcpy.SelectLayerByAttribute_management(TAX1, "NEW_SELECTION", query)
if int(arcpy.GetCount_management(TAX1).getOutput(0)) > 0:
arcpy.DeleteFeatures_management(TAX1)
arcpy.FeatureClassToFeatureClass_conversion(TAX1, "D:/GIS Folder/Blah/blah.gdb", "Blah2")
... View more
11-27-2018
02:11 PM
|
1
|
10
|
8439
|
|
POST
|
Sorry to bring this back up but i am still having issues. also the issue with if fc1 doesn't have anything in the "ACCOUNT" field how do you just keep the update cursor going on to the next one? try:
#build a dictionary of ACCOUNT : Address pairs
addDict = {row[0]:row[1] for row in arcpy.da.SearchCursor(fc1,['ACCOUNT','SiteAddress'])}
#search through fc2 to see if addresses match based on ACCOUNT value
with arcpy.da.UpdateCursor(fc2, ['Account','SiteAddres','Verifi2']) as cursor:
for row in cursor:
if row[1] != None:
if row[0] in addDict:
if row[0] != None:
if row[1].strip().lower()!= addDict[row[0]].strip().lower(): #if the value associated with those ids do not match
row[2] = 'No'
else:
row[2] = 'Match'
cursor.updateRow(row)
del cursor
... View more
11-14-2018
03:21 PM
|
0
|
1
|
2364
|
|
POST
|
What if fc1 has blanks? i guess i didn't think about that till now.
... View more
11-07-2018
03:54 PM
|
0
|
0
|
2364
|
|
POST
|
I would like to just bypass them and continue to check for matches.
... View more
11-07-2018
03:34 PM
|
0
|
0
|
2364
|
|
POST
|
I have the following and i get 'NoneType' object has no attribute 'strip' on line 10. There are some records that have NULL or Blanks in the ACCOUNT field. How do i bypass or skill the ones that are null or blank? try:
#build a dictionary of ACCOUNT : Address pairs
addDict = {row[0]:row[1] for row in arcpy.da.SearchCursor(fc1,['ACCOUNT','SiteAddress'])}
#search through fc2 to see if addresses match based on ACCOUNT value
with arcpy.da.UpdateCursor(fc2, ['Account','SiteAddres','Verifi2']) as cursor:
for row in cursor:
if row[1] != None:
if row[0] in addDict:
if row[1].strip().lower()!= addDict[row[0]].strip().lower(): #if the value associated with those ids do not match
row[2] = 'No'
else:
row[2] = 'Match'
cursor.updateRow(row)
del cursor
... View more
11-07-2018
02:51 PM
|
0
|
7
|
2507
|
|
POST
|
I have the following code to convert KML to Shapefiels but i am getting error on line 26 i am not sure why? line 26, in <module> wks.remove(MasterGDBLocation) ValueError: list.remove(x): x not in list import arcpy, os
# Set workspace (where all the KMLs are)
arcpy.env.workspace="D:\GIS Folder\IDTrialsRoads"
# Set local variables and location for the consolidated file geodatabase
outLocation = "D:\GIS Folder\IDTrialsRoads"
MasterGDB = 'TrailsRoads.mdb'
MasterGDBLocation = os.path.join(outLocation, MasterGDB)
# Create the master FileGeodatabase
arcpy.CreateFileGDB_management(outLocation, MasterGDB)
# Convert all KMZ and KML files found in the current workspace
for kmz in arcpy.ListFiles('*.KM*'):
print "CONVERTING: " + os.path.join(arcpy.env.workspace,kmz)
arcpy.KMLToLayer_conversion(kmz, outLocation)
# Change the workspace to fGDB location
arcpy.env.workspace = outLocation
# Loop through all the FileGeodatabases within the workspace
wks = arcpy.ListWorkspaces('*', 'FileGDB')
# Skip the Master GDB
wks.remove(MasterGDBLocation)
for fgdb in wks:
# Change the workspace to the current FileGeodatabase
arcpy.env.workspace = fgdb
# For every Featureclass inside, copy it to the Master and use the name from the original fGDB
featureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')
for fc in featureClasses:
print "COPYING: " + fc + " FROM: " + fgdb
fcCopy = fgdb + os.sep + 'Placemarks' + os.sep + fc
arcpy.FeatureClassToFeatureClass_conversion(fcCopy, MasterGDBLocation, fgdb[fgdb.rfind(os.sep)+1:-4] + "_" + fc)
... View more
10-25-2018
09:38 AM
|
0
|
3
|
2356
|
|
POST
|
I add an if statement but the null and blanks one don't get updated sequentially. I get no error's, i did add "=" to line 26. RD_ID += 1 import arcpy
fc = r'C:\Temp\Address_Points.shp'
#arcpy.CalculateField_management(fc, "RD_ID", '""" """', "PYTHON")
rd_list = []
with arcpy.da.SearchCursor(fc, ["RD_ID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
rd_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
rd_list.sort()
RD_ID = rd_list[-1] + 1
#whereclause = "RD_ID = '%CC%'"
with arcpy.da.UpdateCursor(fc, "RD_ID") as rows:
for row in rows:
if row[0] in (""," ", None):
row[0] = 'CC%05d' %RD_ID
RD_ID += 1
rows.updateRow(row)
del row
print 'Done'
... View more
07-02-2018
10:29 AM
|
0
|
1
|
1001
|
|
POST
|
Darren and you bring up a good questions. I did think about putting that field into a directory and sort. I thought of stripping the "CC" first then adding it back. I don't get an errors but the script is not working correctly it currently updates all the attributes. It populates all of the attributes with CC48932 not just the ones that start with "CC", it doesn't seem to increase. The last RD_ID is CC48931. rd_list = []
with arcpy.da.SearchCursor(fc, ["RD_ID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
point_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
rd_list.sort()
RD_ID = rd_list[-1] + 1
#whereclause = "RD_ID = '%CC%'"
with arcpy.da.UpdateCursor(fc, "RD_ID") as rows:
for row in rows:
row[0] = 'CC%05d' %RD_ID
RD_ID + 1
rows.updateRow(row)
del row
del rows
... View more
07-02-2018
08:56 AM
|
0
|
3
|
5237
|
|
POST
|
I am getting an error at line 16, I think this because i have text and integers (CC12345). import arcpy
fc = r'C:\Temp\Roads.shp'
#add new domain codes
print "Updating domain codes..."
fields = ["RD_ID", "FID"]
old_codes = []
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
try:
old_codes.append(int(row[0]))
except TypeError:
if row[0] is not None and row[0] != "":
print "Error in domain code objectid: {}".format(row[1])
new_code = max(old_codes) + 1
with arcpy.da.UpdateCursor(fc, "RD_ID", "RD_ID") \
as update_cursor:
for row in update_cursor:
if row[0] is not None or row[0] != "":
if row[1] is None or row[1] == "":
print "\tAdding new code {} for {}".format(str(new_code), row[0])
row[1] = new_code
new_code += 1
update_cursor.updateRow(row)
... View more
06-29-2018
10:54 AM
|
0
|
3
|
5237
|
|
POST
|
I have a road layer that i need to add sequential numbering to, the RD_ID field. Some already have a RD_ID number and some are missing. I need to populate attributes of only the missing ones that only have CC in front of them but in sequential order but starting from the last number left off at. I attached a picture of what i need. thanks. I have the following that adds sequential ID but it doesn't take in consideration where the last RD_ID left off. import arcpy
fc = r'C:\Temp\Roads.shp'
startNumber = 0
with arcpy.da.UpdateCursor(fc, "RD_ID") as cursor:
for row in cursor:
row[0] = startNumber
startNumber = startNumber + 1
cursor.updateRow(row)
print 'Done'
... View more
06-29-2018
08:40 AM
|
0
|
11
|
6459
|
|
POST
|
with DATE or with out DATE in line 10 i get the same error. import arcpy
import datetime as DT
#import datetime
fc = r"C:\Temp\BuildingPermit.gdb\ParcelData"
arcpy.MakeFeatureLayer_management(fc, "PT_FC")
from_date = DT.date.today() - DT.timedelta(days=180)
SQL = "created_date >= DATE '{}'".format(from_date.strftime('%Y-%m-%d %H:%M:%S'))
arcpy.SelectLayerByAttribute_management("PT_FC","NEW_SELECTION", SQL)
arcpy.FeatureClassToFeatureClass_conversion("PT_FC", "C:\Temp", "BP_TestA")
Traceback (most recent call last): File "D:\GIS Folder\Python Scripts\WorkingScripts\SelectByDate\SelectByDate4.py", line 12, in <module> arcpy.SelectLayerByAttribute_management("PT_FC","NEW_SELECTION", SQL) File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7744, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).
... View more
05-22-2018
07:52 AM
|
0
|
2
|
2527
|
|
POST
|
I am still getting an invalid expression even with DATE. import arcpy
import datetime as DT
import datetime
fc = r"C:\Temp\BuildingPermit.gdb\ParcelData"
arcpy.MakeFeatureLayer_management(fc, "PT_FC")
from_date = DT.date.today() - DT.timedelta(days=180)
from_date
datetime.date(2017, 11, 18)
SQL = "created_date >= DATE '{}'".format(from_date.strftime('%Y-%m-%d %H:%M:%S'))
SQL
"created_date >= '2017-11-18 00:00:00'"
arcpy.SelectLayerByAttribute_management("PT_FC","NEW_SELECTION", SQL)
arcpy.FeatureClassToFeatureClass_conversion("PT_FC", "C:\Temp", "BP_TestA")
# sometimes you need to indicate type is DATE
# SQL = "created_date >= DATE '{}'".format(from_date.strftime('%Y-%m-%d %H:%M:%S'))
... View more
05-17-2018
03:41 PM
|
0
|
5
|
2527
|
|
POST
|
I am trying to select features from now back to the last 180 days. I am getting an error on the expression. I am not sure but i might be going about it the wrong way. thoughts, suggestions? import arcpy
import datetime
#from datetime import datetime
from datetime import timedelta
fc = r"C:\Temp\BuildingPermit.gdb\ParcelData"
arcpy.MakeFeatureLayer_management(fc, "PT_FC")
start_time= datetime.timedelta(days = 180)
end_time = datetime.datetime.now()
report_time = end_time-start_time
SQL = "created_date >="+ "'"+report_time.strftime('%Y-%m-%d %H:%M:%S')+"'"
arcpy.SelectLayerByAttribute_management("PT_FC","NEW_SELECTION", SQL)
arcpy.FeatureClassToFeatureClass_conversion("PT_FC", "C:\Temp", "BP_TestA")
... View more
05-17-2018
10:23 AM
|
0
|
8
|
3326
|
| 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 |
09-10-2024
10:42 AM
|