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

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.…
dad
  • 1,335
  • 9
  • 28
40
votes
2 answers

How to resolve spherical geometry failures when joining spatial data

I have a shapefile (with several polygons) and a dataframe with coordinates. I want to assign each coordinate in a dataframe to a polygon in a shapefile. So to add a column in a data frame with a polygon name or id Here is the link to the data…
yuliaUU
  • 1,581
  • 2
  • 12
  • 33
40
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
  • 509
  • 2
  • 5
  • 6
39
votes
3 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
  • 441
  • 1
  • 4
  • 4
27
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,801
  • 2
  • 24
  • 47
25
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
  • 2,408
  • 2
  • 22
  • 45
24
votes
1 answer

Why use st_intersection rather than st_intersects?

st_intersection is very slow compared to st_intersects. So why not use the latter instead of the former? Here's an example with a small toy dataset, but the difference in execution time is huge for my actual set of just 62,020 points intersected…
syre
  • 902
  • 1
  • 7
  • 19
24
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
  • 4,548
  • 7
  • 36
  • 64
24
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
  • 20,038
  • 30
  • 112
  • 189
23
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,941
  • 1
  • 25
  • 43
21
votes
4 answers

Removing holes from polygons in R sf

Is there a way to remove holes from a polygon in R with the package sf? I would be interested in solutions that include other packages, too. Here's an example of a polygon with two holes. library(sf) outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2,…
Duccio A
  • 1,402
  • 13
  • 27
20
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 San Martin
  • 4,224
  • 1
  • 18
  • 31
20
votes
3 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
  • 13,251
  • 6
  • 71
  • 109
19
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
  • 473
  • 2
  • 4
  • 8
19
votes
4 answers

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
  • 13,251
  • 6
  • 71
  • 109
1
2 3
99 100