How do I transfer one field name from text file to a new field name in feature class?

المشرف العام

Administrator
طاقم الإدارة
I am working on a script that involves incidents of fire. I'm taking my values from a text file that is comma delimited. The first line of the text file contains the field names (Latitude,Longitude,Confidence). My goal is to create a new feature class that will take the last field name from my text file (e.g. Confidence) and use this as the field name is my new feature class. I have succeeded in getting arcgis to read the last field name from my text file so that a new feature class is created with the field names: "ID, SHAPE, Confidence", however, my feature class is empty. I believe that I have the right components, I'm just not sure what order to put them in. The part that confuses me the most is, I start reading the text file in a for loop (which I think it pretty normal) and my instinct is to split this text file and, using indexing, point to the last field name "Confidence" using a variable. Once I do this, I'm not sure how to make my insert cursor and Add Field tool (which are outside of the for loop) recognize this variable that points to "Confidence". Any suggestions? Thank you!

Below is my code:

import arcpy work=r"C:\Users\Cara\Documents\WildlandFires.mdb" arcpy.env.workspace=work arcpy.env.overwriteOutput=True iFile= r"C:\Users\Cara\Documents\NorthAmericaWildfires_2007275.txt" f= open(iFile, 'r') #new feature class name newFC= fireIncidents fc=newFC #user input mininum confidence threshold confidenceThreshold=99 minThresh=int(confidenceThreshold) lstFires = f.readlines() #Create New Feature Class arcpy.CreateFeatureclass_management(work, fc, "POINT", "", "", "", "", "", "", "", "") f.close() #Loop through file line by line and populate new rows in feature class #Create Insert Cursor to use for inserting new rows into feature class fields = ["SHAPE@", fieldName] cur = arcpy.da.InsertCursor (fc, fields) #add field arcpy.AddField_management(fc, fieldName , "SHORT") print "created fields" cntr = 0 #counter variable used to print out progress of script for fire in lstFires: if 'Latitude' in fire: #read line, use split function fn = fire.split(",") fieldName = fn[2] continue lstValues = fire.split(",")#split out values into separate values if int(lstValues[2]) > minThresh: # if confidence value is greater than user defined confidenc value, continue with code #create point object that will hold x,y coordinate of fire pnt = arcpy.CreateObject("Point") #pull out individual values using list indexing latitude = float(lstValues[0]) longitude = float(lstValues[1]) confid = int(lstValues[2]) print "I can pull out values" cntr=cntr + 1 #assign x, y properties of Point object to long and lat values pnt.X = longitude pnt.Y = latitude #Create new row for feature class #assigns new Point object to "SHAPE" field and confidence value to "CONFIDENCEVALUE" field row = [pnt, confid] print "row's OK" #Insert new row to feature class cur.insertRow(row) print "Record # " + str(cntr) + " written to feature class" #release cursor lock on feature class del cur

أكثر...
 
أعلى