# Creating line between polygon and nearest raster cell?

I need to create a line between polygons (centroid) and the nearest cell of a raster dataset. The polygon and raster do not intersect. Each polygon has a UID. One cell can be linked to many polygons, but the polygon can only be linked to one cell.

To start, I'm converting the raster to point. From there, I think a Spatial Join needs to be performed using "CLOSEST" as the match option. If I can get the raster cell point to have the polygon UID, I can then use Points to Line with the UID field as the "Line Field" parameter to create an individual line between the two points to connect the polygons to the nearest raster cell.

I tested this on a small area and sample, but it was taking a long time to run each step. In the end, this needs to be performed for hundreds of polygons at a time. Can anyone tell me if I'm on the right track or offer any suggestions to make this work? Some searching has indicated using Near analysis and creating a line from the xy coordinates could be an option as well. Whatever is most efficient.

Making a grid with only values along the boundary would make the raster to point processing faster, as described here. I'm still not sure if the rest of the process is going to work correctly.

Your method is OK, but converting a grid to a set of point usually creates very large feature dataset that are heavy to manipulate.

Another idea would be to take advantage of the grid structure : regular spacing. For each polygon,

1) compute the coordinates of the centroid (calculate geometry )

2) deduce the coordinates of the center (or of the corner, whatever your prefer) of the lower left cell (X centroid - X lower left cell, Y centroid - Y lower left cell )

3) divides the coordinates by the cell size (now you are in relative "cell" coordinates)

4) Round (not truncate) the coordinate (this will bring you to the closest cell)

5) multiply by the cell size

6) add the lower left cell coordinates (you are back in map coordinates)