I am attempting to write a script to include an input from the user that represents a "Minimum Confidence Threshold". I want to use this value to only save & print records to the feature class that have a confidence level above (greater than) this threshold. The data is from a .txt file.
My current code is still printing all 411 records. If I have a confidence level of 99 for example, it should only print out 23 record. I think there must be an error with the way I have arranged my statements or indentations.Any advice?
import arcpy
work = raw_input("Enter the full path of WildlandFires.mdb: ") # C:\Scripts\Lab 7 Data\WildlandFires.mdb
arcpy.env.workspace = work # Set the workspace to the geodatabase
arcpy.env.overwriteOutput = True
iFile = raw_input("Enter the full path of wildfire text file: ")# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt
output = raw_input("Enter the name of the output feature class: ")
threshold = raw_input("Specify the minimum confidence threshold: ")
f = open(iFile, 'r')# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt in "read" mode
lstFires = f.readlines() # Read the lines of fire data from the input file
f.close() # close the file
field = ["SHAPE@", "CONFIVALUE"] # represents the field names for each row in the feature class
# Process: Create Feature Class
arcpy.CreateFeatureclass_management(work, output, "POINT")
arcpy.AddField_management(output, "CONFIVALUE", "FLOAT")
cursor_new = arcpy.da.InsertCursor(output, field)# add the new points that you will create to the "NewFires" feature class
cntr = 0 # counter variable
for fire in lstFires:
if 'Latitude' in fire: # Skip the header
continue
pnt2 = arcpy.Point() # Create a new Point object
lstValues = fire.split(',') # create a list of values "lstValues" based on the type of delimiter
str_int = lstValues [-3:]
str_int = list(map(float, str_int)) #turns string to integers
latitude = str_int[0] # Latitude
longitude = str_int[1] # Longitude
confid = str_int[2] # Confidence Value
if (confid > threshold):
pnt2.X = longitude # Assign the X and Y properties of the Point object
pnt2.Y = latitude
row = [pnt2, confid] # Create a new row for the feature class
cursor_new.insertRow(row) # Insert the new row to the feature class
cntr = cntr + 1 # update the counter
print "Record # " + str(cntr) + " written to feature class"
del cursor_new # release the cursor lock on the feature class