Create multiple Mxd and export it to JPEG using ArcPy

2494
6
07-01-2017 09:44 PM
ShouvikJha
Occasional Contributor III

Hi All, 

I am working on daily rainfall data. I have multiple rasters map for different dates. I want to convert those map into JPEG format along with all layouts (Title, Legend, North arrow, scalebar etc). Already i made a map by manually which i attached below with my sample datasets.

I have numbers of datasets for different dates, therefore, i want to do it using Arcpy to create the different date wise map and export it to JPEG format. How to do it in ArcPy environment. 

I have one script but that is for converting multiple mxd to JPEG, but to create automatically mxd files along with all layouts based on multiple date wise rasters and then export it to JPEG, I am getting trouble to make it. 

I have attached below my sample datasets which I am working. One output map also attached with the sample data sets, which I made by manually. But instead of manually i just take the whole part in ArcPy. 

Thank you in advance. 

import arcpy, os

 folderPath = r"D:\data\sample_data"  
 for filename in os.listdir(folderPath):  
 fullpath = os.path.join(folderPath, filename)  
 if os.path.isfile(fullpath):  
    basename, extension = os.path.splitext(fullpath)  
    if extension.lower() == ".mxd":  
        mxd = arcpy.mapping.MapDocument(fullpath)  
        arcpy.mapping.ExportToJPEG(mxd, basename + '.jpg', resolution = 300)
0 Kudos
6 Replies
ModyBuchbinder
Esri Regular Contributor

Hi

I am not sure I understand but why not using Updating and fixing data sources with arcpy.mapping—Help | ArcGIS for Desktop  to change the MXD with new raster, save it to temporary mxd and export it to JPEG?

Have Fun

Mody

0 Kudos
ShouvikJha
Occasional Contributor III

Thanks. But i don't understand how to replace the rasters into mxd and then export. If i get likely structure the code, it would be useful to solve the issue. 

0 Kudos
ShouvikJha
Occasional Contributor III

it would be possible like this way, If I create one mxd file, with all layouts which I require in maps, can I do loop function for other rasters, So another raster just will add the existing mxd file through loop function and will follow the existing symbology and export it to JPG  

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Something like this:

 mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
# get layer raster1
lyr = arcpy.mapping.ListLayers(mxd, "raster1", df)[0]
#replace to layer raster2
lyr.replaceDataSource(r"C:\Project\Data", "RASTER_WORKSPACE", "raster2")
mxd.save()
# export to JPEG
ShouvikJha
Occasional Contributor III

Buchbinder   I don't understand the structure of script which you posted. If you could brief it will be most useful.

Already I have  made a Mxd file, that mxd file hold almost all information regarding single day of rainfall raster map, 

Now i just want to perform a loop function which will take one by one raster from a folder and follow the same symbology of existing mxd then export it to jpg format. And based on image date, the title of the map (where I mentioned the date), that will also be changed. 

I have attached sample data which I am working on. If you open this file hope you will get more clarity about the work

Thank you  

0 Kudos
ShouvikJha
Occasional Contributor III

please guide us, how to do it ?

0 Kudos