[R-sig-Geo] Create circular polygon of certain radius in R

Robert J. Hijmans r.hijmans at gmail.com
Wed Jun 8 20:47:58 CEST 2016


For lon/lat coordinates, you can use the circles function in "dismo":

library(dismo)
r <- raster(system.file("external/rlogo.grd", package="raster"))
pts <- data.frame(x=c(17, 42, 85, 70, 20, 53, 26, 84), y=c(28, 73, 38,
56, 0, 29, 63, 22))

c1 <- circles(pts, lonlat=FALSE, d=9, dissolve=FALSE)
c2 <- circles(pts, lonlat=TRUE, d=1000000, dissolve=FALSE)

plot(r)
plot(geometry(c1), border='red', lwd=2, add=TRUE)
plot(geometry(c2), border='blue', lwd=2, add=TRUE)



On Wed, Jun 8, 2016 at 9:04 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Wed, 8 Jun 2016, Bede-Fazekas Ákos wrote:
>
>> Hi Giacomo,
>>
>> you should use a projection that is planar (azimuthal). Select one planar
>> projection, use spTransform() from sp package to transform your data to the
>> selected planar projection, and then everything will works fine.
>
>
> Right, this is what rgeos is warning about. I'm afraid, though, that since
> the raster is in geographical coordinates, that may entail transforming the
> circle back from planar coordinates (+units=m) to geographical coordinates,
> and then the number of border line segments may also matter. Had the
> workflow been in projected coordinates from an earlier point, this would be
> simpler.
>
> Roger
>
>
>> Some links:
>>
>> https://en.wikipedia.org/wiki/Map_projection#Azimuthal_.28projections_onto_a_plane.29
>> http: //spatialreference.org/ref/epsg/
>> http: //www.inside-r.org/packages/cran/rgdal/docs/spTransform
>>
>> HTH,
>> Ákos Bede-Fazekas
>> Hungarian Academy of Sciences
>>
>> 2016.06.08. 13:26 keltezéssel, Giacomo May írta:
>>>
>>>  Hi,
>>>  I have a raster, which is projected into "+proj=longlat +datum=WGS84
>>>  +no_defs +ellps=WGS84 +towgs84=0,0,0". Now I would like to create a
>>>  circular Polygon with a radius of 300 meters around a cell of my choice.
>>> I
>>>  know about the function "spCircle()" in the package "sampSurf" and I
>>> heard
>>>  that this should somehow be possibleusing the "gBuffer"-function from
>>> the
>>>  "rgeos"-package, but I don't know exactly how to use it.
>>>  I have tried achieving this with the following piece of code (altdata is
>>>  the raster I am using):
>>>
>>>  coords <- xyFromCell(altdata,12703)
>>>  proj <- altdata at crs@projargs
>>>  coords_sp <- SpatialPoints(coords,CRS(proj))
>>>  polygon <- gBuffer(coords_sp,width=300)
>>>
>>>  But this returns the following warning message:
>>>
>>>  Warning message:
>>>
>>>  In gBuffer(coords_sp, width = 300) :
>>>     Spatial object is not projected; GEOS expects planar coordinates
>>>
>>>  If anyone could help me with this I would be deeply grateful.
>>>  Best regards,
>>>  Giacomo May
>>>
>>>  _______________________________________________
>>>  R-sig-Geo mailing list
>>>  R-sig-Geo at r-project.org
>>>  https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
> http://depsy.org/person/434412
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list