Original User: mzcoyleThis should get you started. You will want to create a script or function to create a template feature class if one does not exist, depending on if you want to make that a part of the code or as a separate process. The rest of the steps are pretty straight forward. You can create a list or dictionary of words and test against the list to see if they match.import csv
import os
import arcpy
def main(input_csv, output_shapefile):
workspace = r"C:\temp\py_temp"
arcpy.env.workspace = workspace
shapefile = r"C:\temp\py_temp\import_template.shp"
out_path = workspace
out_name = output_shapefile
geometry = "POINT"
template = shapefile
arcpy.CreateFeatureclass_management(out_path, out_name, geometry, template)
i_curs = arcpy.InsertCursor(out_name)
with open(input_csv, "rb") as csvfile:
open_reader = csv.reader(csvfile, delimiter=',')
for blank, id, Name, DBH, Staff, Longitude, Latitude in open_reader:
i_row = i_curs.newRow()
i_row.ID = id
Name = Name.capitalize()
i_row.Name = Name
i_row.DBH = DBH
i_row.Staff = Staff
i_row.Longitude = Longitude
i_row.Latitude = Latitude
i_curs.insertRow(i_row)
del open_reader
del i_curs
del i_row
print "done"
if __name__ == '__main__':
csv_file = r"C:\temp\py_temp\SB.txt"
shp_name = "shapefile2.shp"
main(csv_file, shp_name)
Edit: Here is a very simple name check test. This simply assumes if the first letter matches the first letter in the list of tree types then that is the one to use. If you eventually have a list of tree types that have the same first letter you may want to make this more robust.
name_list = ["Ash", "Dogwood", "Hickory", "Maple", "Oak"]
...
Name = Name.capitalize()
if Name not in name_list:
for name_proper in name_list:
if Name.startswith(name_proper[0]):
Name = name_proper
i_row.Name = Name