Select to view content in your preferred language

Autom. production of several maps with same extent but different content (layers)

879
3
03-08-2013 01:55 AM
AdrianRingenbach1
Occasional Contributor
Hi there,

I'm trying to automate the map production of several rockfall-model outputs: I have got different rasterlayers (e.g. rockenergy, reach probability, passing height, ...)  from different model scenarios (e.g. without forest, with forest, with forest gaps, ...). All with the same name in different grouplayers. All thogether there are more than 200 .asc rasters, that i want to get out of the GIS on to the paper. Unfortuately i haven't found an "out of the box" tool, so i began with my poor knowledge of python and the arcpy.mapper. Beneth is my result so far

# ---------------------------------------------------------------------------
# map_production.py
# 
# Description: "Should" generate jpg layout outputs of the input layernames
# ---------------------------------------------------------------------------

print "START map production"

print "arcpy importieren"
import arcpy
print "done arcpy import"


print "mxd spezifizieren"
#Specifies mxd  
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Schmitten_Neu_6.mxd")
print "done mxd spezifizieren"

print "dataframe spezifizieren"
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
print "done df spezifizieren"

#Turns all layers off
"alle Layer unsichtbar machen"
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
   lyr.visible = False
   arcpy.RefreshTOC()
   arcpy.RefreshActiveView()
   
"alle Layer unsichtbar gemacht"

#Turns backgroundlayers on
"Hintergrundlayer sichtbar machen"
for lyr in arcpy.mapping.ListLayers(mxd, "hillshade*", df):
   lyr.visible = True
   arcpy.RefreshTOC()
   arcpy.RefreshActiveView()


print "start E_95CI"
#Loops through the layers given in the quotas (eg. beginning with E_95CI) and creates a list of Layers:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
    #For Each: Turn it on:
   lyr.visible= True
   arcpy.RefreshTOC()
   arcpy.RefreshActiveView()
   arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/e95_cl_jpg.test.jpg")
   
print "done_ 1"


#print "start reach_probability"
##Loops through the layers given in the quotas (eg. reach_probability) and creates a list of Layers:
#for lyr in arcpy.mapping.ListLayers(mxd, "reach_probability", df):
    #For Each: Turn it on:
#   lyr.visible= True
#   arcpy.RefreshTOC()
#   arcpy.RefreshActiveView()
#   arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/e95_cl_jpg.test.jpg")



#print"done_2"


#Saves mxd
mxd.save()

print "done_ 20"




#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd



One main problem is, that after one exportet .jpg-map, the second would overwrite the first, which produces an error. How can i get an variable .jpg-output name? It would be perfect, when the name would differ by the name of the group-layer.

The next one is, that there is nothing visible in the jpg. output beside the northarrow and scalebar. Not even the Background :S

Does someone see my faults?

Or does someone know an already existing tool for my problem :cool: ?

Thanks a lot!
0 Kudos
3 Replies
KamrulKashem
Deactivated User
Hi,

Try not to use the mxd.save() function. Take this out - it never seems to work for me and corrupts my outputs too.

Secondly, you need to change the parameters of the ExportToJPEG

arcpy.mapping.ExportToPDF(map_document=mxd,out_pdf=os.path.join(r"H://Desktop", str(X)),resolution = '600')

Where X = name of what you want the outputs to be...

Hope this helps.. It's quite hard to fully understand without english comments, sorry
0 Kudos
AdrianRingenbach1
Occasional Contributor
I tried your, kamkashem, proposed version. After importing "os", one error message disappeared :D. But the problem of over writing each output ("str(X)") with the next one is not solved yet. So, How can i accomplish that str(x) is something like Str(Xi) for i=1...80     Or even nicer i = name of group layer.

Because the jpeg format is more sympathetic to me, i inspired me also from this thread: http://forums.arcgis.com/threads/63173-Problem-accessing-ModelBuilder-variable-in-a-python-script (especially the record from  07-27-2012 08:40 PM ).

my actual piece of code is the following:
# ---------------------------------------------------------------------------
# map_production.py
# 
# Description: "Should" generate jpg layout outputs of the input layernames
# ---------------------------------------------------------------------------

print "START map production"

print "arcpy and os importieren"
import arcpy
import os, sys, string, arcgisscripting
print "done arcpy and os and so on import"


gp = arcgisscripting.create(9.3)
scriptVar=gp.GetParameterAsText(0)
outfile = "test" + scriptVar +".jpg"


print "specify mxd"
#Specifies mxd  
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Schmitten_Neu_6.mxd")
print "done mxd spezifizieren"

print "specify dataframe"
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
print "done specify df "

#Turns all layers off
print "turn visibility of all layers off"
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
   lyr.visible = False
   arcpy.RefreshTOC()
   arcpy.RefreshActiveView()
   
print "visibility = False  "

#Turns backgroundlayers on
print "turn backgroundlayer on: Visibility = true"

for lyr in arcpy.mapping.ListLayers(mxd, "hillshade*", df):
   lyr.visible = True
   arcpy.RefreshTOC()
   arcpy.RefreshActiveView()
print "background = visible"

print "start withE_95CI"
#Loops through the layers given in the quotas (eg. beginning with E_95CI) and creates a list of Layers:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
    print" produced list"
    #For Each: Turn it on:
    lyr.visible = True
    print " visible: on"
    arcpy.RefreshTOC()
    print " TOC refreshed"
    arcpy.RefreshActiveView()
    print " Active View refreshed"
    print "exporting for each layer starting with ""E_95CI"" a JPEG map within the folder map_export and the name construction ""outfile"" "
    arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/map_export/" + outfile, df,df_export_width=1600, df_export_height=1200)
print "done_"



mxd.save()

print "done_ 20"

#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd



While it is possible to generate a the list E_95CI, the export to jpeg fails.
The python Shell output looks like this:
START map production
arcpy and os importieren
done arcpy and os and so on import
specify mxd
done mxd spezifizieren
specify dataframe
done specify df 
turn visibility of all layers off
visibility = False  
turn backgroundlayer on: Visibility = true
background = visible
start withE_95CI
 produced list
 visible: on
 TOC refreshed
 Active View refreshed
exporting for each layer starting with E_95CI a JPEG map within the folder map_export and the name construction outfile 

Traceback (most recent call last):
  File "H:\Desktop\Masterarbeit\Python scripts\test2.py", line 60, in <module>
    arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/map_export/" + outfile, df,df_export_width=1600, df_export_height=1200)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 686, in ExportToJPEG
    layout.exportToJPEG(*args)
AttributeError: DataFrameObject: Error in executing ExportToJPEG


Does anyone see a pissible solution? I am very happy to every answer!
0 Kudos
JeffBarrette
Esri Regular Contributor
I changed two things.  First, it looks odd to see you using arcpy and arcgisscripting(9.3) so I changed the first few lines to:

import arcpy, os, sys, string
scriptVar = arcpy.GetParameterAsText(0)


Second, I think the issue is your double forward quotes and single forward quote at the end of the string.

Try changing:

arcpy.mapping.ExportToJPEG(mxd, r"H://Desktop/map_export/" + outfile ... 


to

arcpy.mapping.ExportToJPEG(mxd, "H:\\Desktop\\map_export\\" + outfile ...


In Python you can have:

r"C:\Temp\file" or
"C:\\Temp\\file" or
"C:/Temp/file

I also found single slashes at the very end of a quote don't work all the time.

Jeff
0 Kudos