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
26
votes
3 answers

Efficient extraction of all sub-polygons generated by self-intersecting features in a MultiPolygon

Starting from a shapefile containing a fairly large number (about 20000) of potentially partially-overlapping polygons, I'd need to extract all the sub-polygons originated by intersecting their different "boundaries". In practice, starting from…
lbusett
  • 5,191
  • 2
  • 18
  • 43
22
votes
1 answer

fit two sf polygons seamlessly

The problem Suppose we have two shapefiles that should border seamlessly. Only, they don't. Is there a way to force them to stick to one another without gaps? The specific case I have two shapefiles: one for European regions -- REG, the other for…
ikashnitsky
  • 2,511
  • 20
  • 38
22
votes
2 answers

How to put a geom_sf produced map on top of a ggmap produced raster

I tried the following code: library(ggplot2) library(ggmap) library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) str(nc) Classes ‘sf’ and 'data.frame': 100 obs. of 15 variables: $ AREA : num 0.114 0.061 0.143 0.07 0.153…
user1453488
  • 271
  • 2
  • 4
20
votes
0 answers

Why does tmap render 80 times faster than ggplot2? [Plotting shapefiles in R with ggplot2::geom_sf(), using XQuartz/X11 graphics device on macOS]

Update/Edit/Reprex: Rendering the same spatial data with the same graphics device takes 1 second with tmap versus 80 seconds with ggplot2, even though the tmap plot's R object is 80x larger in size. Difference in internals and/or implementation btw.…
spoompls
  • 603
  • 4
  • 17
20
votes
3 answers

How can I do a spatial join with the sf package using st_join()

Here's a toy example I've been wrestling with # Make points point1 <- c(.5, .5) point2 <- c(.6, .6) point3 <- c(3, 3) mpt <- st_multipoint(rbind(point1, point2, point3)) # create multipoint # Make polygons square1 <- rbind(c(0, 0), c(1, 0),…
Ben
  • 15,465
  • 26
  • 90
  • 157
18
votes
2 answers

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
  • 4,656
  • 1
  • 27
  • 49
14
votes
2 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
  • 2,746
  • 3
  • 25
  • 44
14
votes
2 answers

how to make a data frame into a simple features data frame?

I've got a table with place references and x and y coordinates in a given coordinate reference system. I want to turn that into a simple features data frame. How can I create that? I thought it might be: data_frame(place = "London", lat…
wdkrnls
  • 3,946
  • 2
  • 29
  • 52
14
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
  • 5,901
  • 2
  • 14
  • 39
13
votes
1 answer

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
13
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,191
  • 2
  • 18
  • 43
13
votes
1 answer

How to calculate centroid of polygon using sf::st_centroid?

I am trying to manipulate some Brazilian Census data in R using the new "sf" package. I am able to import the data, but I get an error when I try to create the centroids of the original polygons library(sf) #Donwload data filepath <-…
LucasMation
  • 1,886
  • 2
  • 15
  • 38
12
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
  • 634
  • 10
  • 24
12
votes
2 answers

Convert a list of sf objects into one sf

I have a list of sf objects that I would like to row bind to create a single sf object. I'm looking for a function similar to data.table::rbindlist, that would stack the individual objects in an efficient manner. Data for reproducible…
rafa.pereira
  • 10,729
  • 4
  • 59
  • 88
12
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
  • 455
  • 4
  • 14
1
2 3
69 70