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.
r-sf
276
questions
41
votes
3
answers
14k
views
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 ...
42
votes
2
answers
20k
views
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 ...
20
votes
4
answers
7k
views
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 ...
20
votes
4
answers
13k
views
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 ...
50
votes
3
answers
35k
views
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
<dbl> <POINT [°]>
1 1 (117.2 31.8)
2 2 (116....
9
votes
3
answers
3k
views
How to fix degree symbol not showing correctly in R on Linux/Fedora 31
Any map I make with:
ggplot() + geom_sf()
produces the expected map, but does not show the degree sign correctly, as appears from the following picture.
The answer given in this answer on SO - ...
5
votes
2
answers
1k
views
Visual bug when changing Robinson projection's central meridian with ggplot2
I am attempting to project a world map in a Robinson projection where the central meridian is different from 0. According to this StackOverFlow thread, it should be an easy thing (albeit the example ...
-1
votes
1
answer
531
views
Sf package: Close a polygon fom complex shape
Almost two weeks that my students and I are trying to find a solution on a trivial problem.
We want to calculate the distance between two GPS points avoiding the coast according to this tutorial: ...
8
votes
1
answer
3k
views
Select multiple items using map_click in leaflet, linked to selectizeInput() in shiny app (R)
I would like to create a leaflet map where you can select multiple polygons and this will update the selectizeInput() in a shiny app. This would including removing a selected polygon, when it is ...
8
votes
1
answer
2k
views
Find coordinates x distance along linestring
I would like to extract the coordinates of a point at a known distance along the linestring, starting from one end of the linestring.
For example:
library(sf)
path <- st_as_sfc('LINESTRING(10 20, ...
6
votes
2
answers
5k
views
Split line by multiple points using sf package
I am trying to split a large line shape by pairs of points along the line. Based on previous questions asked mainly by @mbcaradima here, here, here and here, I have put together some code which works ...
2
votes
1
answer
232
views
R: Creating a Matrix to Store Join Results
I have these two shapefiles in R:
file_1:https://www12.statcan.gc.ca/census-recensement/alternative_alternatif.cfm?l=eng&dispext=zip&teng=lada000b21a_e.zip&k=%20%20%20151162&loc=//...
26
votes
2
answers
28k
views
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 feature data frame. How can I create that?
I thought it might ...
21
votes
3
answers
8k
views
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 ...
21
votes
4
answers
8k
views
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)
...