4

I'm trying to convert a raster with multiple columns to a point shapefile to get rid of the "count" column but unfortunately the tool "raster to point" works just for one column so I tried to modify this code to write the atribute table to a csv file but it still doesn't work.

I just get a lot of zeros in my outfile. Why am I get just a bunch of zeros?

I'm using ArcMap.

This is the modified code:

outfile = Workspace + "/table"

fOut = open(outfile, "wb")               
fOut.write('ID' + ',' + 'Flowaccumaltion' + ',' + 'Flowlength\n') 
rstArray = arcpy.RasterToNumPyArray(Combined_Raster) 
rows, cols = rstArray.shape                   
for rowNum in xrange(rows):             
    for colNum in xrange(cols):               
        if colNum == 1 or  colNum == 3:
            value = rstArray.item(rowNum, colNum)   
            fOut.write(str(value) + ',')      
        elif colNum ==4:
            value = rstArray.item(rowNum, colNum)   
            fOut.write(str(value) + '\n')           
fOut.close()

This is the raster attribute table I want to convert

Attribute Table

And I would like to get something like this:

ID  , Flowaccumulation,  Flowlength
57  ,    727          ,      1
58  ,     727         ,      1
 0  ,   76073         ,   1008
 1  ,   14919         ,    622
 .  ,      .          ,      .

But if there is a tool which can convert a raster to a point shapefile with all fields except for the "count" field then this would be even better.

4

You could use the Join Field tool after the converting to points to add the raster fields to the points attribute table. Something like:

arcpy.RasterToPoint_conversion(inRaster, outPoint, "value")
arcpy.JoinField_management(outPoint, "rastervalue", inRaster, "value", ["field1","field2", "field3"])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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