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?
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)
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
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
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?
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