简体   繁体   中英

Plot Circle on Raster with Known Coordinates and Radius

I am attempting to plot circles with a defined radius onto a raster image. I have successfully plotted my raster and put points onto the image:

# open image to save    
png("RasterImage.png",
        width=10, height=10, units="in", res=144)

# plot raster
    plot(VI.SOS.mean, main="VI Mean SOS",
         col=terrain.colors(length(seq(100,220,20))-1), axes=F, breaks=seq(100,200,20))

# add points
    points(sensors$X, sensors$Y)

# close png file
    dev.off()

This is what the resulting image looks like:

栅格图像

The pixels in my raster are 30 m:

class       : RasterLayer 
dimensions  : 2871, 3205, 9201555  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 254265, 350415, 4731885, 4818015  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=16 +datum=WGS84 +units=m +no_defs 
data source : in memory
names       : layer 
values      : 38.6, 309  (min, max)

What I would like to do is put a circle with radius x (for example, 300 m) at each of the points. I can manually do this by messing with the size of the points (using cex , for example), but if I either change the dimensions of the image or crop my raster, then the circles are no longer the correct size. Is there a way to put circles on the map using the units defined in the raster?

Thanks!

You can try this:

library(dismo)
cs <- circles(sensors[, c('X','Y')], d=150)
plot(VI.SOS.mean)
plot(polygons(cs), add=TRUE)

Overlapping circles are merged. If you do not want that, you can use the internal function dismo:::.generateCircles

pls <- dismo:::.generateCircles(sensors[, c('X','Y')], d=150, lonlat=FALSE, crs=NA)
plot(pls, add=TRUE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM