Questions tagged [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.

1040 questions
12
votes
1 answer

Create voronoi polygon with simple feature in R

I'm not sure if I completely understood the help page to create voronoi polygons. library(sf) # function to get polygon from boundary box bbox_polygon <- function(x) { bb <- sf::st_bbox(x) p <- matrix( c(bb["xmin"], bb["ymin"], …
Italo Cegatta
  • 360
  • 3
  • 7
12
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,050
  • 4
  • 20
  • 29
11
votes
3 answers

PROJ4 to PROJ6 upgrade and "Discarded datum" warnings

Context My questions are related to the changes induced by the upgrade from PROJ4 to PROJ6 and the consequences in various R spatial packages (sp, sf, raster). We receive now a lot of warnings about “Discarded datum” that looks a bit worrying and…
Gilles
  • 3,668
  • 13
  • 27
11
votes
1 answer

In R, how do I run st_convex_hull function on point sf object?

I'm trying to get a convex hull of point features in R. library(tmap) library(sf) nc <- st_centroid(st_read(system.file("shape/nc.shp", package="sf"))) qtm(nc) ch <- st_convex_hull(nc) qtm(ch) identical(nc, ch) I'd expect the st_convex_hull to…
radek
  • 6,256
  • 7
  • 48
  • 74
11
votes
1 answer

How to write sf object as shapefile to ESRI file geodatabase with st_write?

How do I write an sf object as a shapefile to a file geodatabase using st_write? I don't quite understand the 'dsn', 'layer', and 'driver' arguments of st_write in relation to file geodatabases. For example, I've tried both of these and no luck…
rhaefer
  • 323
  • 3
  • 6
11
votes
1 answer

Snap a point to the closest point on a line segment using sf

I would like to snap a point to the closest point on a road segment using sf::st_snap. However, the function seems to return the wrong result, it's snapping my point to a point at the start of the road segment. Any ideas on how to fix this?…
rafa.pereira
  • 10,729
  • 4
  • 59
  • 88
11
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
  • 665
  • 5
  • 21
11
votes
3 answers

(Spatial) Efficient way of finding all points within X meters of a point?

I have a large spatial dataset (12M rows). The geometries are points on a map. For each row in the dataset, I'd like to find all the points that are within 500 meters of that point. In r, using sf, I've been trying to do this by parallel looping…
Tim_K
  • 589
  • 7
  • 23
10
votes
3 answers

sf: Write Lat/Long from geometry into separate column and keep ID column

I have a df with polygon ID's from a shapefile and their centre-points in a geometry column: # A tibble: 3 x 2 ID geometry 1 1 (117.2 31.8) 2 2 (116.4 40.1) 3 4 (117.9 26) I want to put the…
Jorrit G
  • 139
  • 2
  • 6
10
votes
0 answers

geom_sf size argument doesn't work when size < 1

Question: I'm trying to create a map of U.S. states/counties with the sf package and geom_sf() from ggplot2, but I can't get the size argument for polygon border line width in geom_sf() to properly create thin lines when size < 1 (e.g.…
sdevine188
  • 258
  • 3
  • 8
10
votes
2 answers

Set the right crs on sf object to plot coordinate points

I'm trying to define the right CRS for my sf object. I want to plot points atop the following layer (country: the Netherlands): Simple feature collection with 380 features and 3 fields geometry type: MULTIPOLYGON dimension: XY bbox: …
Tdebeus
  • 1,211
  • 3
  • 14
  • 36
10
votes
1 answer

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,316
  • 12
  • 29
10
votes
3 answers

Plotting static base map underneath a sf object

I'm trying to plot a static base map underneath my sf object (for print). When using ggmap I first get a lot of errors, then I can't seem to figure out how to chain the base map to my ggplot2 object with a geom_sf. library(sf) #…
Tdebeus
  • 1,211
  • 3
  • 14
  • 36
10
votes
1 answer

Efficient way to plot data on an irregular grid

I work with satellite data organized on an irregular two-dimensional grid whose dimensions are scanline (along track dimension) and ground pixel (across track dimension). Latitude and longitude information for each centre pixel are stored in…
stm4tt
  • 665
  • 5
  • 21
10
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
  • 86,225
  • 12
  • 117
  • 197
1
2
3
69 70