Export Map (Data Frame) to JPEG

4460
4
02-11-2013 04:06 AM
by Anonymous User
Not applicable
Original User: Playa

I have an Index Feature Class that I want to use to export my CURRENT Data Frame to JPEG. I want to loop through each row within the Index Feature Class and for each row select the feature and use it to set the Current Extent and Scale and export the Data Frame to JPEG using the name of the selected feature (i.e. 3318BD07) I've attached my code so far, but its not passing the current row as new selection. Any assistance to update my code to accomplish the following will be appreciated.

>>> import arcpy,os
>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
>>> index10k = arcpy.mapping.ListLayers(mxd, "Index10k_wgs84",df)[0]
>>> rows = arcpy.SearchCursor(index10k,"","","TAG","")
>>> for row in rows:
...     df.extent = index10k.getSelectedExtent(False)
...     df.scale = df.scale*1.1
...     arcpy.mapping.ExportToJPEG(mxd, os.path.join(r'S:\Projects\01_Rebieeck_West\jpeg',row.getValue("TAG)+".jpg"),df)


Regads
0 Kudos
4 Replies
GeorgeNewbury
Occasional Contributor
You're not selecting anything. When you put the search cursor in, that's basically going through row by row and giving you access to the item in the row, but it doesn't actually 'select' the row. At a high level when you go through each row you want to:

1. Get the row's geometry from the shape field.
2. Get the extent of the geometry
3. Set the dataframe to that extent (and maybe refresh the active view).
4. Export the dataframe.

Hope this gets you in the right direction.

George
0 Kudos
by Anonymous User
Not applicable
Original User: JSkinn3

George is correct in that you will just need to set the data frame extent to the individual features extent when you are using the Search Cursor.  Here is an example:

import arcpy,os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
index10k = arcpy.mapping.ListLayers(mxd, "Index10k_wgs84",df)[0]
rows = arcpy.SearchCursor(index10k)
for row in rows:
     geom = row.shape
     df.extent = geom.extent
     df.scale = df.scale*1.1
     arcpy.mapping.ExportToJPEG(mxd, os.path.join(r'S:\Projects\01_Rebieeck_West\jpeg',row.getValue("TAG")+".jpg"),df)
0 Kudos
PeterWilson
Occasional Contributor III
Hi Jake

Your example put me onto the right track. I've attached my final script that I used.

Question: I created a Fishnet using the Data Driven Pages using the extent of my study area and defining the page size of an A1 map. I used this feature class to loop through each features extent to export the data frame to a jpeg. The Fishnet features are based on a scale of 1:5 000 in the data frame and 1:2 000 in the Layout View. It seams that my exported jpeg's are based on the scale from the Layout View and not the Data Frame scale?

import os,arcpy
... mxd = arcpy.mapping.MapDocument(r'E:\Projects\Rebieeck_West\mxd\Rebieeck.mxd')
... df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
... lyr = arcpy.mapping.ListLayers(mxd,"Fishnet")[0]
... sCur = arcpy.SearchCursor(lyr)
... for row in sCur:
...     geom = row.shape
...     df.extent = geom.extent
...     df.scale = df.scale * 1.1
...     arcpy.mapping.ExportToJPEG(mxd,os.path.join(r'E:\Projects\Rebieeck_West\jpeg',row.getValue("PageName")+".jpg"),df,df_export_width=817,df_export_height=571,world_file=True)


Regards
0 Kudos
by Anonymous User
Not applicable
Original User: jencarta

Hi Peter,

I see your last post was a few months ago, but I was playing around with some code today trying to do the same thing as you. I discovered something. Because the data frame extent coordinates are based on the extent of the data frame in Layout View, not in Data View, you cannot set both extent and scale and have them both "stick" without changing the data frame size accordingly. I would guess this could be handled as well with some sort of calculation of what the data frame size should be based on extent and scale. Obviously, the page size would have to be big enough to handle whatever the data frame size would be.

In my case, I have index quads as features that I want to use the extents of to set the extent of the data frame. However, the scale must remain at 1:50,000 always. Because the quads are projected, they vary in size, although minimally (but enough to create problems!)

I have not yet solved the problem. I looked into data driven pages, but that won't help because size and position of data frame are static elements as mentioned on this page: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00sr00000006000000

Perhaps I will post a question to the forum about this! If I get a solution, I will post it here.

Jennifer
0 Kudos