I have a polyline that I am converting to a raster in arcpy. This is occuring within a loop and at each iteration I change the processing environment to a different area of interest. In this case it is a specific polygon (like below)

whereClause = '"FID" = ' + str(poly.FID) # Create a clause to select only the current record
arcpy.MakeFeatureLayer_management(shapefile, "currentPolygon", whereClause)        
arcpy.env.extent = "currentPolygon"

At each iteration I would like to create a raster where cells containing the polyline are given a value of 1 and cells without polyline are given a 0 within the bounds of the env.extent.

What is the key to creating the 0 values?

Does it come from the arcpy.env.nodata parameter?

I can make the conversion in my loop but cannot quite get the binary format I am envisioning.

arcpy.FeatureToRaster_conversion("roadsLayer", "VALUE", "roadsGrid.tif",)

1 Answer 1


In the help files for ArcMap, the link states how to do it procedurally, simply check the IsNull and Con statement links for code examples. I also think you can "not" the isnull expression shown in the IsNull link, but I have no way of testing it now

  • This requires Spatial Analyst?
    – klewis
    Aug 14, 2014 at 0:07
  • @klewis, yes as indicated in the IsNull and Con help sections
    – user681
    Aug 14, 2014 at 0:10
  • Reclass might work as well, i.e. NO DATA will get 0
    – FelixIP
    Aug 14, 2014 at 5:34
  • From these answers/comments it sounds like it cannot be done by changing the env.extent value and it must be done with another reclass or IsNull/Con step
    – jotamon
    Aug 14, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.