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?










share|improve this question









New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
    – Mike T
    Nov 19 at 3:57















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?










share|improve this question









New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
    – Mike T
    Nov 19 at 3:57













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?










share|improve this question









New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 19 at 3:48









Andre Silva

7,026113578




7,026113578






New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 23:39









David Ranzolin

83




83




New contributor




David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






David Ranzolin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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




    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










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)





share|improve this answer

















  • 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




















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 from st_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 (and rgeos) package come from the GEOS library, which assume coordinates to be planar. This is why you get the message st_buffer does not correctly buffer longitude/latitude data (even if you were using degrees in the dist argument).






share|improve this answer

















  • 1




    Good additional information.
    – wl1234
    Nov 19 at 4:00











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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

























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)





share|improve this answer

















  • 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

















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)





share|improve this answer

















  • 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















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)





share|improve this answer












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)






share|improve this answer












share|improve this answer



share|improve this answer










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 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
















  • 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










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














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 from st_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 (and rgeos) package come from the GEOS library, which assume coordinates to be planar. This is why you get the message st_buffer does not correctly buffer longitude/latitude data (even if you were using degrees in the dist argument).






share|improve this answer

















  • 1




    Good additional information.
    – wl1234
    Nov 19 at 4:00















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 from st_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 (and rgeos) package come from the GEOS library, which assume coordinates to be planar. This is why you get the message st_buffer does not correctly buffer longitude/latitude data (even if you were using degrees in the dist argument).






share|improve this answer

















  • 1




    Good additional information.
    – wl1234
    Nov 19 at 4:00













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 from st_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 (and rgeos) package come from the GEOS library, which assume coordinates to be planar. This is why you get the message st_buffer does not correctly buffer longitude/latitude data (even if you were using degrees in the dist argument).






share|improve this answer












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 from st_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 (and rgeos) package come from the GEOS library, which assume coordinates to be planar. This is why you get the message st_buffer does not correctly buffer longitude/latitude data (even if you were using degrees in the dist argument).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 3:41









Andre Silva

7,026113578




7,026113578








  • 1




    Good additional information.
    – wl1234
    Nov 19 at 4:00














  • 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










David Ranzolin is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre