How to use a text file (CSV) list as input as well as outputs in Model Builder

726
2
06-27-2014 12:53 PM
D__SamuelRajasekhar
New Contributor III
Hello All,

An example. I have multiple geo-referenced aerial photographs (TIFF formats) across various directories in the network. I create foot-prints shape file using FME. A sub-set (say 212 out of 2500) of these TIFFs are selected from the shape file and exported as a text file (CSV table).

I was so far using a python script ( a simple one) to re-project these TIFFs from the CSV into a different directory with the same names and extension (.tif). Will I be able to input this CSV file in a model?

Thanks,
Samuel
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
The easiest way to access CSV files is to access them as tables. Just be sure you use nice safe field names (< 10 characters, alphanumeric + "_", start with an alpha character) and the iterator tools can use them for a loop.

For output, probably the easiest way to dump CSV is using a short python function pasted inside the Calculate Value tool.
0 Kudos
D__SamuelRajasekhar
New Contributor III
below is the python script I was using:

# Location where the images will be copied to:

arcpy.env.workspace = r'R:\RhodeIsland_imagery_20130118\1951_1952_RIUTM_GeoTIFF\ArcReProject'

# Set the output projection, i.e., the zone number

with open(r'X:\Archive\Python_Scripts\UTM_19.txt', 'r') as f:
        prj = f.readlines()[0]


outPath = arcpy.env.workspace

istFiles = open(r'R:\RhodeIsland_imagery_20130118\1951_1952_RIUTM_GeoTIFF\Index\List_Files_UTM.csv', 'r')
for inputRasters in listFiles.readlines():
        inputFilenames = os.path.splitext(os.path.basename(inputRasters))[0]
        

        outPut = os.path.join(outPath,inputFilenames + ".tif")

     
        arcpy.ProjectRaster_management(inputRasters, outPut, prj)


Below is the table (the location of TIFFs):

[HTML]\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R50_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R51_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R52_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R53_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R54_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_5R55_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R1_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R10_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R11_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R12_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R13_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R14_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R15_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R16_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R2_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R3_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R4_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R5_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R6_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R7_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R8_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_7R9_Orthorect_nocollar.tif
\\gisarl01\bps_backup\May_BPS_Delivery\BPS_Delivery\WO_286_CA_Santa_Cruz_County_1956\Without_Collar\1956B_Santa_Cruz_County_Flight_CJA_8R38_Orthorect_nocollar.tif
[/HTML]

Below is the model I am trying to create:

Note that the table is not connecting to iterator (I tried other iterators too)
0 Kudos