# Calculate points with angle and distance from a centroid

Here is just a small r-script, which calculates the location of points around a centroid. I had problems with a dataset containing only the angle and the distance of the points and not their exact location. In my case the dataset represents a little forest survey with trees occurring in a given distance from the plots centroid.

require(rgeos);library(rgdal) bsp_sel # my plot data trueCentroids = gCentroid(bsp_sel,byid=TRUE) plot(bsp_sel) points(trueCentroids,pch=2)

# data structure: # Species | Distance (in m) | Angle (in radians degree) ## For example # Spruce | 20.5 | 66 centerPoint <- coordinates(trueCentroids) # Function to calculate for instance the coordinates of the point in 20.5m by 66° from the coordinates of the centerpoint retPoCordinates <- function(center,angle,distance){ x <- round(centerPoint[,1] + distance * cos(angle),0) y <- round(centerPoint[,2] + distance * sin(angle),0) result <- as.data.frame(cbind(x,y));names(result) <- c("x","y") return(result) } pp <- retPoCordinates(centerPoint,data$angle,data$distance) #Saves the coordinates of all trees in the variable pp coordinates(pp) <- ~x+y points(pp,col="green4",pch=19) # Add to plot

#If you want you could furthermore save your SpatialPoint Object as Esri shapefile. Use the tree species as attribute-table #and the spatial projection from your first shape spp <- SpatialPointsDataFrame(coords=coordinates(pp),data=as.data.frame(data$Species),proj4string=CRS(proj4string(bsp_sel))) writeOGR(spp,"shapes","treepoints",driver="ESRI Shapefile",) # Besides you could now calculate a distance matrix between the points or make a test for spatial aggregation and so on... library(dismo) pointDistance(pp,longlat=F) # ...

Go 4 it ! 😉