1

I am trying to export points form a raster using the arcpy's RasterToPoint_conversion, but I don't want to export all the cells, only the ones with a value of 1.

This is the code:

import arcpy

rast_tif = ".......\Local\Loc_rast.tif"
out_raster = arcpy.Raster(rast_tif)
arcpy.RasterToPoint_conversion(out_raster, '.......\Local\Max_points.shp', "VALUE" == 1)

But returns the error

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 001000: Field: Field 0 does not exist

  • I see. Is there a workaround to this? – Litwos Sep 2 '16 at 7:36
2

The third parameter of the tool is a field, not an expression (The field to assign values from the cells in the input raster to the points in the output dataset, see the help page for Raster to Point.). As a workaround you can either

  • Convert the raster (arcpy.RasterToPoint_conversion(out_raster, '.......\Local\Max_points.shp', "VALUE") then use Select to filter the points with a value = 1
  • First use Con to make a raster with only the cells with a value = 1, then convert the raster to points as in the first method.

The second approach is the most rational one (first filter, then export only what you're interested in. Converting raster to points can be a time- and memory-consuming operation if you have a lot of cells). But the first one is a good option if you don't have a Spatial Analyst license, for example.

  • Thanks. I will try them both. Which one do you think is faster? – Litwos Sep 2 '16 at 7:49
  • It depends on the number of raster cells and the number of rasters cells = 1. The second option should be more efficient (you filter first and then export), but if you have a limited number of raster cells you might not see a big difference. If almost all your raster cells = 1, there won't be much difference neither. – GISGe Sep 2 '16 at 7:56
  • It works. I used: con_raster = arcpy.sa.Con(out_raster, 1, "", "VALUE = 1") . I will stick with con, because there are a lot of values with 0. Thank you! :) – Litwos Sep 2 '16 at 7:58

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.