Questions tagged [r-sf]

The motivation behind the `sf` package is to provide a complete, standardized implementation of simple features in R, with links to GDAL, GEOS and Proj.4. There is a also https://gis.stackexchange.com/ for spatial R questions.

sf is a new R package for handling and analyzing spatial data in R. While various R packages are available that provide classes and methods for spatial data (e.g. sp, rgdal and rgeos), sf, which is developed by Edzer Pebesma and others, is intended to gradually replace the well known sp package. The motivation behind this package is to provide a complete, standardized implementation of simple features in R, with links to GDAL, GEOS and Proj.4.

1940 questions
14
votes
4 answers

How to find which polygon a point belong to via sf

I have a sf object that contains polygon information (precincts) for a metro area, obtained through a .shp file. For a given lat/lon pair, I want to determine which precinct it belongs to. I'm thinking I can utilize sf::st_contains() but am having…
kevinykuo
  • 4,600
  • 5
  • 23
  • 31
13
votes
2 answers

Automatic Label Placement for GIS maps in R

I'm making GIS maps in R using the sf package (and related packages) to read in shapefiles, and ggplot2 (and friends) for plotting. This works fine, but I can find no way to (automatically/programmatically) create label placements for features such…
invertdna
  • 171
  • 6
12
votes
1 answer

sf: How to get back to MULTIPOLYGON from GEOMETRYCOLLECTION?

I have a world country dataset, and would like to split it on the prime meridian, and re-center the data to focus on the Pacific. I am trying to do this using Simple Features (sf), but am coming across an object-type issue I can't solve. In order to…
bealhammar
  • 155
  • 1
  • 7
12
votes
2 answers

Create polygons representing bounding boxes for subgroups using sf

I'm attempting to use the sf package and a piped/tidyverse workflow to generate bounding boxes based on groups defined in another column. I think it should work like below, but it seems like st_bbox is not respecting groups. I expect to receive…
Ben Carlson
  • 1,053
  • 2
  • 10
  • 18
12
votes
1 answer

Changing CRS of a SF object

I have some 'roads' as a sp object: class : SpatialLinesDataFrame features : 17360 extent : 490176.4, 567680.9, 148639.1, 212821 (xmin, xmax, ymin, ymax) coord. ref. : +init=epsg:27700 +proj=tmerc +lat_0=49 +lon_0=-2 …
TheRealJimShady
  • 777
  • 3
  • 9
  • 24
12
votes
2 answers

Distances of points between rows with sf

I have multiple trajectories saved in simple feature (sf) of the type POINT. I'd like to calculate the Euclidean distances between subsequent locations (i.e. rows). Until now, I've "manually" calculated distances using the Pythagorean formula for…
Ratnanil
  • 1,641
  • 17
  • 43
12
votes
2 answers

A proper way to plot climate data on an irregular grid

I have asked this question as part of the Efficient way to plot data on an irregular grid question, but the general feedback was to split the original question in more manageable chunks. Hence, this new question. I work with satellite data organized…
stm4tt
  • 755
  • 1
  • 5
  • 22
11
votes
1 answer

Creating Star Map Visualizations Based on Location and Date

Background I am working on trying to create a Celestial map based on a given location and date in R. Ideally the visual would look like this: (Source) I did see this blog which utilized D3 Celestial Maps and was very helpful in creating the visual…
Bensstats
  • 988
  • 5
  • 17
11
votes
2 answers

What should I actually be doing in response to this warning? "Please note that rgdal will be retired by the end of 2023"

I keep noticing this message when I load the rgdal package: "Please note that rgdal will be retired by the end of 2023, plan transition to sf/stars/terra functions using GDAL and PROJ at your earliest convenience." I don't know what this means. Does…
canderson156
  • 1,045
  • 10
  • 24
11
votes
3 answers

How to truly calculate a spherical voronoi diagram using sf?

I want to make a world map with a voronoi tessellation using the spherical nature of the world (not a projection of it), similar to this using D3.js, but with R. As I understand ("Goodbye flat Earth, welcome S2 spherical geometry") the sf package is…
Arthur Welle
  • 586
  • 5
  • 15
11
votes
2 answers

How to get ride of polygon borders using geom_sf in ggplot2

This question has been asked before in an old thread, but the accepted answer does not currently work anymore in the current version of ggplot2. Here is a minimal example: library(ggplot2) library(rnaturalearth) world = ne_countries(scale =…
Miao Cai
  • 902
  • 9
  • 25
11
votes
3 answers

Using r sf::st_write to non-public schema in PostgreSQL

I'm trying to write a spatial table to a schema that is not the default public schema in a PostgreSQL db. library(sf) library(DBI) library(RPostgreSQL) library(spData) # PostgreSQL DB parameters host <- "myHost" port <- 5432 username <-…
mark
  • 537
  • 6
  • 25
11
votes
4 answers

r - Create linestring from two points in same row in dataframe

I was wondering if there is a way to create linestring from two points given in the same row in a dataframe in a new geometry column. In other words longitudes and latitudes of the two points are given in a dataframe like the following: df <-…
adl
  • 1,390
  • 16
  • 36
11
votes
1 answer

Setting Boundaries of Leaflet with sf geometry in R

I would like to use the sf package to extract a bounding box (e.g., st_bbox ) and pass these coords to a leaflet using fitBounds. What is the best way to do this? There is a similar post is here: I don't want to take an average of all coordinates…
KennyC
  • 445
  • 1
  • 9
  • 16
11
votes
2 answers

Create sf object from two-column matrix

I have a simple two-column matrix that I want to convert to an sf object where each row specifies a point: > set.seed(123);m=matrix(runif(10),ncol=2) > m [,1] [,2] [1,] 0.2875775 0.0455565 [2,] 0.7883051 0.5281055 [3,] 0.4089769…
Spacedman
  • 92,590
  • 12
  • 140
  • 224