1

ArcGIS 10.1 - attempting to add a derived raster layer to the ToC. This works in 10.2. In 10.1 I get a screen flash and nothing added.

rasterized = r'in_memory\rasterized'
arcpy.PolygonToRaster_conversion(poly_shp, field, rasterized, None, cellsize)
res = arcpy.MakeRasterLayer_management(rasterized, 'tmplyr')
rasterlyr = res.getOutput(0)

mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd, '*')[0]
arcpy.mapping.AddLayer(df, rasterlyr, "TOP")

Where: poly_shp = unicode vector name field = unicode field name from the poly_shp rasterized = str cellsize = float

Adding:

arcpy.RefreshTOC()
arcpy.RefreshActiveView()

has no effect.

Edit:


I know that the in_memory workspace is functioning properly as the following try is hit on subsequent runs.

try:
        arcpy.Delete_management(rasterized)
        arcpy.AddMessage('Overwriting in_memory raster')
except:
        pass 

1 Answer 1

1

This line is wrong:

arcpy.PolygonToRaster_conversion(poly_shp, field, rasterized, None, cellsize)

You have missed out cell alignment parameter, so try

arcpy.PolygonToRaster_conversion(poly_shp, field, rasterized, "","", cellsize)

With that parameter set your code executes and a raster is added to my TOC. If that correction does not work then it strongly suggests either the poly_shp, field or cellsize parameters are invalid.

3
  • Using: res = arcpy.PolygonToRaster_conversion(roi,abundance,rasterized,"MAXIMUM_AREA","",cellsize) had no effect. Replacing "MAXIMUM_AREA" with "" also had no effect.
    – Jay Laura
    May 9, 2014 at 15:43
  • Your code worked for me when I included the missing parameter. Please amend your question to show EXACTLY what your your variables hold
    – Hornbydd
    May 9, 2014 at 15:49
  • updated - can you update your answer with the datatypes you are passing in? It amazes me that this works in 10.2 and fails in 10.1.
    – Jay Laura
    May 9, 2014 at 16:23

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.