2

I found a script to batch export geotiffs from data view and when hard coded it work well

mxd = arcpy.mapping.MapDocument("CURRENT")

res = 200 #resolution of tif
export = "S:\\6 - GIS\\For Randoms\\For Jeff\\Thunderchild Reserve\\Shapefiles\\Imagery" #folder
preFix = "image" #filename
widthcolumn = 3910 #width (number of columns)
heightrow = 1765 #height (number of rows)

df = arcpy.mapping.ListDataFrames(mxd)[0]

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.AddMessage("Exporting Map " + str(pageNum) + " of " + str(mxd.dataDrivenPages.pageCount))
  arcpy.mapping.ExportToTIFF(mxd, export + "\\" + preFix + str(pageNum) + ".tif",df,
                 df_export_width=widthcolumn,
                 df_export_height=heightrow,
                 resolution = res,
                 world_file=True,
                 tiff_compression="NONE",
                 geoTIFF_tags=True)

When I try to define my variables using the arcpy.GetParameterAsText() and set my export variable as folder in the tool box I return an error.

mxd = arcpy.mapping.MapDocument("CURRENT")

res = arcpy.GetParameterAsText(0) #resolution of tif
export = arcpy.GetParameterAsText(1) #folder save path
preFix = arcpy.GetParameterAsText(2) #filename
widthcolumn = arcpy.GetParameterAsText(3) #width (number of columns)
heightrow = arcpy.GetParameterAsText(4) #height (number of rows)

df = arcpy.mapping.ListDataFrames(mxd)[0]

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.AddMessage("Resolution = " + res)
  arcpy.AddMessage("Export Folder = " + export)
  arcpy.AddMessage("Exporting Map " + str(pageNum) + " of " +     str(mxd.dataDrivenPages.pageCount))
  arcpy.mapping.ExportToTIFF(mxd, export + "\\" + preFix + str(pageNum) + ".tif",df,
                 df_export_width=widthcolumn,
                 df_export_height=heightrow,
                 resolution = res,
                 world_file=True,
                 tiff_compression="NONE",
                 geoTIFF_tags=True)

The error message that I get is:

*Executing: BatchExportGeotiffs 300 "S:\6 - GIS\For Randoms\For Jeff\Thunderchild Reserve\Shapefiles\Imagery" image 4888 2647
Start Time: Fri Mar 03 16:19:40 2017
Running script BatchExportGeotiffs...
Resolution = 300
Export Folder = S:\6 - GIS\For Randoms\For Jeff\Thunderchild Reserve\Shapefiles\Imagery
Exporting Map 1 of 4
Failed script BatchExportGeotiffs...
Traceback (most recent call last):
  File "S:\6 - GIS\Resources\scripts\Python\BatchExportGeoTiffs.py", line 22, in <module>
    geoTIFF_tags=True)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1391, in ExportToTIFF
    layout.exportToTIFF(*args)
AttributeError: DataFrameObject: Error in parsing arguments for ExportToTIFF
Failed to execute (BatchExportGeotiffs).
Failed at Fri Mar 03 16:19:40 2017 (Elapsed Time: 0.04 seconds)*

Can anyone tell me where I'm going wrong?

0

2 Answers 2

5

The widthcolumn and heightrow variables are string and need to be type integer:

Try:

widthcolumn = int(arcpy.GetParameterAsText(3))
heightrow = int(arcpy.GetParameterAsText(4))
1

Try using

widthcolumn = arcpy.GetParameter(3)
heightrow = arcpy.GetParameter(4)

that would return the matching types.

http://pro.arcgis.com/en/pro-app/arcpy/functions/getparameter.htm

1
  • Here you are referencing ArcGIS Pro documentation when the question is about ArcGIS Desktop. In this case it probably makes no difference but wherever possible I think we should try to match the documentation to the ArcGIS architecture in use.
    – PolyGeo
    Commented Mar 7, 2017 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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