Select to view content in your preferred language

ExportToTif width / height calculation

3831
5
10-02-2013 05:33 AM
JosephArmbruster
Occasional Contributor
I am using arcpy to export of a dataframe to geotiff.  The dataframe contains all of the feature / raster data for a JOG sheet.  The code looks like this:

dpi = 300
output_tif = #... path to the output geotiff
path_to_mxd = # ... contains the path to the mxd of interest

mxd = arcpy.mapping.MapDocument(path_to_mxd)

# we assume basemap exists...
target_data_frame = arcpy.mapping.ListDataFrames(mxd, 'BaseMap')[0]

mxd.activeView = target_data_frame

arcpy.mapping.ExportToTIFF(
  map_document = mxd,
  out_tif = output_tif,
  data_frame = target_data_frame,
  resolution = dpi,
  world_file = True,
  color_mode = '24-BIT_TRUE_COLOR',
  tiff_compression = 'NONE',
  geoTIFF_tags=True)

After exporting, I end up with a 640x480 image.  For the content of a JOG map sheet, this is obviously not what I want.  There are two additional parameters I can provide to this function; df_export_width and df_export_height but I am not certain how they should be calculated using only the meta-data that is available via the arcpy interfaces (mapdocument, pagesize, elementsizes / etc...).  I would like to reproduce the exact-width and height values for a given DPI, the same way the "Export Map" dialog calculates it within arcmap.  The detail here is that I am using a dataframe, not a layout view.  For layout view, the formula is trivial:
- df_export_width = mxd.pageSize.width * conversion_factor * dpi
- df_export_height = mxd.pageSize.height * conversion_factor * dpi

In my case, the page units are centimters, so the conversion factor is 0.393701.  Obviously, this logic does-not make sense when using a dataframe...

So what is the formula for width and height when using a data frame?

Thank You in advance.
0 Kudos
5 Replies
MattSayler
Frequent Contributor
Looks to me like it's just based off the size of the window. If you change the size of the view, the W/H for a given DPI changes in the dialog:
[ATTACH=CONFIG]27962[/ATTACH]

[ATTACH=CONFIG]27963[/ATTACH]
0 Kudos
JosephArmbruster
Occasional Contributor
Matt - no kidding 🙂

The question is: What is the formula for the width and height when using a data frame?
0 Kudos
JeffBarrette
Esri Regular Contributor
This may be a more simple solution:  Create a page layout that is the size AND shape of the output image you want to create (with dataframe exports you can't specify page size, only pixel width/height).  On the layout you will have a single data frame with your data.  Export the layout rather than the data frame.

Here is a snippet from the help:

Controlling graphic quality of the generated image differs for page layout exports versus data frame exports. When exporting a page layout, control image detail by changing the resolution parameter. When exporting a data frame, keep the resolution parameter at its default value, and change the df_export_width and df_export_height parameters to alter image detail. The height and width parameters directly control the number of pixels generated in the export file and are only used when exporting a data frame. Images with larger numbers of pixels will have higher image detail. For most page layout exports, the default parameter values should generate good results and nice looking export images on the first try. For data frame exports, you may need to experiment with the df_export_width and df_export_height values a few times before getting the result you want.


If you have to export a data frame, then multiply the resolution (default=96) times the size (this is a general rule but results can vary from machine to machine).  For example if i want a 3 inch x 3 inch output, then my export_height and export_width will = 288 (96x3).

Jeff
0 Kudos
JosephArmbruster
Occasional Contributor
This may be a more simple solution:  Create a page layout that is the size AND shape of the output image you want to create (with dataframe exports you can't specify page size, only pixel width/height).  On the layout you will have a single data frame with your data.  Export the layout rather than the data frame.

Here is a snippet from the help:



If you have to export a data frame, then multiply the resolution (default=96) times the size (this is a general rule but results can vary from machine to machine).  For example if i want a 3 inch x 3 inch output, then my export_height and export_width will = 288 (96x3).

Jeff


This still does not answer my question.  When you say "times the size".  What "size" are you referring to?  Tell me the exact arcpy dataframe object I should use to obtain that "size" that you speak of.  This, is what my question boils down to.

Joe
0 Kudos
JeffBarrette
Esri Regular Contributor
Posting to this forum too.

That is because when the application is actually open the data frame window has a defined size.  But when you run a stand-alone script, the application isn't actually open, there is not a real point of reference and depending on your system settings, you may get different results on diferent machines.  Using a page layout that has a defined page space whether open or not, you will get consistent results.

Also - defining a page layout size and fixed dataframe size on the layout you will get consistent results.  Otherwise when you resize the TOC, the application, etc, the data frame size will be different. etc, etc,

Jeff
0 Kudos