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
19
votes
1 answer

R: Handling of sf objects in raster package

Previously I was using raster::crop and raster::mask with shapefiles of class Spatial*, read in using rgal::readOGR. I am just "upgrading" my scripts to use sf for reading and manipulating polygons. raster::crop raster::crop expects an 'extent'…
pat-s
  • 5,992
  • 1
  • 32
  • 60
18
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,519
  • 5
  • 21
  • 43
18
votes
1 answer

Mapping different states with geom_sf using facet wrap and scales free

First, I am aware of this answer : Mapping different states in R using facet wrap But I work with object of library sf. It seems that facet_wrap(scales = "free") is not available for objects plotted with geom_sf in ggplot2. I get this…
Sébastien Rochette
  • 6,536
  • 2
  • 22
  • 43
17
votes
4 answers

Convert sequence of longitude and latitude to polygon via sf in R

I have five longitude and latitude that form a shape like this. df <- c(order=1:5, lon=c(119.4,119.4,119.4,119.5,119.5), lat=c(-5.192,-5.192,-5.187,-5.187,-5.191)) How could I easily convert them into an sf polygon data frame using…
rasyidstat
  • 585
  • 2
  • 6
  • 17
17
votes
1 answer

Dissolving polygon features with the sf package

Dissolve is a common geoproccessing technique discussed as an sf approach here. I'm trying to replicate dissolve as it functions in ArcGIS. Consider counties by two groups in ArcGIS. The ArcGIS dissolve command yields two polygons, regardless of the…
ReginaldMilton
  • 279
  • 1
  • 2
  • 8
16
votes
1 answer

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
  • 338
  • 3
  • 8
15
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,519
  • 5
  • 21
  • 43
15
votes
3 answers

Can't remove gridlines when plotting with geom_sf

The standard means of removing gridlines seem futile when plotting with geom_sf. For instance, if we plot a simple ggplot object, this works to remove the grid library(tidyverse) library(sf) mtcars %>% ggplot( aes(disp, hp) ) + …
tomw
  • 3,114
  • 4
  • 29
  • 51
14
votes
1 answer

Reading shape file with sf::st_read fails to capture encoding UTF8

I want to read a shape file which is encoded in UTF8. It works fine when I read it using rgdal::readOGR but sf::st_read fails to get the correct Encode. Any suggestions on how to solve this? For a reproducible example, the shape file I'm trying to…
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
14
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
  • 7,240
  • 8
  • 58
  • 83
14
votes
3 answers

R Overlay points and polygons with a certain degree of tolerance

Using R, I would like to overlay some spatial points and polygons in order to assign to the points some attributes of the geographic regions I have taken into consideration. What I usually do is to use the command over of the sppackage. My problems…
Nemesi
  • 781
  • 3
  • 13
  • 29
14
votes
1 answer

Creating a regular polygon grid over a spatial extent, rotated by a given angle

Hi all, I am struggling with this and hope someone could come out with a simple solution. My objective is to create a regular polygon grid over the extent of a polygon, but rotated by a user-defined angle. I know that I can easily create a…
lbusett
  • 5,801
  • 2
  • 24
  • 47
14
votes
1 answer

Find nearest features using sf in R

I'm wanting to find the nearest polygons in a simple features data frame in R to a set of points in another simple features data frame using the sf package in R. I've been using 'st_is_within_distance' in 'st_join' statements, but this returns…
mweber
  • 739
  • 1
  • 6
  • 17
14
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
  • 659
  • 10
  • 24
14
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
  • 410
  • 4
  • 8