0

I am trying to made multiple concentric circles of multiple radii in kms scaled to a map, similar this post was using the post here (ggmap: create circles).

map.sp<-readShapeSpatial("C:file.shp")

plot(map.sp,xlim=c(143.4, 144), ylim=c(-13.4, -13))#"SpatialPolygonsDataFrame"

d8 <- data.frame(lat = c(-13.177047), lon = c(143.949718))
coordinates(d8) <- ~ lon + lat
projection(d8) <- "+init=epsg:4326"
d_mrc8 <- spTransform(d8, CRS = CRS(projection(map.sp)))

library(scales) # for `alpha()` function
library(rgeos) #for gBuffer function
d_mrc_bff8 <- gBuffer(d_mrc8, width = 100) # Buffer creation

plot(d_mrc_bff8, col = alpha("blue", .35), add = TRUE)
points(d_mrc8, cex = 2, color="red",pch = 20) 

All commands finish without any error messages.

My map is produced within the correct x and y limits and the final point is plotted (although in black not red).

However, no buffer is created.

Further information below about the specific "SpatialPolygonsDataFrame" file I am using.

coord. ref: +proj=longlat +ellps=WGS84

Extent: 138.0012, 153.5516, -29.17855, -10.34855  (xmin, xmax, ymin, ymax)
  • Its hard to understand what you are trying to do here without flicking backwards and forwards to the question you linked to. Could you forget about that question, and rewrite this as a self-contained question? It might end up simpler. – Spacedman Apr 17 '18 at 7:09
  • Hi @Spacedman, I have edited the post so that it now incorporates the original post I was referring to. You should now not need to flick backwards and forwards. – LiveLongandProsper Apr 19 '18 at 3:25
  • When you say "gBuffer doesn't work" you don't say how it doesn't work. Error message? Wrong output? gBuffer works perfectly on SpatialPolygonsDataFrames. – Spacedman Apr 19 '18 at 6:31
  • Hi @Spacedman, I have done two rounds of edits now, please see if they are appropriate or require further explanation. – LiveLongandProsper Apr 21 '18 at 3:59
  • 1
    Everything here seems to be in latitude-longitude coordinates, so your buffer has a radius of 100 degrees, so when you plot it over an existing map its probably not visible because its a circle way outside the map. You need your data in a coordinate system of the units you want to buffer before you buffer it. – Spacedman Apr 21 '18 at 7:40
0

Based on Spacedman's clues and other Stackexchange posts, here is what I came up with:

1) map.sp is plotted in latitude-longitude coordinates, however, the default input for gBuffer is degrees.

2) Convert my input (kms) to degrees using formula: n km / 40,000 km * 360

https://stackoverflow.com/questions/5217348/how-do-i-convert-kilometres-to-degrees-in-geodjango-geos

3) The input is now in correct units and is correctly plotted on the map.

  • There are a few misleading things to warn you about with this answer: (1) the default units for gBuffer are the same as the spatial reference system, so they could be metres, feet, degrees, etc., it depends (2) that formula to "convert kms to degrees" is approximate, and should only be used around the equator (3) be suspicious while interpreting your resulting map as it may only seem "correct". – Mike T Apr 23 '18 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.