Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a feature class with 5 lines in it, and need select each one and turn them into its own raster -- for example, line 1 is raster 1, line 2 is raster 2, etc. This is the python script:

import arcpy

SightLines = "C:\\temp\\SightLines.shp"

index = 0
rows = arcpy.SearchCursor(SightLines)
for row in rows:
    RasterFileName = "C:\\temp\\fakeData.gdb\\Raster" + str(index)
    arcpy.AddMessage("Raster File " + RasterFileName)
    arcpy.FeatureToRaster_conversion(row, "FID", RasterFileName, "1")
    arcpy.AddMessage(" >> MADE SUCCESSFULLY")
    index = index + 1

Unfortunately, this is throwing the following error at the FeatureToRaster_conversion step:

    raise e
RuntimeError: Object: Error in executing tool

I can't figure out what raise e is trying to tell me. What exactly is going wrong?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

The "FeatureToRaster" conversion tool works on a feature class as a whole. You are passing it a row object, and this does not work. You would first need to extract each line as its own feature class, then convert that to a raster, then you can delete the temporary feature class.

share|improve this answer
    
OH. That explains quite a lot. Thanks :) –  Erica May 20 '13 at 19:22
add comment

Instead of exporting a separate feature class per line, create a feature layer instead- This will speed things up since no new features need to be written to disk (feature layers are in memory).

share|improve this answer
    
Great tip. Thank you! –  Erica May 21 '13 at 2:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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