Questions tagged [sf]

us this tag when asking questions about sf R package (sf: Simple Features for R)

Filter by
Sorted by
Tagged with
7
votes
2answers
7k views

How to calculate distance from POINT to LINESTRING in R using `sf` library and get all POINT features from LINESTRING where distances were calculated?

I'm trying to calculate distances from a set of POINT features (1, 2, 3, 4, 5, 6 & 7) to a LINESTRING feature using sf library in R. I could calculate all the distances using the function ...
8
votes
5answers
10k views

Identify polygon containing point with R sf package

I would like to be able to map geocoded coordinates to a region on a .shp file in R using the sf package. I can load up the map and plot it but I am struggling with the code to return the region for ...
8
votes
1answer
3k views

Split polyline by point using 'sf' package in R

I'm learning the sf package in R and would like to locate about 450 sites along the nearest reaches of a river network and to obtain the upstream and downstream distances along the reach where the ...
1
vote
2answers
104 views

“non finite transformation detected” using sp R

This is a part of a broader question already posted (Non finite transformation detected - lidR spTransform) but I am creating a new question for the sp related part of that. I'm trying to reproject ...
3
votes
5answers
4k views

Find nearest point along polyline using 'sf' package in R

This is a follow-up question related to my earlier post about using the sf package to split polylines using nearby points. I have 450 points with XY coordinates and a large river network (~214,000 ...
2
votes
1answer
1k views

Choosing CRS / PROJ4 string for EURO-Cordex rotated pole projection?

I have to analyze some CORDEX models which have a rotated pole projection. The projection is described in this document, see page 10, Table 1, row "Europe high res". I have tried to describe the ...
22
votes
4answers
13k views

Crop simple features object in R

Is there a function to crop sf map object, similar to maptools::pruneMap(lines, xlim= c(4, 10), ylim= c(10, 15)) used for SpatialPolygon or SpatialLine? I am considering st_intersection() but there ...
5
votes
2answers
2k views

Combining st_join with st_nn to include all points within, as well as within a given distance of a polygon

This is a follow up to my earlier question (Spatial join in R - Adding points to polygons with multiple corresponding points). I have successfully joined a spatial points file to a polygon file in R ...
4
votes
1answer
366 views

fit two sf polygons seamlessly

Copied from my SO question 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 ...
4
votes
1answer
1k views

How to I limit the x and y axes with tmap in r

I have made this plot with the following code: library(tmap) tm_shape(RH2) + tm_fill(col="AREAL") + tm_borders() But there is a dot on the far right (an island) which I don't ...
10
votes
1answer
10k views

Create a circle of defined radius around a point and then find the overlapping area on a shapefile

My use case is related to calculating the area of a polygon in a shapefile that is covered by another polygon. Specifically, I want to do the following: Create circles that have a 100m radius, from ...
3
votes
2answers
4k views

Find nearest line segment to each point in R

I've seen similar questions, but not with R. I have a sf object with approx 500000 thousand points. I also have an sf object of lines. Each line has a unique segment number called 'segnum'. For each ...
2
votes
1answer
114 views

Reproject using WKT for just the horizontal CRS

I'm trying to reproject LiDAR point clouds from California zone 2 (ftUS) using spTransform from sp R package to a metric CRS like EPSG 3857 (initial post here) and got non finite transformation ...
2
votes
2answers
6k views

How to use st_buffer?

I would like to calculate a buffer of 5km around country polygons. However, I somehow always get a warning and an error. Here is a reproducible example code. library(sp) library(sf) library(tmap) ...
1
vote
1answer
66 views

Why do these coordinates not display correctly (or intersect correctly) with this boundary file?

This is a follow up to my previous question. I wrote code that imports the boundaries of a few US states, and, for some arbitrary point within those boundaries, buffers a circle around that point and ...
1
vote
1answer
326 views

How to update CRS r object from PROJ4 to PROJ6

I have a script which contains several r objects which are CRSs that I use for transforming spatial objects. After updating R and many packages, there is a warning which wasn't there before. LCC <- ...
0
votes
1answer
54 views

Test intersections with time indicators in R

I have a sf object with MULTIPOLYGONS that refers to flood episodes from 1800's onwards(https://data.gov.uk/dataset/16e32c53-35a6-4d54-a111-ca09031eaaaf/recorded-flood-outlines). Then I have another ...
1
vote
1answer
3k views

Fastest way to extract a raster in R (improve the time of my reproducible code)

I'm wondering if I have maximized the speed at which a mean of an area buffered around a point in a raster can be extracted. Fastest way I have ever found to extract a raster, with the pre-cropping ...
10
votes
1answer
2k views

r - create multipolygon from overlapping polygons using sf package

I'm trying to remove overlapping areas from multiple polygons using sf like the following: # sample polygon poly <- data.frame( lon = c(0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 2, 2, 0.8, 1, 1, 2, ...
8
votes
3answers
2k views

Return end-vertices of an sf linestring

I am trying to return the vertices of a linestring using the sf package. So far I have: ls <- st_sfc(st_linestring(rbind(c(0,0),c(0,1))), st_linestring(rbind(c(0,0),c(10,0)))) ...
7
votes
3answers
3k views

Split a line when it crosses a polygon in R

This should be a simple problem but I can't seem to find a solution. I have a line which crosses several polygons and I want to split it into multiple lines at the intersection of each polygon using ...
3
votes
1answer
2k views

Convert a linestring into a closed polygon when the points are not in order

How can I convert an open linestring into a closed polygon, but when the points are not in order? Here is the easy case, when the points are in order (from an sf vignette): library(sf) #> Linking ...
2
votes
2answers
2k views

Using simple features (sf) in R, how do I erase polygons overlapping with another layer

With a regular spatialDataFrame I could use erase(x, y) or x-y. How can I perform the equivalent using sf objects? As an example: ##Create layers based on this answer: http://stackoverflow.com/...
18
votes
1answer
10k views

Simplify polygons of sf object

How do I simplify an sf polygon without introducing gaps and slivers? With a shapefile, for example, I would use rmapshaper::ms_simplify(): library("pryr") library("rgdal") library("rmapshaper") ...
6
votes
2answers
2k views

Converting points to polygons by group

I have a dataframe with around 40 points. They are grouped by an ID variable (their name), which four points in each group. I'm trying to turn these points into polygons, but I've had a lot of trouble ...
5
votes
1answer
3k views

Counting points in polygons with sf package of R? [closed]

I'm quite new to R and especially GIS with R. So recently I had to proceed to a quite simple analysis: counting health centers (points) per administrative unit (polygons). Quite common process in ...
5
votes
1answer
1k views

Creating an sf object from the maps package

I am trying to use data from the maps package in an sf workflow. I'm not sure if I have the operation correct (see below). It seems to work until state 20 (massachusetts). What am I doing wrong? Maybe ...
4
votes
1answer
635 views

Spatial 1 to 1 join by proximity in sf and R?

I'm trying to join a Simple Feature of POINT geometry type to another Simple Feature of POLYGON geometry type using st_join and nngeo::st_nn as the person asking this other question also did. The ...
1
vote
1answer
239 views

Cluster geometries that touch each other

I'm trying to cluster the geometries in a sf object that touch each other. For the moment I'm using the same approach that it's explained in the answer here, but the problem is that the same idea ...
4
votes
1answer
3k views

Load a CSV as Simple Features R

Is there a direct way to load a CSV as an sf? I've looked through the sf documentation and nothing jumps out at me, currently using: my_csv <- read.csv('my_data.csv', header = TRUE) my_sp <- ...
3
votes
1answer
218 views

CRS validity and PROJ versions

I'm not sure where the right place to raise this is, so: The PROJ strings for EPSG codes 4151 and 4283 are identical: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs which is a hassle ...
2
votes
1answer
133 views

Updating GeoPackage records with R

I'd like to update records of a GeoPackage containing vector information in R. I've tried this: library(sf) library(RSQLite) nc <- st_read(system.file("shape/nc.shp", package="sf")) # Write Geo ...
1
vote
1answer
46 views

Intersect points and polygons

I have a dataset where I'm trying to look determine determine which polygons my sampling locations occur in. I have been following the example here: https://gis.stackexchange.com/questions/282750/...
1
vote
1answer
53 views

Merge sub-regions of multiple regions

First, let's set up the data. Download adjoining Seoul, Incheon, Gyeonggi-do region shapefiles from this website (in Korean). I attach the files, as they are not accessible outside Korea. Then read ...
1
vote
1answer
79 views

Making a for loop/function testing geometries' intersections for multiple time-units in R

I have two multipolygons and I want to test intersections between their geometries based for different cycles of years. Basically I have a flood dataset that contains flood events and their geometry ...
1
vote
0answers
159 views

Exported GeoPackage from R not drawing in ArcMap

I am trying to export multiple layers of point data from R as a single GeoPackage. The code works fine (included below), however when I try and load the resulting GeoPackage into ArcMap (10.6) I get ...
1
vote
1answer
1k views

How to read a csv dataset with multipoint column in sf

i have a csv with a multipoint WGS84 column: head(df, n=3) CUP the_geom <chr> <chr> 1 ...
1
vote
3answers
3k views

st_intersection failing for overlapping multipolygons in sf

I'm working with some user classification data on a citizen science platform. The way our workflow works is to take multiple user classifications of areas, overlay them on one another, and then look ...
1
vote
1answer
181 views

How do I create a shapefile of circles of varying radii around lat/long points and map the overlap onto another shapefile?

I have a shapefile of US counties downloaded from the Census, a set of points, and a calculated radius around each point. I'm trying to draw a circle of that radius around each point, then plot the ...
0
votes
1answer
30 views

Combine and categorize shapes

I wish to combine multiple shapefiles for different regions and assign them names in R/sf. I'm not sure if my procedure is orthodox. That may also be the reason for the incorrect boundary box which ...
0
votes
0answers
38 views

R terra and `Error in x@ptr$geometry(nlyrs) : could not find valid method`

i am using terra::raster 0.9-1 and, specifically terra::values and the xyz function in terra::rast, but i keep encountering the following Error in x@ptr$geometry(nlyrs) : could not find valid method &...
0
votes
1answer
983 views

Use sf (R) to return the overlapping area between two polygons by rows?

I have two sfc data frames with the same number of rows (individual IDs), but each data frame contains a polygon assigned to the individual. For example, dataframe1 may have a circle assigned neared ...