1

I am trying to export rasters stored in a raster field in a gdb feature class to thumbnail-sized jpg with arcpy. The reason is so that I can attach them to the feature class to be displayed in a popup in ArcGIS online.

If I click on the raster field in ArcMap, the thumbnails are shown, but I am not sure how to export them with arcpy.

Desired thumbnail

I have considered copying the raster to jpg, but what I really want is a down-sampled jpg (ideally less than 1mb each). I could use ExportToJPG, but then I would need to set up an mxd.


The @FelixIP suggestion to resample works well to create thumbnails. Here is a functional snipped to create thumbnails, and add the URL and thumbnail name to a table that could be used to show the thumbnail in AGOL.

#Export Raster to Thumbnail Tif

import os
import arcpy
from arcpy import env

rcat = "location of an unmanaged raster catalog"
pathsName = "name of output location of a table of raster paths"

#Export raster catalog paths to dbf table
arcpy.ExportRasterCatalogPaths_management(rCat, "ALL", pathsName)

# Add fields to store some useful fields to help manage thumbnail paths
arcpy.AddField_management(pathsName, "thumbURL", "TEXT", field_length=500)
arcpy.AddField_management(pathsName, "rasName", "TEXT", field_length=100)

#Use data access cursor to loop through table and create thumbnails
with arcpy.da.UpdateCursor(pathsName, seColumns) as cursor:
    for row in cursor:
        #Assign the raster path to a variable from the table
        rasPath = str(row[1])

        #assign input raster name to a variable
        inName = arcpy.Describe(rasPath).name

        #Create a URL for the thumbnail to be stored later 
        tURL = "web server location" + inName + ".png"

        #Write thumbnail URL and raster name
        row[2] = tURL
        row[3] = inName
        #update the rows
        cursor.updateRow(row)

        #Create thumbnail to send to web
        outThumbLoc = 'tumbnail storage folder'

        #Create thumbnail name
        outThumb = os.path.join(outThumbLoc, inName + ".png")

        #Use resample to create thumbnails
        try:
            arcpy.Resample_management(rasPath, outThumb, tScale, "BILINEAR")
        except Exception as err:
            print rasPath
            print(err.args[0])
3
  • 1
    Just resample them. Let me know if you struggling with batch. I've got script. As usual reply next February
    – FelixIP
    Commented Feb 4, 2017 at 1:57
  • Thanks @FelixIP that is a great idea. I will reply to you now so I don't forget to do it next year. Commented Feb 6, 2017 at 16:51
  • What does your code for trying to do this look like so far? It seems like you have some ideas but have not yet assembled them into a code snippet to test and present with the results of that testing.
    – PolyGeo
    Commented Feb 16, 2017 at 4:33

0

Browse other questions tagged or ask your own question.