Select to view content in your preferred language

Trouble converting polygon to raster

1361
3
10-07-2010 10:53 AM
DavidMazeika
Deactivated User
I am attempting to convert polygons into a raster file based on a specific field. However, when I attempted this I got the following error messages:

ERROR 010067: Error in executing grid expression. Unable to decode column value
ERROR 010235: Returned error from ShapeGrid

The field I am using to populate the raster grid was one I added into the table of contents. So the only thing I can think of is there's an issue there, especially since I was able to populate the raster using a preexisting field. Any help is greatly appreciated.

-Dave
0 Kudos
3 Replies
DerekRyter
Deactivated User
I am having the same problem. I can use a field in a polygon shape file to create a raster in Spatial Analyst in ArcTools. But when I try to do the same thing programatically, with the same field, it gives me the same error you get. I am using short integer fields, and the code will work with one field and not another. If I find an answer I'll post it.

Here is the code:

Private Sub cmdPoly2Asc_Click()
    'first, build the workspace
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New RasterWorkspaceFactory
    Dim pWS As IRasterWorkspace2
    Set pWS = pWSF.OpenFromFile(txtPath, 0)
    'next, get the features as a feature class
    Dim pFC As IFeatureClass
    Set pFC = pFeatLayer.FeatureClass
    'set up a ConversionOp and RasterConversionOp to turn the features into a raster
    Dim pRasCon As IConversionOp
    Set pRasCon = New RasterConversionOp
    'set up how the raster will be created
    Dim pEnviro As IRasterAnalysisEnvironment
    Set pEnviro = pRasCon
    pEnviro.SetCellSize esriRasterEnvValue, Val(txtCellSize.Value)
    'pEnviro.OutWorkspace = pWS
    'since I want to use the field selected by the user, I need to use a geodataset
    Dim pDS As IDataset
    Set pDS = pFeatLayer.FeatureClass
    Dim pGeoDataset As IGeoDataset
    Set pGeoDataset = pDS
    'now build a feature descriptor to make a raster
    Dim pFeatDesc As IFeatureClassDescriptor
    Set pFeatDesc = New FeatureClassDescriptor
    pFeatDesc.Create pGeoDataset, Nothing, pField.Name     '<+++++++++Crash!
   
    'now make the rasterdataset from the features
    Dim pOutRasDS As IRasterDataset
    Set pOutRasDS = pRasCon.ToRasterDataset(pFeatDesc, "GRID", pWS, "TEMP")
   
    'convert the raster dataset to an asc raster
    Dim pRasterExportOp As IRasterExportOp
    Set pRasterExportOp = New RasterConversionOp
   
    Dim lcFileName As String
    If Right(txtPath, 1) = "\" Then
        lcFileName = txtPath & txtFileName & ".asc"
    Else
        lcFileName = txtPath & "\" & txtFileName & ".asc"
    End If
   
    Dim fso As Object, fldr
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fldr = fso.GetFolder(txtPath)
    If fso.FileExists(lcFileName) Then Kill lcFileName

    pRasterExportOp.ExportToASCII pOutRasDS, lcFileName
    Dim pRDS As IDataset
    Set pRDS = pOutRasDS
    pRDS.Delete
   
    'lastly, open the asc grid and remove the header
    Open lcFileName For Input As #1
    Dim lcLine As String
    Dim i As Long
    For i = 1 To 6
        Line Input #1, lcLine
    Next i
   
    Dim lcFileCont As String
   
    Do
        Line Input #1, lcLine
        lcFileCont = lcFileCont & lcLine & vbCrLf
    Loop While Not EOF(1)
   
    lcFileCont = Left(lcFileCont, Len(lcFileCont) - 4)
    Close
   
    Kill lcFileName
    Open lcFileName For Output As #1
    Print #1, lcFileCont
    Close
   
    Set pRasterExportOp = Nothing
    Set pOutRasDS = Nothing
    Set pEnviro = Nothing
    Set pRasCon = Nothing
    Set pWS = Nothing
    Set pWSF = Nothing
    Set pRDS = Nothing
    Set pDS = Nothing
    Set pFeatDesc = Nothing

End Sub
0 Kudos
ZackSteel
Emerging Contributor
I'm having the same problem as the two previous posts on this thread. Did anyone ever find a solution?
Thanks.
0 Kudos
JosteinSvegården
Deactivated User
I have the same problem, trying to make a grid out of polygons, with values from a field that I added and calculated manually. Short integer field
0 Kudos