ExportToJpeg Resolution Problem

2399
8
09-08-2017 11:07 AM
StevenOliver
New Contributor II

Im still pretty new to Python, pretty much an infant. I put together a script for bulk exporting DDP to .jpg with world file, and it works fine, except for one problem. the resolution only exports at the default, 96 dpi. When I put an interger in the resolution, it doesnt change from 96 dpi.I would like it to be a little higher. Everything I have seen in others scripts, it seems to work fine and it matches the syntax of ExportToJpeg? I have checked over many options from different answers, including making it a constant, different spacing, etc., etc. My question is what am I missing? 

The script is as follows:

...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"C:\Insert\File\Path\Here\{}.jpg".format(pageNum), df, df_export_width=1600, df_export_height=1200, resolution=300, world_file=True)
del mxd

Thanks for any help!

0 Kudos
8 Replies
RandyBurton
MVP Regular Contributor

Try the command without giving a width and height.  I think if you use just "resolution=300" then the height and width will be calculated for you.

0 Kudos
StevenOliver
New Contributor II

Unfortunately I had already tried that. That was actually what I was thinking was wrong. The 1600 x1200 parameters for height and width do not matter. I just did that for the sake of some legibility when zooming on the jpeg. I am trying to work within a set end file size of all exported jpegs in mind. I thought that a higher resolution would help me achieve that.  Eventually these images will get stitched into one for an offline map, and I can make the 1600x1200 work for my purpose (maybe), I would just like help understanding why it is not, so I can grow my python "skills" (I say that loosely) and understanding even more.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

On my py... links blog, I maintain a link to issues addressed... sometimes there is a quiet announcement of things that get 'fixed' along the way... so unless you are working with 10.5.1, you might want to have a troll to see if something was noted and address in the past.  Here is the one for 10.5.1 Step back in time for other versions from the link

0 Kudos
StevenOliver
New Contributor II

A link to your blog post was one of the first I came across on my search for answers actually. I bookmarked it for future use, because I am sure it will come in handy...... many more times than once.

Thanks for posting that blog, it really does help!

RandyBurton
MVP Regular Contributor

In your code, you are setting:

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

Then you are referencing it in the export code.  This is accessing the frame in "Data View"  which uses your screen's resolution.   Without a data frame reference, the export code will default to "PAGE_LAYOUT" (or "Layout View") which will allow you to set the resolution.  I tested the following code in ArcMap 10.5 at resolutions of 150 and 300.

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.mapping.ExportToJPEG(mxd, r"C:\Path\To\Page" + str(pageNum) + ".jpg", resolution=300)
del mxd
‍‍‍‍‍

ExportToJPEG

Exporting Data Driven Pages

0 Kudos
StevenOliver
New Contributor II

That actually makes perfect sense. Thanks! I had thought about a code similar to the one you wrote, not exactly, but decided to go with the one I originally posted. I don't know why really, I guess I thought it would be simpler and cause less headache. We see how that turned out. Anyway, I will try it tomorrow morning and see how it works out. It looks like just the ticket. I sure do appreciate the help.

0 Kudos
JeffHanson2
New Contributor III

I had the same issue but just fixed it by changing df/dataframe to "PAGE_LAYOUT" in the ExportToJPEG function.   Works like a charm.

JeffHanson2
New Contributor III
arcpy.mapping.ExportToJPEG(mapDoc, OutputFileJPG, "PAGE_LAYOUT", df_export_height=1200, df_export_width=2250, resolution=300)
0 Kudos