0

I am trying to use arcpy.mapping.ExportToJPEG to convert some raster files to jpeg format. I am new to this module. I am using the following script:

mxd = arcpy.mapping.MapDocument(r"E:/analysis/maps/new_cs_rivnat/c1_s1/53_cities.mxd")
arcpy.mapping.ExportToJPEG(mxd, r"E:/analysis/maps/new_cs_rivnat/c1_s1/test.jpg")

In the 53_cities.mxd, there are 12 raster files and I want to convert all these, How can I do that? This script only converts the first raster.

1 Answer 1

1

You will need to set up a loop to run over each of the rasters you want to export.

Here is one option, this uses vectors...but it could be tweaked to use a raster instead.

import arcpy
import os

mxd = arcpy.mapping.MapDocument(r"Full path to mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

for lyr in arcpy.mapping.ListLayers(mxd):   
    ext = lyr.getExtent()
    df.extent = ext
    rounded = (round(df.scale/500)*500) + 500
    df.scale = rounded
    
    #jpg_name = os.path.join("Path and name of new jpg...") an example:
    jpg_name = os.path.join(r"c:\temp",lyr.name +".jpg")

    resolution = "150"

    arcpy.mapping.ExportToJPEG(mxd,jpg_name,resolution = 200)
del mxd
del df
print ("Done")

I havent been able to test this, it is a mix and match out of a script I used to use. You might need to perform a search and zoom to, before setting the zoom extent / scale.

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.