SnapRaster not followed in Raster to Polygon

2242
7
Jump to solution
09-06-2016 07:08 AM
Greg_Yetman
Occasional Contributor

I'm using python to convert polygons to a series of rasters and I need the results to exactly match the extents of a set of existing rasters. I tried doing this with SnapRaster, but some of the outputs have an extra row and column. Is this a bug, or have I missed something? 

tile = os.path.join(image_tile_ws,tile_name + '.tif') env.snapRaster = tile env.extent = Raster(tile).extent env.cellSize = tile arcpy.PolygonToRaster_conversion(level0,iso_field,'l0_' + tile_name, 'MAXIMUM_AREA',weight_field,env.cellSize)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

possible...  Snap Raster (Environment setting)—Help | ArcGIS for Desktop because

Tools that honor the Snap Raster environment will adjust the extent of output rasters so that they match the cell alignment of the specified snap raster.

View solution in original post

0 Kudos
7 Replies
Greg_Yetman
Occasional Contributor

tile = os.path.join(image_tile_ws,tile_name + '.tif')

env.snapRaster = tile

env.extent = Raster(tile).extent

env.cellSize = tile

print('Creating raster...')

arcpy.PolygonToRaster_conversion(level0,iso_field,'l0_' + tile_name, 'MAXIMUM_AREA',weight_field,env.cellSize)

Second go at adding code, the formatting stripped all of the line breaks out. I also should mention that I'm running this with ArcGIS Desktop 10.3.1 on Windows Server r2. I've replicated the problem on a Windows 8 VM as well. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

possible...  Snap Raster (Environment setting)—Help | ArcGIS for Desktop because

Tools that honor the Snap Raster environment will adjust the extent of output rasters so that they match the cell alignment of the specified snap raster.

0 Kudos
Greg_Yetman
Occasional Contributor

I saw that, but according to the "How the Snap Raster environment setting works" page: 

"The lower left corner of the extent is snapped to a cell corner of the snap raster and the upper right corner is adjusted using the output cell size. As a result, when the output cell size is the same as the snap raster cell size, the cells in the output raster are aligned with the cells of the snap raster." 

Which is why I set the cell size based on the raster that I'm trying to match. 

How the Snap Raster environment setting works—Help | ArcGIS for Desktop 

DanPatterson_Retired
MVP Emeritus

but the extent can be adjusted in order for this to occur, hence the possibility of gaining another row/column in order for this to happen

0 Kudos
Greg_Yetman
Occasional Contributor

Thanks for the info Dan. 

I understand how an adjustment would be required for alignment with a difference in resolution or extent, but given that I have matched an existing rasters resolution and extent--and I am using the same coordinate system--I don't see why an additional row or column (or both, as occurs for some rasters) is needed in this case. Perhaps it's just a tolerance issue in the floating point calculation of the output extent. 

Fortunately, clipping the raster created using clip_management and the extent from the original raster fixes the problem, so I'm checking for output that is too large and clipping it where it occurs. 

0 Kudos
SteveLynch
Esri Regular Contributor

The extra row and column that were added are filled with NoData, correct?

0 Kudos
Greg_Yetman
Occasional Contributor

Not exclusively. The input polygons are often larger than the extent of the raster that I'm trying to match. Where the polygon extends beyond the extent of the raster, the additional row and/or column has the same value as the neighboring pixels (derived from the polygon). Where it does not, the extra row and/or column contain NoData values. Where only a portion of the polygon extents beyond the extent of the raster, I see the result that I would expect -- data in the extra row and/or column where the polygon extends beyond the snap raster; NoData where it does not. 

0 Kudos