Nodata areas in the raster created by conversion tool "Polygon to Raster"

427
8
12-14-2021 02:28 AM
GiuseppeGentili
New Contributor III

Hoping to have post this message in the right section, I reports a trouble experienced in the creation of raster from polygon feature class using the conversion tool "PolygonToRaster".
If I I set the environment extent the raster that has been created by the tool reports a "blank" area whose pixels are "nodata". If no extent is set, the raster is created with the correct representation of  input polygon coverage (any "nodata" pixels ...)
The extent of the feature class is little bit grater that the output extent I have set.
I have also performed a "Check geometry" before to execute the tool.

Here is the python code that reproduces the wrong result:

import arcpy
import os

arcpy.env.overwriteOutput = True

GDB_locale = r'C:\TEMP\rcwh0\scratch.gdb'
clu_fc = r'C:\TEMP\rcwh0\scratch.gdb\rcwh0'
mca_ras = os.path.join(GDB_locale, "mca_ras")
out_cellsize = 2

desc = arcpy.Describe(clu_fc)

xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax

print "Extent of %s \nxmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (clu_fc, xmin, xmax, ymin, ymax)

arcpy.env.extent = "359900 5059900 370100 5070100"

xmin = arcpy.env.extent.XMin
xmax = arcpy.env.extent.XMax
ymin = arcpy.env.extent.YMin
ymax = arcpy.env.extent.YMax

print "Env extent \nxmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax)

arcpy.PolygonToRaster_conversion(clu_fc, "CODE_H", mca_ras, "MAXIMUM_COMBINED_AREA", "NONE", out_cellsize)

I get the same wrong raster regardless the cell assignement parameter  value set in the tool.

I have attached the file GDB in which there is the polygon feature class (rcwh0) used for the conversion, and the screen shot of the wrong raster created (in red color the nodata)

This trouble was experienced in ArcMap 10.8.1

0 Kudos
8 Replies
DanPatterson
MVP Esteemed Contributor

Try the code variant using a "with" statement

Using environment settings in Python—ArcGIS Pro | Documentation

and use Code formatting ... the Community Version - Esri Community

so there are line numbers in your code people can reference


... sort of retired...
0 Kudos
GiuseppeGentili
New Contributor III

Unfortunately the "with" variant does not fix the trouble. 
I have got the same bad raster.

Here is the code with the variant:

with arcpy.EnvManager(cellSize=2, extent="359900 5059900 370100 5070100"):


    xmin = arcpy.env.extent.XMin
    xmax = arcpy.env.extent.XMax
    ymin = arcpy.env.extent.YMin
    ymax = arcpy.env.extent.YMax

    print "Env extent \nxmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax)

    arcpy.PolygonToRaster_conversion(clu_fc, "CODE_H", mca_ras, "MAXIMUM_COMBINED_AREA", "NONE", out_cellsize)
0 Kudos
DanPatterson
MVP Esteemed Contributor

out_cellsize is defined elsewhere? or use

out_cellsize=cellSize  from your "with" statement

What happens when you change the Cell assignment type to the default

and try a *.tif in a folder as output


... sort of retired...
0 Kudos
GiuseppeGentili
New Contributor III

Yes, out_cellsize is set before the "with" statement. 
Unfortunately, also the tif file shows the same trouble. I have attached it as zip file.

0 Kudos
DanPatterson
MVP Esteemed Contributor

It keeps failing when done manually (aka, no code) 

You have thousands of tiny polygons less than a fraction of a m^2, I cleaned those out and it still fails.

I would work with the polygon file to find out what the problem is.  Do it in ArcToolbox, I got a warning about the spatial index, try recreating the spatial indices after removing polygons less than your desired cell size


... sort of retired...
0 Kudos
GiuseppeGentili
New Contributor III

I have added a spatial index to the polygon feature class, having left the setting grid sizes to 0,0,0 
Anyway, the converted raster again shows the nodata areas. 

Without removing any tiny polygons, I have reduced the extent by the value of one cell size.
The conversion worked well !!

There aren't any tiny polygons along the "nodata" area, so I think that the tiny polygons are not responsible of this trouble. I have successfully converted other polygon coverages having thousands of tiny polygons as well. 

0 Kudos
SteveLynch
Esri Regular Contributor

I've logged an issue for the problem.

 

-Steve

 

0 Kudos
GiuseppeGentili
New Contributor III

Many thanks for your support. I'll look forward to your good news.

0 Kudos