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
    yesterday















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
    yesterday













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 yesterday









Andre Silva

7,006113577




7,006113577






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 2 days ago









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
    yesterday














  • 1




    Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
    – Mike T
    yesterday








1




1




Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
yesterday




Take a look at gis.stackexchange.com/a/121539 to dynamically project each point using aeqd
– Mike T
yesterday










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
    yesterday




















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
    yesterday











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
    yesterday

















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
    yesterday















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 2 days ago









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
    yesterday
















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










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
yesterday






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
yesterday














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
    yesterday















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
    yesterday













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 yesterday









Andre Silva

7,006113577




7,006113577








  • 1




    Good additional information.
    – wl1234
    yesterday














  • 1




    Good additional information.
    – wl1234
    yesterday








1




1




Good additional information.
– wl1234
yesterday




Good additional information.
– wl1234
yesterday










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

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt