-1

I have 1000s of tif rasters of land cover (at the county level) that I would like to process in fragstats, and would like to use batch processing. The Fragstats help file is basically useless.

Is there an automated way to set up a batch file for use in Fragstats?

I am using ArcGIS Desktop 10.5.

  • Did you find an answer to the question? – trecia Oct 24 '17 at 12:54
1

The main FRAGSTATS documentation has a section on the necessary format of the batch file, also in the tutorials package there is an entire section on batch processing, so I wouldn't really call it useless.

Each line of the batch file contains the path to the file, and attributes about the raster. Since you are using GeoTIFFs most of these attributes can be read automatically by FRAGSTATS. So really you just need to get a list of your rasters and output the paths to a text file. This becomes a fairly simple task in Python.

import arcpy
from arcpy import env

#Set workspace to folder containing GeoTIFFs
env.workspace = "Q:/Temp/Files"
#List all GeoTIFF datasets in workspace folder
fllst = arcpy.ListRasters("*", "TIF")
#Set the output path for batch file
txt_path = os.path.join(env.workspace, "geotiffbatch.fbt")
#Open batch file for writing
txt_file = open(txt_path, "w")
for fl in fllst:
    #Construct path string to dataset
    pth = os.path.join(env.workspace, fl)
    #Construct string formatted for batch file
    outStr = pth + ", x, 999, x, x, 1, x, IDF_GeoTIFF\n"
    #Write string to batch file
    txt_file.write(outStr)

#Close batch file    
txt_file.close()

The batch file is ready to read in FRAGSTATS where you can then setup the metrics and output location. I would recommend looking at the tutorial package linked above for more information.

If the files were Ascii grids or other formats that FRAGSTATS will not automatically read the attributes of you could use arcpy.Describe() to get the raster attributes necessary.

  • Thank you very much! As a python illiterate, I still do not know by what to replace the "x" in : outStr = pth + ", x, 999, x, x, 1, x, IDF_GeoTIFF\n". Would you know how to have the number of rows an columns written in the text file in place of those "x"? – LandryF Aug 29 '18 at 18:16
  • This depends on what your raster format is. In this case it is a GeoTIFF which FRAGSTATS will read that information from the header of the file. This is also the case for several other raster formats that can be read by FRAGSTATS. You would only need to change those if you were using an ASCII grid or something similar. – Jacob F Aug 29 '18 at 18:44
  • You are absolutely right. This code works perfect as it is, thanks! – LandryF Aug 30 '18 at 14:35

protected by Community Apr 5 at 23:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.