Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get bounding box for coordinates in columns of dataframe

I have a dataframe with two columns of type numeric.

foo <- data.frame(replicate(2,sample(10.1:15.2,100,rep=TRUE)))

    X1 X2
1 13.1 15.1
2 13.1 11.1
3 13.1 15.1
4 10.1 13.1
5 15.1 11.1
6 13.1 11.1
...

These numbers represent coordinates in 4326. X1 is latitude, X2 is longitude. How would I get the bounding box for all these coordinates?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Convert to sf and use st_bbox:

library(sf)

foo %>% 
  st_as_sf(coords = c("X2","X1"), crs = 4326) %>% 
  st_bbox()

# xmin ymin xmax ymax 
# 10.1 10.1 15.1 15.1 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading