Raster to Polygon fails with empty input

7910
15
05-07-2010 03:33 PM
JoeChampagne
Occasional Contributor
When I attempt to run the Raster to Polygon tool with a NoData raster (801 rows and 1400 columns), a corrupted shapefile is output and the following error message appears:

ERROR 010067: Error in executing grid expression.
Failed to execute (RasterToPolygon).

This is an issue because I'm trying to batch process a large number of watershed rasters (some of which are empty) using a Python script (832 tiles), and the script is interrupted when it encounters the first empty raster. Is there any known workaround for this issue? Alternately, is there any way to programmatically check for these invalid inputs?
0 Kudos
15 Replies
DanielBennett
New Contributor
Hi,

Same problem as above. What is the fastest (python script) test that tells me if a raster is all NoData?

I'm thinking SearchCursor:

rows = arcpy.SearchCursor("C:/Data/raster", " ??WHERE NODATA??", "", "",  "")
if is_empty(rows):
    empty = True
else:
    empty = False
0 Kudos
SteveLynch
Esri Regular Contributor
In 10SP1 we fixed it so that Raster To Polygon with all NoData will throw
ERROR 010151: No features found

To test if a Raster has all NoData run the IsNull tool. If the output is all 1 then it only has NoData


Steve
BenLeslie1
Occasional Contributor III

Hi - I'm just trying to work round this error in my script....

"To test if a Raster has all NoData run the IsNull tool. If the output is all 1 then it only has NoData"

How do you test whether the whole raster is 1?

0 Kudos
NeilAyres
MVP Alum

Here is an example of getting the % of nulls in a raster.


# calculate % no data cells in a raster.
import sys, os, arcpy
from arcpy import env
from arcpy.sa import *


if arcpy.CheckExtension("Spatial"):
    arcpy.CheckOutExtension("Spatial")
else:
    print "No SA licence"
    exit


HomeDir = "c:/Data/Swala/BurkinaFaso/IPSurvey/"
fgdb = "IPRasterData.gdb"
InData = os.path.join(HomeDir, fgdb)


env.workspace = InData
env.overwriteOutput = True


ListRast = arcpy.ListRasters()
# ListTable = arcpy.ListTables()


for r in ListRast:
    print "Processing", r
    Ras = arcpy.Raster(r)
    NullRas = IsNull(Ras)
    NCol = NullRas.width
    NRow = NullRas.height
    NCell = NCol * NRow
    Mean = NullRas.mean
    NNull = Mean * NCell
    print "{} % Null {}".format(r, NNull / NCell * 100)

SteveLynch
Esri Regular Contributor

or

look at the GetRasterProperties gp tool

-Steve

XanderBakker
Esri Esteemed Contributor

Although Neil's snippet allows for determining the percentage of NoData in a raster, Steve provides a solution that does exactly what you are looking for and does not require Spatial Analyst. To show a little what you can do with it, here's a litte sample:

import arcpy

ras = r"D:\Xander\LineasTransmision\Modelo\fgdb\RastersModelo.gdb\cmp_totexl02a"

props = ['MINIMUM', 'MAXIMUM', 'MEAN', 'STD', 'ALLNODATA', 'ANYNODATA', 'UNIQUEVALUECOUNT']

for prop in props:

    try:

        print "{0}: {1}".format(prop, arcpy.GetRasterProperties_management(ras, prop))

    except Exception as e:

        print "{0}: {1}".format(prop, e)

Returns:

# MINIMUM: 22

# MAXIMUM: 396

# MEAN: 97,7094252332071

# STD: 51,5918279932734

# ALLNODATA: 0

# ANYNODATA: 1

# UNIQUEVALUECOUNT: 327

So you will just have to test for the property "ALLNODATA" and when the result is '1', skip that raster.

Kind regards, Xander

EvaSevillano
New Contributor II

Useful script! 

Is it possible however that a raster has the ALLNODATA = 1 but looks visually ok, has a nodata value defined and the statistics are ALSO provided from the Get Raster Properties parameters: MEAN, MAXIMUM, MINIMUM, STANDARD DEVIATION ??

I am trying to understand why this happens to be able to convert to points afterwards...

Any suggestions for a workaround?

Thanks

0 Kudos
XanderBakker
Esri Esteemed Contributor

Not sure if I understand... You have a raster that returns ALLNODATA = 1 (so all pixels are NoData values) but does have values (hence the valid stats for MEAN, MAXIMUM, MINIMUM, STANDARD DEVIATION)? If that happens it should be a bug. Is it possible to share the raster? Did you contact support?

0 Kudos
EvaSevillano
New Contributor II

Yes, you understood correctly.

Strange as it comes from masking a source raster  (like spliting it). The source raster also shows allnodata = 1,  but looks ok, stats ok, values ok, nodata defined ok. 

The split rasters some show the allnodata 1 and some allnodata =0. All of them looking ok, stats ok, nodata defined ok.

Sure. I can share. How do we exchange the file?

I only wrote here, as I saw the issue of the allnodata thread.

Thank you! Really surprised with this artifact.

Can't figure out what it is.

Enviado desde Yahoo Mail con Android

El jue., jul. 26, 2018 a 18:38, Xander Bakker<geonet@esri.com> escribió:

#yiv9856133252 * #yiv9856133252 a #yiv9856133252 body {font-family:Helvetica, Arial, sans-serif;}#yiv9856133252 #yiv9856133252 h1, #yiv9856133252 h2, #yiv9856133252 h3, #yiv9856133252 h4, #yiv9856133252 h5, #yiv9856133252 h6, #yiv9856133252 p, #yiv9856133252 hr {}#yiv9856133252 .yiv9856133252button td {}

|

GeoNet

|

Re: Raster to Polygon fails with empty input

reply from Xander Bakker in Spatial Analyst - View the full discussion

Not sure if I understand... You have a raster that returns ALLNODATA = 1 (so all pixels are NoData values) but does have values (hence the valid stats for MEAN, MAXIMUM, MINIMUM, STANDARD DEVIATION)? If that happens it should be a bug. Is it possible to share the raster? Did you contact support?

Reply to this message by replying to this email, or go to the message on GeoNet

Start a new discussion in Spatial Analyst by email or at GeoNet

Following Re: Raster to Polygon fails with empty input in these streams: Inbox

This email was sent by GeoNet because you are a registered user.

You may unsubscribe instantly from GeoNet, or adjust email frequency in your email preferences

0 Kudos