Select to view content in your preferred language

Problem: Feature to Raster converstion using python scipt

5673
7
08-16-2011 11:46 PM
ZiaAhmed
Occasional Contributor
I am trying to convert a shape file to raster by a python script. But it did not work. However,  this conversion was done successfully by  ArcToolBox. I used similar parmeters for raster conversion in the script - but I have got following errors. Any idea?

# print arcpy.GetMessages

Traceback (most recent call last):
  File "K:\SCRIPT\Python_Script\ShapeToRaster.py", line 22, in <module>
    arcpy.FeatureToRaster_conversion(inFeatures, field, outRaster, cellSize)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1686, in FeatureToRaster
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input features: is not the type of Composite Geodataset, or does not exist.
ERROR 001000: Field: Field MUKEY does not exist
Failed to execute (FeatureToRaster).

---------------------------------------------------------------------

# Import system modules
import arcpy, os,sys
#
# Set environment settings
arcpy.env.workspace = "K:/STATE_MUKEY/AREA.gdb"
#
# Set local variables
inFeature = "soilmu_in.shp"
field = "MUKEY"
outRaster = "K:/STATE_MUKEY/RASTER.gdb/soilmu_in"
#assignmentType = "CELL_CENTER"
#priorityField = "NONE"
cellSize = 90

# Execute FeatureToRaster
arcpy.FeatureToRaster_conversion(inFeature, field, outRaster, cellSize)

print arcpy.GetMessages
Tags (2)
0 Kudos
7 Replies
HemingZhu
Frequent Contributor
I am trying to convert a shape file to raster by a python script. But it did not work. However,  this conversion was done successfully by  ArcToolBox. I used similar parmeters for raster conversion in the script - but I have got following errors. Any idea?

# print arcpy.GetMessages

Traceback (most recent call last):
  File "K:\SCRIPT\Python_Script\ShapeToRaster.py", line 22, in <module>
    arcpy.FeatureToRaster_conversion(inFeatures, field, outRaster, cellSize)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1686, in FeatureToRaster
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input features: is not the type of Composite Geodataset, or does not exist.
ERROR 001000: Field: Field MUKEY does not exist
Failed to execute (FeatureToRaster).

---------------------------------------------------------------------

# Import system modules
import arcpy, os,sys
#
# Set environment settings
arcpy.env.workspace = "K:/STATE_MUKEY/AREA.gdb"
#
# Set local variables
inFeature = "soilmu_in.shp"
field = "MUKEY"
outRaster = "K:/STATE_MUKEY/RASTER.gdb/soilmu_in"
#assignmentType = "CELL_CENTER"
#priorityField = "NONE"
cellSize = 90

# Execute FeatureToRaster
arcpy.FeatureToRaster_conversion(inFeature, field, outRaster, cellSize)

print arcpy.GetMessages


You set up arcpy.env.workspace = "K:/STATE_MUKEY/AREA.gdb" and inFeature = "soilmu_in.shp".  Basically you are telling arcpy to find soilmu_in.shp in K:/STATE_MUKEY/AREA.gdb, which does not exist.
0 Kudos
ZiaAhmed
Occasional Contributor
Thanks your reply. These is exist! Please see the attachment.  I mentioned before, I converted this file to raster using ArcTool box.

You set up arcpy.env.workspace = "K:/STATE_MUKEY/AREA.gdb" and inFeature = "soilmu_in.shp".  Basically you are telling arcpy to find soilmu_in.shp in K:/STATE_MUKEY/AREA.gdb, which does not exist.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
hzhu is correct.  You are specifying a shapefile rather than a feature class.  Change:

inFeature = "soilmu_in.shp"


to

inFeature = "soilmu_in"
0 Kudos
ZiaAhmed
Occasional Contributor
After changing to feature class, it shows similar error.
Thanks

hzhu is correct.  You are specifying a shapefile rather than a feature class.  Change:

inFeature = "soilmu_in.shp"


to

inFeature = "soilmu_in"
0 Kudos
HemingZhu
Frequent Contributor
Thanks your reply. These is exist! Please see the attachment.  I mentioned before, I converted this file to raster using ArcTool box.


Your code specified you shape file in "K:/STATE_MUKEY/AREA.gdb", which is obviously wrong.  You should specify the full path of your shape file (wherever that is). like this
inFeature = "K:/STATE_MUKEY/soilmu_in.shp"

0 Kudos
ZiaAhmed
Occasional Contributor
Following script works well for this example (Indiana) and as well for other States. This  script was imported  from Model Builder. Thanks Zia


# Import arcpy module
import arcpy

# Local variables:
soilmu_in= "K:\\STATE_ MUKEY\\AREA.gdb\\soilmu_in"
soilmu_in__2_ = "K:\\STATE_ MUKEY\\RASTER.gdb\\soilmu_in"

# Process: Polygon to Raster
arcpy.PolygonToRaster_conversion(soilmu_in, "MUKEY", soilmu_in__2_, "CELL_CENTER", "NONE", "90")
print arcpy.GetMessages


Your code specified you shape file in "K:/STATE_MUKEY/AREA.gdb", which is obviously wrong.  You should specify the full path of your shape file (wherever that is). like this
inFeature = "K:/STATE_MUKEY/soilmu_in.shp"

0 Kudos
__4
by
New Contributor
Hello, I got the same Error recently. But my problem is some about raster not shapefile.And  finally I work it out by the key of datatype. For example I want to use "GreaterThanEqual" in my model, so I create a variable with the default datatype "Raster Dataset" and when I use my tool in code, I got the error like this,

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input raster or constant value 1: is not the type of Composite Geodataset, or does not exist.
ERROR 000860: Input raster or constant value 1: is not the type of Composite Geodataset, or does not exist.
Failed to execute (Model3).

And while I change the datatype from "Raster Dataset" into "Raster Layer" , my code ,the same code, works well.

So I think we can do something by the Datatype.
Further, to my surprise, when I change the datatype from "Raster Layer" back to "Raster Dataset", my code still work.
I am confused. I am not sure,but my code could work.

May you succeed.
0 Kudos