I am using R and have a SpatialGrid object similar to the example from this question:
## read shapefile
library("rgdal")
shp <- readOGR("nybb_13a", "nybb")
proj4string(shp) # units us-ft
# [1] "+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333
# +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0 +datum=NAD83
# +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0"
### define coordinates and convert to SpatialPointsDataFrame
poi <- data.frame(x=c(919500, 959500, 1019500, 1049500, 1029500, 989500),
y=c(130600, 150600, 180600, 198000, 248000, 218000),
id="A", stringsAsFactors=F)
coordinates(poi) <- ~ x + y
proj4string(poi) <- proj4string(shp)
### define SpatialGrid object
bb <- bbox(shp)
cs <- c(3.28084, 3.28084)*6000 # cell size 6km x 6km (for illustration)
# 1 ft = 3.28084 m
cc <- bb[, 1] + (cs/2) # cell offset
cd <- ceiling(diff(t(bb))/cs) # number of cells per direction
grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)
grd
# cellcentre.offset 923018 129964
# cellsize 19685 19685
# cells.dim 8 8
sp_grd <- SpatialGridDataFrame(grd,
data=data.frame(id=1:prod(cd)),
proj4string=CRS(proj4string(shp)))
I have a SpatialGrid rather than SpatialGridDataFrame, so:
new_sp_grd <- SpatialGrid(grd,proj4string=CRS(proj4string(shp)))
I now want to calculate the centre coordinates of each grid cell, so that I can calculate the distance between this point and a variety of SpatialLines and SpatialPolygons objects.
Can anyone suggest how to do this? There is help for finding the centre of a polygon, but not a grid, and functions such as gCentroid from the rgeos package do not work on SpatialGrids.

value(X/Y) = bbox min X and Y + cellsize/2 offset. Then every cell in the grid will have the coordinates:X = valueX + cellsize*columnandY = valueY + cellsize*row– caiohamamura Jul 27 '16 at 15:11