2

I have a script that works to export my pages as jpegs, but I want to add the world file to them. I don't want to have to do all the {df} args and whatnot, I just want to skip to the world file. How can I do this?

Script I currently have:

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    arcpy.mapping.ExportToJPEG(mxd, r"D:\Matt_work\jpgs" + str(pageNum) + ".jpg")
del mxd

EDIT: If I use this script:

mxd = arcpy.mapping.MapDocument("CURRENT") 
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    arcpy.mapping.ExportToJPEG(mxd, r"D:\Matt_work" + str(pageNum) + ".jpg", world_file=True)
del mxd

I get this runtime error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  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 1026, in ExportToJPEG
    layout.exportToJPEG(*args)
  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\arcobjects\mixins.py", line 568, in exportToJPEG
    return self._arc_object.exportToJPEG(*args)
TypeError: PageLayoutObject: Error in executing ExportToJPEG
  • 2
    You can't export a map as a georeferenced image, only a dataframe. This is the same as exporting manually (in data view with the "focus" on the active dataframe). Just throw a line in that says: df = arcpy.mapping.ListDataFrames(mxd, "*")[0] and then modify your ExporttoJPEG line with a reference to the df variable (arcpy.mapping.ExportToTIFF(mxd, fname, df)) – Mike May 27 '16 at 22:49
2

When exporting a Page Layout to JPG you cannot generate a world file with it - this is the same when using the Export dialog from within ArcMap (File > Export Map).

World files are not generated for page layout exports; a referenced data frame must be provided or the export will fail.

(from ExportToJPEG)

This is because a Page Layout can include a lot of other information including multiple data frames, so there is no way to determine which georeference information to export with the image.

You can export to JPG from the Data View and include the world file information, even from Data Driven Pages. To do this you do need to specify the data frame you want to export.

import arcpy

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

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    arcpy.mapping.ExportToJPEG(mxd, r"N:\GISSE\DDP\Export{}.jpg".format(pageNum), df, world_file=True)
del mxd

enter image description here

You may also like to include the Export width df_export_width and Export Height df_export_height as the default size for exported data frame images is rather small at 640x480 pixels.

arcpy.mapping.ExportToJPEG(mxd, r"N:\GISSE\DDP\Export{}.jpg".format(pageNum), df, df_export_width=1600, df_export_height=1200, world_file=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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