Last active
August 29, 2015 14:16
-
-
Save jhollist/9dda43e9fdbf7b24ebb2 to your computer and use it in GitHub Desktop.
R script showing problem with turf.js buffers at smaller distances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "FeatureCollection", | |
"features": [ | |
{ | |
"type": "Feature", | |
"geometry": { | |
"type": "Polygon", | |
"coordinates": [ | |
[ | |
[ | |
0.0009, | |
0 | |
], | |
[ | |
0.0009, | |
-0.0002 | |
], | |
[ | |
0.0008, | |
-0.0003 | |
], | |
[ | |
0.0007, | |
-0.0005 | |
], | |
[ | |
0.0006, | |
-0.0006 | |
], | |
[ | |
0.0005, | |
-0.0007 | |
], | |
[ | |
0.0003, | |
-0.0008 | |
], | |
[ | |
0.0002, | |
-0.0009 | |
], | |
[ | |
5.5103e-20, | |
-0.0009 | |
], | |
[ | |
-0.0002, | |
-0.0009 | |
], | |
[ | |
-0.0003, | |
-0.0008 | |
], | |
[ | |
-0.0005, | |
-0.0007 | |
], | |
[ | |
-0.0006, | |
-0.0006 | |
], | |
[ | |
-0.0007, | |
-0.0005 | |
], | |
[ | |
-0.0008, | |
-0.0003 | |
], | |
[ | |
-0.0009, | |
-0.0002 | |
], | |
[ | |
-0.0009, | |
6.8909e-19 | |
], | |
[ | |
-0.0009, | |
0.0002 | |
], | |
[ | |
-0.0008, | |
0.0003 | |
], | |
[ | |
-0.0007, | |
0.0005 | |
], | |
[ | |
-0.0006, | |
0.0006 | |
], | |
[ | |
-0.0005, | |
0.0007 | |
], | |
[ | |
-0.0003, | |
0.0008 | |
], | |
[ | |
-0.0002, | |
0.0009 | |
], | |
[ | |
2.2326e-18, | |
0.0009 | |
], | |
[ | |
0.0002, | |
0.0009 | |
], | |
[ | |
0.0003, | |
0.0008 | |
], | |
[ | |
0.0005, | |
0.0007 | |
], | |
[ | |
0.0006, | |
0.0006 | |
], | |
[ | |
0.0007, | |
0.0005 | |
], | |
[ | |
0.0008, | |
0.0003 | |
], | |
[ | |
0.0009, | |
0.0002 | |
], | |
[ | |
0.0009, | |
0 | |
] | |
] | |
] | |
}, | |
"properties": { | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment