# Convert a column of a polygon with float values to a raster by using arcpy.da.SearchCursor

I have a polygon feature and i want to convert it to a raster but i dont want the polygon as a whole , i just want each column to produce a different raster.The first problem starts that the values are float. I have tried to write a python to do this but I am still getting errors, below is my table and I would like to have a raster for the S10 and S100 respectively.

the code is as follows:

import arcpy
import os, sys
import numpy as np

outputfolder = arcpy.GetParameterAsText(0)
featuredata = arcpy.GetParameterAsText(1)
createdRaster = arcpy.GetParameterAsText(2)

#cursor = arcpy.da.SearchCursor(fc,['S10','S100'])

rows = arcpy.da.SearchCursor(featuredata,['S10','S100'])
#for i in range(2,7,2):
#rows.reset()
for row in rows:
if row[1]:
#fid = row.getValue('FID')
query = str(row[1])

arcpy.Select_analysis(featuredata,"in_memory")
arcpy.FeatureToRaster_conversion("in_memory",row[1],createdRaster,10)

arcpy.Delete_management("in_memory")


And the error that I get :

Traceback (most recent call last):
File "C:\Python27\featureToraster.py", line 21, in <module>
arcpy.FeatureToRaster_conversion("in_memory",row[1],createdRaster,10)
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 001000: Field: Field 0.405 does not exist


The error that you are getting is a result of the tool expecting a field object, but instead receiving a value of a field. SearchCursors return values of fields, not the fields themselves.

Here is how I would approach your problem.

1) Use the Polygon to Raster tool because you only have polygon features in your input and this tool will give you more precision over how your rasters get produced.

2) Execute the tool twice from the ArcGIS user interface. Choose a raster file format that can support floating point data (see a complete list here, look at the "supported data types" column). If all you need are two rasters, scripting is unnecessary.

If you really want to use scripting, this should work:

import arcpy

input = r"C:\path\to\file.shp"
out_raster_1 = r"C:\path\to\output"
out_raster_2 = r"C:\path\to\output"

arcpy.PolygonToRaster_conversion(input, "S10", out_raster_1, cellsize=10)  # specify cell_assignment and priority_field if desired
arcpy.PolygonToRaster_conversion(input, "S100", out_raster_2, cellsize=10)

• the raster produced does not have an attribute table and it only has values of one column which is not the output i want..that is just a sample data . – stasha Dec 5 '17 at 20:55
• You can add an attribute table to your raster once it is created. I would recommend the procedure outlined here: gis.stackexchange.com/questions/77906/… – Chris Dec 6 '17 at 18:12