ArcGIS Error 000864 – Creating Unique Cell Values for Raster

arcgis-desktoperror-000864

I have a raster which shows the probability that a cell will be used (raster_Use). I also have a points file that shows mortality locations (points_Morts). I have overlain points_Morts onto raster_Use and extracted the probability of use for each mortality location. I also need to extract the cell ID from raster_Use for each mortality point in points_Morts. I've tried converting the raster_Use to a polygon but I've received the following error:

ERROR 000864 Input raster: The input is not within the defined domain.
ERROR 000863: Invalid GP data type.

I read in another thread that a solution is to change the raster values from a float to an integer. I've tried that but the resulting raster only contained 0s because the values are between 0 and 1 and thus rounding down to 0. My next thought is to create another raster that's identical to raster_Use that contains 1…n unique values and then extract those values to the points_Morts file. I can't figure out how to do so.

Does anyone have an idea of how to do so?


@Luke provided a great answer, but unfortunately it doesn't quite work. To expand on why it doesn't, identifying the column and row numbers creates a key for the points file but there still isn't a key for all cells in raster_Use. So I know which cells points_Morts falls in, however, I don't know the ID for cells in raster_Use that don't contain points from points_Morts. I tried converting raster_Use to a points object and then implemented @Luke's solution, but the Raster to Points tool creates 4 points for every raster cell instead of 1. Ideally, I would like to start with a cell (e.g., the lower left corner cell) and assign it a value of 1 then continue onto the next cell assigning a value in ascending order.


I misunderstood Luke's question on "why?" I'm doing this. I am validating the predictive ability of a model. Raster_Use is my prediction and points_morts is my validation dataset. I'm validating my model by grouping the cells from raster_Use into 20 equal-area bins. Expected use is the predicted value for each grid cell. I place these cells into 20 equal-area bins and then summed by bin and standardize to 1. Observed use is the frequency of mortality locations in each grid cell, summed by bin and then standardized to 1. After that, I'll use linear regression to regress observed vs predicted use where the slope of the regression relationship between observed and expected provides an assessment of the predictive abilities of the model.

Best Answer

You can calculate an incrementing ID based on the row and column numbers which will uniquely identify the cell that the points are in.

Add a column to your point feature class named CELLID (type = long integer).

In the field calculator, select the python parser, tick the show code-block box and in the pre-logic script code section enter:

import arcpy

def calc_cell_id(shape, raster):

    raster = arcpy.Raster(raster)
    xmin = raster.extent.XMin
    ymax = raster.extent.YMax
    px = raster.meanCellWidth
    py = raster.meanCellHeight
    ncols = raster.width

    col = int(abs((xmin - shape.getPart(0).X) / px))
    row = int(abs((ymax - shape.getPart(0).Y) / -py))

    id = row * ncols + col + 1

    return id

In the "CELLID = " section enter:

calc_cell_id( !SHAPE!, "NAME_OF_YOUR_RASTER_LAYER")

For example:

enter image description here

To create a raster with the same values, open the ArcMap python window and enter the following:

raster = arcpy.Raster("NAME_OF_YOUR_RASTER_LAYER")

arcpy.env.extent = raster
arcpy.env.mask = raster
arcpy.env.cellSize = raster
arcpy.env.extent = raster

ncols = raster.width

arcpy.gp.singleoutputmapalgebra("$$ROWMAP * %s + $$COLMAP + 1" % ncols, "path/to/save/your/output_unique_id_raster")
Related Question