Odd behavior using Reclassify in arcpy

914
6
Jump to solution
11-21-2018 12:45 PM
RobertTrotter
New Contributor III

I am using Reclassify in arcpy to reclassify a raster, and am running into an issue.  I'll briefly explain what I am trying to do, then explain the issue I am running into.

I have a point shapefile, and I am converting this to a raster, what I want is a raster in with two values, a 1 for pixels which did not include a point (does not matter how many points for now), and 0.3 for pixels that do include points.  To get there, I am using arcpy.PointToRaster_conversion as follows

pointfile = shapefile with point features

outraster = output raster

cellsize = size of raster cells

field = the field used to assign the value to the raster (the field is the same constant for all points) 0.3

arcpy.PointToRaster(pointfile,field,outraster,"","",cellsize)

This produces a raster in which the cells that include points have the field value, and the rest of the cells have "NoData"

Map Calculator does not work in arcpy, so I am using Reclassify

value = value field in raster

temporaryraster = Reclassify(outraster,value,RemapValue([["NoData",100],[0.3,30]),"DATA")

The output raster should have the value 30, where there were previously values of 0.3, and 100s where previously there was "NoData",  the output is correct, except there are values of 29 where there should be values of 100.  Any suggestions?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Robert, I meant, doing the IsNull part first and assigning it to a variable and then using that in the con

isnull_result = IsNull(…..

con_result = Con(isnull_result, …..

step-wise may have been a better tern

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Con(IsNull(inRaster), 1.0, 0.3)

IsNull returns 1 for locations that are nodata and 0, otherwise, but you can use Con to do the final reclass of you cells that have points to 0,3

0 Kudos
RobertTrotter
New Contributor III

Hello, my apologies if I am missing something obvious (I am new to Python), but I had tried this approach earlier, and it seems that the function is part of the Raster Calculator, which works, but only produces INTEGER output.  Is there another way, or perhaps am I doing it wrong?  (I used the same script you have shown).

In the meantime, I found a workaround (I did the reclass, allowed it to go to integers, and then used the Plus and Times functions to modify the output).  Thanks!

This fixed the "converting 100 to 29" issue, but any ideas what caused it?

0 Kudos
DanPatterson_Retired
MVP Emeritus

The Con and IsNull tools in arctoolbox can be used, incrementally.  There is no reason that either tool is limited to an integer.  If it were, you can always 'times' by 1.0 or 'float' it

0 Kudos
RobertTrotter
New Contributor III

I did indeed end up "floating" it as a workaround.  By using it incrementally, do you man by imbedding it in a loop or a function?  And you are right about it not being limited to an integer, I was thinking of the Reclass tool, which does seem to be limited.  Thanks!

0 Kudos
RobertTrotter
New Contributor III

forgot to mention, I have not been successful in getting functions to run in arcpy (using the def approach).  I get a syntax error using a simple "def functionname(var)" command, but that is probably a problem for another thread.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Robert, I meant, doing the IsNull part first and assigning it to a variable and then using that in the con

isnull_result = IsNull(…..

con_result = Con(isnull_result, …..

step-wise may have been a better tern

0 Kudos