Batch export to GeoTIFFs for set polygon features in data frame?

4149
16
10-10-2011 02:21 PM
EdGage
by
New Contributor
I'm not a particularly savvy user, as my question will make clear, so any help is greatly appreciated!
What I'd like to do is use some sort of batch map export, whereby I could export a series of GeoTIFFs driven by a list of polygon features in a data frame. I tried playing with the functionality in data driven pages, but the only export options are from the layout view, and what I need are georeferenced images (to be batch segmented for further analysis). Any ideas how to proceed?
Thanks!
0 Kudos
16 Replies
JohnSobetzer
Frequent Contributor
If you are using 9x you can get a wonderful Arcscript called Zoom through features/bookmarks and export to graphics file.  If will produce geotiffs and other rasters from the view, and other rasters or pdfs from the layout.  I would love to run it on 10x but I can't install it.

If you are using 10x there is the possibility of using arcpy but the script that was nicely provided to me by an ESRI staffer produced odd results and it was determined there was a bug.  I don't know if the bug was in 10.1, both 10.0 and 1 or in the arcpy module.
0 Kudos
JeffBarrette
Esri Regular Contributor
Try arcpy.mapping.  Check out the help and samples at the following link:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataDrivenPages/00s300000030000000/

I made changes to Sample #1 so you can export just the data frame and I also changed it to ExportToTIFF.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\NameOfMXD.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Dataframe Name")[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
    arcpy.mapping.ExportToTiff(mxd, r"C:\Project\OutPut\Page" + str(pageNum) + ".tif", df)
del mxd
0 Kudos
JohnSobetzer
Frequent Contributor
Should this produce a geotiff?  The sample I was given provided for geotiff tags and it also required export widths and heights which seems to match up with the notion of exporting a view.  But then again it failed to properly georeference the results.

I can't seem to find any ability to control the quality & dpi of the result either in this sample.  It didn't seem to zoom to the extents either.  So I'm obviously missing something.
0 Kudos
JeffBarrette
Esri Regular Contributor
Its all in the help link I provided.  The sample does not exercise all parameters but here they are.  The help explains each one.

Syntax
ExportToTIFF (map_document, out_tiff, {data_frame}, {df_export_width}, {df_export_height}, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags})


Jeff
0 Kudos
JohnSobetzer
Frequent Contributor
That's what I thought Jeff. but I wanted to make sure.

I did some testing.  I am using the 10.1 beta.  The first script I had didn't include the line that begins with Print.  It produced geotiffs that were roughly compressed to 70% of the lengths in the E-W direction and somewhat rotated counterclockwise.  (When I first noticed this the helpful ESRI tech person indicated he was getting somewhat strange results and said he would look at it further to see if it was a bug.)

Next I added the print line and nothing seemed to change in the result but I did see a message box indicating it was exporting page 1 then page 2, ....

I used for my export width and heights numbers I got just using a straight export to geotiff at the resolution I wanted.  I wondered if the problem was in those numbers.

So I exported a layout to tif and found the widths and heights from that and then used those in the script.  I got a much better result roughly compressed to 99% of the lengths in the E-W direction with a very slight rotation.  So now in my rather arcpy ignorant mind I'm thinking this really is the key to the problem.  Would that be it?

If so my question to you is how does one determine what the widths and height parameters should be in order to get a perfect match of the geotiff to the original data?

Having said all this, I note that it is still the View that is being exported to geotiff, not the layout.  Is there a method in ArcPy to alternately export the entire Layout to georeferenced tif so that the map legend gets included?
0 Kudos
EdGage
by
New Contributor
Thank you both for your postings on the question. I ran the script and get output ok, but have the same distortion issue when importing the exported images back into the project file. I tried the approach that John posted (manually exporting a view and using the pixel dimensions as input into the {df_export_width}, {df_export_height} fields in the python script). This improved the situation, but not perfectly.
Interestingly, the results are different whether the exported files are specified with geotags or with separate world files; the former is more visibly distorted, the latter less distorted but spatially offset (all other parameters the same).
Any ideas?
Thanks!
0 Kudos
DavidRahe
New Contributor
The Bug seems to be still active.

I tried exporting GeoTIFFs via this Python script:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
   mxd.dataDrivenPages.currentPageID = pageNum
   arcpy.mapping.ExportToTIFF(mxd, r"C:\Projecs\Test\Page" + str(pageNum) + ".tif", data_frame=df, geoTIFF_tags=True)
del mxd
del df

results are not correcty georeferenced.

Maybe anybody has some further Ideas?
greetings

David
0 Kudos
AndrewMoffitt
Occasional Contributor III
Solution Found!

I found the solution to this problem from here: gis.stackexchange.com

Combining that code with the code provided in this thread, I was able to export my clipped dataframes (via datadrivenpages) to .tiff.
This code runs in the Python Command window of ArcMap

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
ar = df.extent.height / df.extent.width
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
    arcpy.mapping.ExportToTIFF(mxd,r"C:\ImageTemp\" + str(pageNum) + ".tif",df,1024,1024*ar,48,True)
0 Kudos
JohnSobetzer
Frequent Contributor
Drewsky:

Thank you!

The reasons for the prior failures made sense; it fit with the odd results I kept getting.

I should note when I tried copying and pasting the code you successfully used, I got this error: Parsing error IndentationError: expected an indented block (line 6)

So based on some earlier code I got from ESRI I indented that and subsequent lines and then added an unindented line with just these words: del mxd.  It worked.  I'd copy and paste the code into here but the lines don't indent properly and because one of them wordwraps and that seems to cause problems.  I don't know how to avoid that; it's a pain in the butt.  I'd like to be able to copy and paste code out of a text file using notebook, but that's tricky.

The upshot is that in 10.1 it produced a properly georeferenced tif, although a very low quality one given the 1024 x 1024 H & W and 48.  As you suggested the actual columns and rows were not 1024 x 1024 but 1024 x 983.  I increased them to 9306 x 9306 and 300 and got just what I wanted.

Since I wasn't the original poster I can't say answered, but great job.
0 Kudos