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
1,995
questions
11
votes
2
answers
5k
views
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
votes
1
answer
242
views
How can I do 3D distance calcs using the R "simple features" library `sf`?
I have just recently started using nice and the relatively new library(sf). It's nice to see that points and lines can have Z coordinates. For example:
> st_linestring(rbind(c(0,0,0),c(1,1,1)))
...
26
votes
3
answers
14k
views
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 ...
3
votes
3
answers
2k
views
row-wise operations on sf objects
I'm having some trouble with rowwise operations on sf objects, where the geometry is polygon type.
sf functions inside by_row don't seem to work e.g. the following should create a list-column holding ...
1
vote
0
answers
248
views
st_read() error: NULL pointer returned by GetGeomFieldRef
Problem:
A NULL pointer was returned while reading ShalePlay_Bakken_Isopach_EIA_08Jan2015.shp from this EIA zip file.
library(sf)
tmp_file <- tempfile()
tmp_dir <- tempdir()
zp <- "https:/...
5
votes
1
answer
2k
views
Cannot get alpha to work with ggplot2::geom_sf on sf linestring object
This requires the libraries sf and ggplot2 in R. I have a sf object with 4 linestrings. 3 of these are identical and one is extended:
a <- st_linestring(rbind(c(2,2), c(3,3), c(3,2)))
b <- ...
0
votes
1
answer
2k
views
read multiple `.shp` file as one object?
how to read multiple .shp file as one object?
I want to read simply like under the code.
nc <- st_read(dsn = "nc",
layer = c("nc1","nc2"))
what is the best method to read multiple ...
2
votes
1
answer
684
views
Install a github package alongside a CRAN package with the same name?
Is there any reasonable way to install a CRAN package alongside a github package of the same name?
Specifically, I am after the geom_sf() geom in the sf branch in the ggplot2 github page: https://...
15
votes
4
answers
9k
views
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 ...
1
vote
0
answers
73
views
R function will not coerce sf data.table
I am trying to coerce only certain columns in my sf data.table from character to numeric. When I write the code out without a function it works.
columns <- c("STATEFP", "COUNTYFP", "TRACTCE", "...
6
votes
1
answer
1k
views
spatial join on two simple features {sf} with over 1 mil. entries as fast as possible
I hope this is not too trivial but I really can't find an answer and I'm too new to the topic to come up with alternatives myself. So here is the Problem:
I have two shapefiles x and y that represent ...
9
votes
2
answers
3k
views
whole earth polygon for world map in ggplot2 (and sf)
When plotting world maps there is a problem with ggplot2: it colours the whole background with the same colour, including the corners of the plot which aren't actually part of the globe, see the ...
20
votes
1
answer
7k
views
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. ...
11
votes
3
answers
4k
views
Aggregate POLYGONs to MULTIPOLYGONs and keep data.frame
I have a sf object of POLYGON geometry type. I would like to aggregate these polygons into MULTIPOLYGONs using grouping attribute (group_attr) and join a new MULTIPOLYGON object with a attribute table....
0
votes
1
answer
2k
views
Reading a shapefile and plot with geom_sf returns error
I wish to plot some maps of Denmark using the new sf package and geom_sf() from ggplot2. I have a shapefile from a public map service, with a total of 4 files (DK.shp, DK.dbf, DK.shf and DK.prj). I ...