Skip to content

Instantly share code, notes, and snippets.

@jhollist
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhollist/9dda43e9fdbf7b24ebb2 to your computer and use it in GitHub Desktop.
Save jhollist/9dda43e9fdbf7b24ebb2 to your computer and use it in GitHub Desktop.
R script showing problem with turf.js buffers at smaller distances
#load libraries
library(jsonlite)
library(geojsonio)
library(sp)
library(lawn)
library(rgeos)
#create pt
pt<-minify('{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}')
#create lawn.js buffer
lawn_buffer_10<-buffer(pt,10,"meters")
lawn_buffer_50<-buffer(pt,50,"meters")
lawn_buffer_100<-buffer(pt,100,"meters")
lawn_buffer_150<-buffer(pt,150,"meters")
lawn_buffer_250<-buffer(pt,250,"meters")
#convert lawn_buffer_x to json file
toJSON(lawn_buffer_10,auto_unbox = TRUE)%>%
geojson_write("inst/misc/lawn_buffer_10.geojson")
toJSON(lawn_buffer_50,auto_unbox = TRUE)%>%
geojson_write("inst/misc/lawn_buffer_50.geojson")
toJSON(lawn_buffer_100,auto_unbox = TRUE)%>%
geojson_write("inst/misc/lawn_buffer_100.geojson")
toJSON(lawn_buffer_150,auto_unbox = TRUE)%>%
geojson_write("inst/misc/lawn_buffer_150.geojson")
toJSON(lawn_buffer_250,auto_unbox = TRUE)%>%
geojson_write("inst/misc/lawn_buffer_250.geojson")
#create sp point
pt_sp<-SpatialPoints(coordinates(list(x=0,y=0)),CRS("+proj=longlat +datum=WGS84"))
#transfrom to web mercator becuase geos needs project coords
pt_sp_3857<-spTransform(pt_sp,CRS("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"))
#buffer
rgeos_buffer_100<-gBuffer(pt_sp_3857,width=100)
rgeos_buffer_100<-spTransform(rgeos_buffer_100,CRS("+proj=longlat +datum=WGS84"))
geojson_write(rgeos_buffer_100,"inst/misc/rgeos_buffer_100.geojson")
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment