How to buffer a pair of longitude and latitude coordinates in R?
up vote
1
down vote
favorite
I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet
or mapview
. st_buffer
, however, does not correctly buffer longitude/latitude data.
Initial code:
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df)
#....
# Something goes here, but I don't know what?
#...
st_buffer(df_sf, 500)
Warning message:
In st_buffer.sfc(st_geometry(x), dist, nQuadSegs) :
st_buffer does not correctly buffer longitude/latitude data
What's the missing piece?
coordinate-system r buffer latitude-longitude sf
New contributor
add a comment |
up vote
1
down vote
favorite
I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet
or mapview
. st_buffer
, however, does not correctly buffer longitude/latitude data.
Initial code:
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df)
#....
# Something goes here, but I don't know what?
#...
st_buffer(df_sf, 500)
Warning message:
In st_buffer.sfc(st_geometry(x), dist, nQuadSegs) :
st_buffer does not correctly buffer longitude/latitude data
What's the missing piece?
coordinate-system r buffer latitude-longitude sf
New contributor
1
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet
or mapview
. st_buffer
, however, does not correctly buffer longitude/latitude data.
Initial code:
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df)
#....
# Something goes here, but I don't know what?
#...
st_buffer(df_sf, 500)
Warning message:
In st_buffer.sfc(st_geometry(x), dist, nQuadSegs) :
st_buffer does not correctly buffer longitude/latitude data
What's the missing piece?
coordinate-system r buffer latitude-longitude sf
New contributor
I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet
or mapview
. st_buffer
, however, does not correctly buffer longitude/latitude data.
Initial code:
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df)
#....
# Something goes here, but I don't know what?
#...
st_buffer(df_sf, 500)
Warning message:
In st_buffer.sfc(st_geometry(x), dist, nQuadSegs) :
st_buffer does not correctly buffer longitude/latitude data
What's the missing piece?
coordinate-system r buffer latitude-longitude sf
coordinate-system r buffer latitude-longitude sf
New contributor
New contributor
edited Nov 19 at 3:48
Andre Silva
7,026113578
7,026113578
New contributor
asked Nov 18 at 23:39
David Ranzolin
83
83
New contributor
New contributor
1
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57
add a comment |
1
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57
1
1
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Your point should be in a Projected Coordinate System. If it is in a geographic coordinate system, the values will be in decimal degrees.
I am not sure what you use over there, but I have picked NAD83 California Albers, which uses metres as its unit.
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df) %>% st_transform(3488) #transform to NAD83(NSRS2007) / California Albers
df_sf_buff <- st_buffer(df_sf, 500)
plot(df_sf_buff)
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely insf
with:df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't needrgdal
orrgeos
.
– Spacedman
Nov 19 at 8:41
add a comment |
up vote
1
down vote
In order to make st_buffer
to output correct results, make sure:
- the CRS unit is the same as the one used in the
dist
argument fromst_buffer
.
AND,
- the CRS is in a projected coordinate system (i.e., with planar coordinates), as stated in wl1234's answer. This is because the geometrical operations from
sf
(andrgeos
) package come from the GEOS library, which assume coordinates to be planar. This is why you get the messagest_buffer does not correctly buffer longitude/latitude data
(even if you were using degrees in thedist
argument).
1
Good additional information.
– wl1234
Nov 19 at 4:00
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Your point should be in a Projected Coordinate System. If it is in a geographic coordinate system, the values will be in decimal degrees.
I am not sure what you use over there, but I have picked NAD83 California Albers, which uses metres as its unit.
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df) %>% st_transform(3488) #transform to NAD83(NSRS2007) / California Albers
df_sf_buff <- st_buffer(df_sf, 500)
plot(df_sf_buff)
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely insf
with:df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't needrgdal
orrgeos
.
– Spacedman
Nov 19 at 8:41
add a comment |
up vote
1
down vote
accepted
Your point should be in a Projected Coordinate System. If it is in a geographic coordinate system, the values will be in decimal degrees.
I am not sure what you use over there, but I have picked NAD83 California Albers, which uses metres as its unit.
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df) %>% st_transform(3488) #transform to NAD83(NSRS2007) / California Albers
df_sf_buff <- st_buffer(df_sf, 500)
plot(df_sf_buff)
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely insf
with:df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't needrgdal
orrgeos
.
– Spacedman
Nov 19 at 8:41
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Your point should be in a Projected Coordinate System. If it is in a geographic coordinate system, the values will be in decimal degrees.
I am not sure what you use over there, but I have picked NAD83 California Albers, which uses metres as its unit.
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df) %>% st_transform(3488) #transform to NAD83(NSRS2007) / California Albers
df_sf_buff <- st_buffer(df_sf, 500)
plot(df_sf_buff)
Your point should be in a Projected Coordinate System. If it is in a geographic coordinate system, the values will be in decimal degrees.
I am not sure what you use over there, but I have picked NAD83 California Albers, which uses metres as its unit.
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df) %>% st_transform(3488) #transform to NAD83(NSRS2007) / California Albers
df_sf_buff <- st_buffer(df_sf, 500)
plot(df_sf_buff)
answered Nov 19 at 2:35
wl1234
767
767
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely insf
with:df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't needrgdal
orrgeos
.
– Spacedman
Nov 19 at 8:41
add a comment |
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely insf
with:df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't needrgdal
orrgeos
.
– Spacedman
Nov 19 at 8:41
2
2
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely in
sf
with: df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't need rgdal
or rgeos
.– Spacedman
Nov 19 at 8:41
If you want to avoid all the faff of building a point using sp::coordinates, you can do it purely in
sf
with: df = st_sfc(st_point(cbind(-121, 37)),crs=4326)
- then you don't need rgdal
or rgeos
.– Spacedman
Nov 19 at 8:41
add a comment |
up vote
1
down vote
In order to make st_buffer
to output correct results, make sure:
- the CRS unit is the same as the one used in the
dist
argument fromst_buffer
.
AND,
- the CRS is in a projected coordinate system (i.e., with planar coordinates), as stated in wl1234's answer. This is because the geometrical operations from
sf
(andrgeos
) package come from the GEOS library, which assume coordinates to be planar. This is why you get the messagest_buffer does not correctly buffer longitude/latitude data
(even if you were using degrees in thedist
argument).
1
Good additional information.
– wl1234
Nov 19 at 4:00
add a comment |
up vote
1
down vote
In order to make st_buffer
to output correct results, make sure:
- the CRS unit is the same as the one used in the
dist
argument fromst_buffer
.
AND,
- the CRS is in a projected coordinate system (i.e., with planar coordinates), as stated in wl1234's answer. This is because the geometrical operations from
sf
(andrgeos
) package come from the GEOS library, which assume coordinates to be planar. This is why you get the messagest_buffer does not correctly buffer longitude/latitude data
(even if you were using degrees in thedist
argument).
1
Good additional information.
– wl1234
Nov 19 at 4:00
add a comment |
up vote
1
down vote
up vote
1
down vote
In order to make st_buffer
to output correct results, make sure:
- the CRS unit is the same as the one used in the
dist
argument fromst_buffer
.
AND,
- the CRS is in a projected coordinate system (i.e., with planar coordinates), as stated in wl1234's answer. This is because the geometrical operations from
sf
(andrgeos
) package come from the GEOS library, which assume coordinates to be planar. This is why you get the messagest_buffer does not correctly buffer longitude/latitude data
(even if you were using degrees in thedist
argument).
In order to make st_buffer
to output correct results, make sure:
- the CRS unit is the same as the one used in the
dist
argument fromst_buffer
.
AND,
- the CRS is in a projected coordinate system (i.e., with planar coordinates), as stated in wl1234's answer. This is because the geometrical operations from
sf
(andrgeos
) package come from the GEOS library, which assume coordinates to be planar. This is why you get the messagest_buffer does not correctly buffer longitude/latitude data
(even if you were using degrees in thedist
argument).
answered Nov 19 at 3:41
Andre Silva
7,026113578
7,026113578
1
Good additional information.
– wl1234
Nov 19 at 4:00
add a comment |
1
Good additional information.
– wl1234
Nov 19 at 4:00
1
1
Good additional information.
– wl1234
Nov 19 at 4:00
Good additional information.
– wl1234
Nov 19 at 4:00
add a comment |
David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.
David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.
David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.
David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f303126%2fhow-to-buffer-a-pair-of-longitude-and-latitude-coordinates-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
Nov 19 at 3:57