ExporttoJPEG - can't change resolution, always resets to default

1923
7
09-04-2018 07:25 AM
TheodoreF
Occasional Contributor II

ArcGIS Pro (latest)

Using the ExportToJPEG (or even ExportToPNG) arcpy function, I can't seem to export an image with my desired resolution. It always defaults to 96 dpi even when I specify 500. What am I doing wrong? Is this a bug?

p = arcpy.mp.ArcGISProject("CURRENT")
print ("project loaded")
l = p.listLayouts("MyLayout")[0]
print ("layouts listed")
if not l.mapSeries is None:
 ms = l.mapSeries
 if ms.enabled:
   for pageNum in range(1, ms.pageCount + 1):
     ms.currentPageNumber = pageNum
     print("Exporting page {0} of {1}".format(str(ms.currentPageNumber), str(ms.pageCount)))
     l.exportToJPEG(r"C:\\Users\\Theo\\Dropbox\\site_plans\\Current_GR_site_plans\\GR2-GroundMovement-SP-_{0}".format(str(ms.currentPageNumber) + ".jpg", 500))‍‍‍‍‍‍‍‍‍‍‍

You can see at the end I specify 500 as the resolution. Even when I write- resolution = 500, it's the same. My images aren't coming out in my desired quality.

If I export a single page using the share ribbon, setting the dpi to 500, it works. But I'm automating this, so that's not a viable option for me.

Guides used:

MapFrame—ArcPy | ArcGIS Desktop 

Layout—ArcPy | ArcGIS Desktop 

similar issue to:

ExportToJpeg Resolution Problem 

but i don't understand the answers given.

7 Replies
DanPatterson_Retired
MVP Emeritus

since they all support an output resolution, have you tried another format (eg png) to see if the resolution of the layout works?

0 Kudos
XanderBakker
Esri Esteemed Contributor

I just took a simplified part of your code (leaving out the map series) and ran that against a project I have:

p = arcpy.mp.ArcGISProject("CURRENT")
l = p.listLayouts()[0]
l.exportToJPEG(r"C:\GeoNet\test500.jpg", 500)

The result came out correctly with 500 dpi and is exactly the same as a manual export at 500 dpi. Makes me wonder if this might be data related or something to do with the map series you configured.

I am running 2.2.1. There is an update (2.2.2) coming out today (?)  with a list of fixes

Release notes for ArcGIS Pro 2.2—ArcGIS Pro | ArcGIS Desktop 

... but I don't see anything related to the issue you are encountering. 

Might be good to contact Esri Support and work through this issue directly with them.

TheodoreF
Occasional Contributor II

Hi Xander,

Yes I've raised a support call with ESRI so we'll see what they say.

Interesting that you made it work with that smaller snippet. I'll try run the snippet too.

It must be something elsewhere in the script... Maybe it only works on Current layouts? Maybe it doesn't work with Map Series? That must be a glitch then...

I'm going to need to run the code outside of ArcGIS Pro, referencing a named layout and a named .aprx file. Whilst using map series.

0 Kudos
TheodoreF
Occasional Contributor II

The issue remains even when using ExportToPNG, ExportToTIFF etc.

0 Kudos
TheodoreF
Occasional Contributor II

Fixed it. It appears there was a closing bracket in the wrong place on the final line:

p = arcpy.mp.ArcGISProject("CURRENT")
print ("project loaded")
l = p.listLayouts("MyLayout")[0]
print ("layouts listed")
if not l.mapSeries is None:
 ms = l.mapSeries
 if ms.enabled:
   for pageNum in range(1, ms.pageCount + 1):
     ms.currentPageNumber = pageNum
     print("Exporting page {0} of {1}".format(str(ms.currentPageNumber), str(ms.pageCount)))
     l.exportToJPEG(r"C:\\Users\\Theo\\Dropbox\\site_plans\\Current_GR_site_plans\\GR2-GroundMovement-SP-_{0}".format(str(ms.currentPageNumber)) + ".jpg", 500)
XanderBakker
Esri Esteemed Contributor

Glad you resolved it. 

0 Kudos
TheodoreF
Occasional Contributor II

problem is, there error stems from incorrect syntax in an official ESRI documentation article..

See the final line of code in example 2 here:

MapSeries—ArcPy | ArcGIS Desktop 

      l.exportToPNG(relpath + "\\Output\\Ex2_{0}".format(ms.pageRow.STATE_NAME + ".png"))
should be
      l.exportToPNG(relpath + "\\Output\\Ex2_{0}".format(ms.pageRow.STATE_NAME) + ".png")