arcpy.conversion.RasterToPoint errors

371
9
10-04-2018 12:04 PM
JimFritz
Occasional Contributor

Having difficulty with the following script.  A couple of variables to know about are not shown but have been run prior to this snippet, they are:

outrasterpath = r"S:/General-Offices-GO-Trans/SLR-Mapping/GIS_Projects_2018/Smart_T_Line_Model/geodata/TEST_RASTERCLIP.gdb/"

outrastertopoint = r"S:/General-Offices-GO-Trans/SLR-Mapping/GIS_Projects_2018/Smart_T_Line_Model/geodata/TEST_RASTERTOPOINT.gdb/"

arcpy.env.workspace = outrasterpath
rasterList = arcpy.ListRasters("*", "GRID")
for raster in rasterList:
    arcpy.conversion.RasterToPoint(raster, outrastertopoint + raster, "Pixel Value")
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 195, in RasterToPoint
    raise e
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 192, in RasterToPoint
    retval = convertArcObjectToPythonObject(gp.RasterToPoint_conversion(*gp_fixargs((in_raster, out_point_features, raster_field), True)))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input raster: is not the type of Composite Geodataset, or does not exist.
ERROR 001000: Field: Field Pixel Value does not exist
Failed to execute (RasterToPoint).

A few other bits of info.  I have tried "VALUE", "Pixel value", and "Stretch.Pixel Value" for the last argument, none work.

Have left the () with no inputs on Line 2 with no luck.

Thanks for any help!

0 Kudos
9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

throw a print statement in at line 3.5.

you don't raw encode (ie r ) forward-slashed paths (can't remember if it is an issue but it shouldn't be there)

And the biggie... it requires a 'raster layer' as input, not a file on disk unless it is a *.lyr which wouldn't be in a gdb anyway.  So you will have to add a 

Make Raster Layer—Data Management toolbox | ArcGIS Desktop 

to the workflow

0 Kudos
JimFritz
Occasional Contributor

Dan,

The forward slashes have not been issue so far.

Here’s the result of the print:

print(rasterList)

So, that is OK.

I did change a line of code as I had “raster” meaning a pathname to a grid that was used for clipping earlier in the script as opposed to it being referenced in the

For raster in rasterList:

Thanks,

Jim

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

lets try print(raster) since print(rasterlist) didn't appear to print (or is it a copy past issue),

You still need a rasterlayer… which isn't a raster per se but a *.lyr *.lyrx or it is a 'layer' open in arcmap or Pro

0 Kudos
JimFritz
Occasional Contributor

Here’s the result of both print(raster) and print(rasterlist). In this script it’s looping thru 5 grids, from rasterlist:

print(raster)

T_0517__BRI_DJS_TP_34_5_1

print(rasterList)

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

so it is a raster... throw it into the makerasterlayer and use that layer in the conversion

0 Kudos
JimFritz
Occasional Contributor

Dan,

Since it is going to be 1,455 rasters in the loop I was hoping to not have to run another conversion prior to running the raster to point.

SO, I’m hoping for another solution but will attempt to use this if no other solutions come in.

Thanks,

Jim

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Try one... from the example they use a *.img… I have tested with *.tiff that is both seem to be standalone files, so the gdb raster stuff, you will have to see if it works.

import arcpy
from arcpy import env
env.workspace = "C:/data"  # ---- notice, a folder with a raster dataset
arcpy.RasterToPoint_conversion("source.img", "c:/output/source.shp", "VALUE")

if it works for one raster that you know of then you should be good.

I wouldn't even change the shapefile output until you know the process works

replace env.workspace with your gdb path

replace source.img with your 'raster' name

0 Kudos
JimFritz
Occasional Contributor

OK, will give that a go tomorrow.

Thanks for your assistance!

0 Kudos
DarrenWiens2
MVP Honored Contributor

Try specifying the entire path for the input raster, rather than relying on the workspace env. If that doesn't work, try running the tool on its own (outside any loop), hardcoding the values that you think should work, and work backwards from there. Things I see that can make easy mistakes in your code: concatenating path components (should try to use os.path.join), using FGDB rasters, relying on envs, specifying a field that probably doesn't exist, and I'm not sure that FGDB rasters are GRID format (although it seems to be working for you).