Select to view content in your preferred language

Exporting multiple maps as images at a time,

5157
12
Jump to solution
05-17-2013 05:07 AM
JamalNUMAN
Legendary Contributor
Exporting multiple maps as images at a time,

I wanted to export 12 maps at a time such that only 2 layers are turned on: the layer of lines and one of the buildings. The layer of buildings contains 12 fields and each field represent one property like: date of construction, number of floors, using, etc.

[ATTACH=CONFIG]24421[/ATTACH]


Is there such python? For the time being I do this work manually!

Thank you

Best

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
Tags (2)
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Ok, I made it into a script tool for you. You can open this up inside the current map and run it from the toolbox like any other tool.  It takes one parameter, which will be the output folder for all your .jpg files.  I tested this on the UntitledII.mxd and it worked fine.

View solution in original post

0 Kudos
12 Replies
by Anonymous User
Not applicable
Yes, this can be done with Python.  I did a simple test where I just had 12 building layers and roads were my lines and turned off all buildings layers.  I numbered them like Building1, Building2, etc. In your case you may want to give the layers a more descriptive name.  I used a wildcard to search for all layers that start with 'Buildings*' and looped through to turn only that layer on (lines layer is always on).  I am assuming your properties you want to show are set up as a label? 

import arcpy, os
from arcpy import mapping as m
arcpy.env.overwriteOutput = True

mapPath = r'C:\Users\GIS\Desktop\maptest.mxd'
outpath = r'C:\Users\GIS\Desktop\Exports'

mxd = m.MapDocument(mapPath)
df = m.ListDataFrames(mxd)[0]

# Loop through layers
for lyr in m.ListLayers(mxd, 'Buildings*'):
    lyr.visible = True
    lyr.showLabels = True # I'm assuming this is where you have the properties?
    jpg = os.path.join(outpath, lyr.name + '.jpg')
    m.ExportToJPEG(mxd, jpg)
    print 'Exported %s' %jpg
    lyr.visible = False
        
del mxd


You could get a lot more fancy with this, but this should get you started in the right direction.  Since you are at 10.1, you have more control over the legend and you can turn on/off the auto-add feature to add the current layer inside the loop to the legend.

Here is a shot of my map and the folder with all the output jpgs.
[ATTACH=CONFIG]24423[/ATTACH][ATTACH=CONFIG]24424[/ATTACH]
0 Kudos
JamalNUMAN
Legendary Contributor
Yes, this can be done with Python.  I did a simple test where I just had 12 building layers and roads were my lines and turned off all buildings layers.  I numbered them like Building1, Building2, etc. In your case you may want to give the layers a more descriptive name.  I used a wildcard to search for all layers that start with 'Buildings*' and looped through to turn only that layer on (lines layer is always on).  I am assuming your properties you want to show are set up as a label? 

import arcpy, os
from arcpy import mapping as m
arcpy.env.overwriteOutput = True

mapPath = r'C:\Users\GIS\Desktop\maptest.mxd'
outpath = r'C:\Users\GIS\Desktop\Exports'

mxd = m.MapDocument(mapPath)
df = m.ListDataFrames(mxd)[0]

# Loop through layers
for lyr in m.ListLayers(mxd, 'Buildings*'):
    lyr.visible = True
    lyr.showLabels = True # I'm assuming this is where you have the properties?
    jpg = os.path.join(outpath, lyr.name + '.jpg')
    m.ExportToJPEG(mxd, jpg)
    print 'Exported %s' %jpg
    lyr.visible = False
        
del mxd


You could get a lot more fancy with this, but this should get you started in the right direction.  Since you are at 10.1, you have more control over the legend and you can turn on/off the auto-add feature to add the current layer inside the loop to the legend.

Here is a shot of my map and the folder with all the output jpgs.
[ATTACH=CONFIG]24423[/ATTACH][ATTACH=CONFIG]24424[/ATTACH]



Very much appreciated Caleb,

With my little experience in playing with codes, I couldn�??t figure out how to stich the code in a �??script tool�?� such that the inputs\outputs can be filled by a dialogue box.

[ATTACH=CONFIG]24426[/ATTACH]

Or even I couldn�??t know how to run the code!

The data is attached

Best

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
by Anonymous User
Not applicable
Ok, I made it into a script tool for you. You can open this up inside the current map and run it from the toolbox like any other tool.  It takes one parameter, which will be the output folder for all your .jpg files.  I tested this on the UntitledII.mxd and it worked fine.
0 Kudos
JamalNUMAN
Legendary Contributor
Ok, I made it into a script tool for you. You can open this up inside the current map and run it from the toolbox like any other tool.  It takes one parameter, which will be the output folder for all your .jpg files.  I tested this on the UntitledII.mxd and it worked fine.


Fantastic! It worked fine. This will be saving much of my time. Thank you so much for the crucial development.

I�??m not sure if this code can be further developed such that

1. it generates copies of the �??Building�?� such that a copy for each field (except the built in fields) is added

[ATTACH=CONFIG]24439[/ATTACH]

2. these copies are symbolized according to their corresponding fields such that the copy which has been generated based on the �??stage�?� field, for example, is also classified based on this field (stage).

[ATTACH=CONFIG]24440[/ATTACH]

I know that this might require massive effort and time to be done! However, the one you have already developed is great.

I could do the above mentioned steps manually unless you are still willing to offer help.

Best

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
JamalNUMAN
Legendary Contributor
Ok, I made it into a script tool for you. You can open this up inside the current map and run it from the toolbox like any other tool.  It takes one parameter, which will be the output folder for all your .jpg files.  I tested this on the UntitledII.mxd and it worked fine.


Hi Caleb,

Is there a way to make your fantastic script tool more generic?

I wanted the end user to have the option to choose which layers that should be kept turned on and which layers that to be turned on/off  while creating the images.



For example, in the screenshot below, I need to keep the �??governorates�?� layer turned on with only one of other layers! In this case six images are expected to be exported

[ATTACH=CONFIG]24450[/ATTACH]


Thank you

Best

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
by Anonymous User
Not applicable
Hi Jamal,

I was able to alter the tool to do what you wanted, however, every time I run it ArcMap freezes after it is complete.  It properly exports all the jpgs but then I have to force close ArcMap afterwards.  I do not really know what is going on with that, I could not figure out what is causing the issue.  I played around with deleting the mxd object, refreshing the active view and a few others but same result every time, I don't know why.  See if you can reproduce this issue.  Here is the tool, hopefully it will work without freezing ArcMap for you.

If anyone else tests this out (v 10.1 tool) and can figure out why it might be crashing ArcMap I would love to know!
0 Kudos
ganeshnarim
Emerging Contributor
Ok, I made it into a script tool for you. You can open this up inside the current map and run it from the toolbox like any other tool.  It takes one parameter, which will be the output folder for all your .jpg files.  I tested this on the UntitledII.mxd and it worked fine.


Hi,

I wanted to use your tool in my project but when i'm trying to run it's end up with the below error. i missed something..???
I'm using Arcmap 9.3.1..

Executing: Script2
Start Time: Sun May 19 12:00:47 2013
Running script Script2...
<type 'exceptions.SyntaxError'>: invalid syntax (<string>, line 26)
Failed to execute (Script2).
End Time: Sun May 19 12:00:47 2013 (Elapsed Time: 0.00 seconds)


Can you please guide me step by step.. because i'm very new to python programming...i wanted to learn it by doing...please help me..!!

Thanks..
0 Kudos
JamalNUMAN
Legendary Contributor
Hi Jamal,

I was able to alter the tool to do what you wanted, however, every time I run it ArcMap freezes after it is complete.  It properly exports all the jpgs but then I have to force close ArcMap afterwards.  I do not really know what is going on with that, I could not figure out what is causing the issue.  I played around with deleting the mxd object, refreshing the active view and a few others but same result every time, I don't know why.  See if you can reproduce this issue.  Here is the tool, hopefully it will work without freezing ArcMap for you.

If anyone else tests this out (v 10.1 tool) and can figure out why it might be crashing ArcMap I would love to know!


Perfect�?�Perfect�?�Perfect! It worked like a charm. I�??m very thankful to your help and massive effort.

The ArcGIS 10.1 didn�??t crash

[ATTACH=CONFIG]24480[/ATTACH]

Cheers

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
JamalNUMAN
Legendary Contributor
Hi,

I wanted to use your tool in my project but when i'm trying to run it's end up with the below error. i missed something..???
I'm using Arcmap 9.3.1..

Executing: Script2
Start Time: Sun May 19 12:00:47 2013
Running script Script2...
<type 'exceptions.SyntaxError'>: invalid syntax (<string>, line 26)
Failed to execute (Script2).
End Time: Sun May 19 12:00:47 2013 (Elapsed Time: 0.00 seconds)


Can you please guide me step by step.. because i'm very new to python programming...i wanted to learn it by doing...please help me..!!

Thanks..



Hi ganesh,

It worked fine in ArcGIS 10.1. There should be some issues related to your version


Cheers

Jamal
----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos