Select to view content in your preferred language

How to Get Polygon of Raster Extent in ArcGIS Pro

17875
12
Jump to solution
09-07-2021 04:55 PM
dgray
by
Regular Contributor

Hi,

I would like to know a way, or several methods if they exist, of generating a rectangular polygon representing the footprint of a raster using ArcGIS Pro.  I don't want to go through the extra time to convert a raster to polygon as is, because this is a potentially very time-consuming step (especially if the raster is an image), whereas I only want a single-valued output. 

If this method does not require higher licensing levels or extensions, that would be even better, but if not that's ok too.

If there's a custom Python script that will do that job, or a snippet of Python I could insert into a script, please let me know.

Thanks!

0 Kudos
12 Replies
ClaireMcHenry2
Emerging Contributor

Did anything ever come from this? I am attempting to batch export the extent of multiple historic maps (all raster). I suppose I am looking for the footprint as well and not the extent itself. 

0 Kudos
JohnGaiot
Regular Contributor

It seems like a basic function but in my experience, it's not. There is one function that comes very close and it's a quick one-step solution. It's called "Raster Domain".. However, the Downsides: it requires 3D Analyst, and more importantly, the final polygon goes through the centroid of each cell at the data extent of the raster, so it's not an exact 'footprint' as it falls a half cell short on all sides of features represented. But if you want something quick and approximate, this would be the ideal solution.

For something more exact, the simplest method would be to use Raster Calculator (which requires a Spatial or Image Analyst license). Set the "NoData" Environment variable to something other than Zero. If you have a floating point or non-discrete raster like a DEM, you will first need to convert your raster to integer. Second, multiply the raster by Zero, so you get a single value for the entire raster where there were valid values. Third, convert the Zero raster to a polygon. Now you have your extents based on features in a raster.

0 Kudos
Town_ofCBS_GIS
Emerging Contributor

Hello, I was also trying to do this so I could label all my rasters. To do this I had to create a polygon layer. Make sure the project you are working on is saved and closed, then open the python notebook in a different project. Also, I only had one 'Map' - when I had multiple it would not work. Below is my python code:

 

import arcpy

# Set the workspace environment
arcpy.env.workspace = r"C:\path\to\your\geodatabase.gdb" # Update the path to your geodatabase

# Input map project file (.aprx)
map_project = r"C:\path\to\your\map_project.aprx" # Update the path to your map project file (.aprx)

# Reference the map project
aprx = arcpy.mp.ArcGISProject(map_project)

# Get all the maps in the project
maps = aprx.listMaps()

# Create a polygon feature class to store layer names as polygons
polygon_fc_name = "LayerNamesPolygon"
polygon_fc_path = arcpy.management.CreateFeatureclass(arcpy.env.workspace, polygon_fc_name, "POLYGON").getOutput(0)

# Add a field to store layer names in the polygon feature class
arcpy.management.AddField(polygon_fc_path, "Layer_Name", "TEXT")

# Iterate through each map in the project
for map_obj in maps:
# Iterate through each layer in the map object
for lyr in map_obj.listLayers():
if lyr.isRasterLayer:
# Get the raster layer name
raster_layer_name = lyr.name

# Get the extent of the raster layer
desc = arcpy.Describe(lyr)
extent = desc.extent

# Create a polygon from the extent
array = arcpy.Array([extent.lowerLeft, extent.lowerRight, extent.upperRight, extent.upperLeft])
polygon = arcpy.Polygon(array)

# Insert the polygon with layer name into the feature class
with arcpy.da.InsertCursor(polygon_fc_path, ["SHAPE@", "Layer_Name"]) as cursor:
cursor.insertRow([polygon, raster_layer_name])

# Save changes to the map project
aprx.save()

# Delete the ArcGISProject object to release locks
del aprx

0 Kudos