Questions tagged [sf]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
280 views

Convert raster to polygons, crop, reproject

I wish to map a high-resolution grid of population counts of Korea and extract from it the Seoul Capital Area (SCA) at the same level of resolution. The population data comes in two forms: raster (...
2
votes
1answer
43 views

Calculate the diameter of an `sf` object

The diameter of a set of points in a metric space is defined as the supremum of all pairwise distances between points in the set. So in the case of the earth's surface, the diameter of a (closed) set ...
3
votes
1answer
585 views

Calculate percentage overlap of 2 sets of polygons in R

I have a map of NC counties. I have overlayed two circles, representing the coverage area of two radio transmitters in the state: ### Make transmitters df rm(list = ls()) library(tidyverse) library(...
1
vote
1answer
161 views

I want to create a Voronoi diagram while retaining the data in the data frame

We will use st_voronoi() to create a Voronoi diagram. I have three questions. Point one. I understand that the argument to st_voronoi() should be the following data. ■SFC format (an error occurs ...
1
vote
0answers
45 views

Shapes from different sources are offset

I am looking for a reliable shapefile of the Seoul Capital Area (SCA), comprising Seoul, Incheon and Gyeonggi-do provinces. One common source is GADM. However, the coastline is not up-to-date so I ...
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 ...
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 ...
-2
votes
1answer
91 views

Converting .csv (.geo column in sf package) to shapefile in R [closed]

I have extracted values from raster layers and now want to convert it to shapefile. The CSV file contains values of different bands and one column .geo in sf package. Any ideas to convert the CSV file ...
3
votes
1answer
105 views

st_transform from GRS80 returns empty geometries

I wish to transform a set of South Korean province shapes from CRS (Coordinate Reference System) GRS80, but st_transform returns empty geometries. I have downloaded the dataset from this page (in ...
1
vote
0answers
54 views

Split polygon by polygon

I have a polygon which I want to split using overlapping polygons in order to create 3 polygons (with the original attributes) How can i achieve it using R ?
1
vote
2answers
49 views

Most efficient way to find points in a polygon (polygon always rectangular)

This question has been asked a lot by a lot of different people I am sure. I did some searching and found some blog posts and potential ways forward, but before I dove off into the deep end I thought ...
1
vote
1answer
122 views

How to calculate the distance of points to line in R?

I need the distance from each point of the object found to the transect line. 'id' is a research transect, and 'obj.id' is the object found. in this case, 1 object was found in transect A and 2 ...
1
vote
2answers
90 views

sf::st_crs() compatibility across different versions of PROJ

I am supporting an package that serves {sf} objects using EPSG:4326 as default projection; I have little control over the setup my users have (some rely on defaults, others compile from source). I ...
0
votes
1answer
26 views

Detect lines not connected to the main network R

How could I autodetect lines not touching the principal net in R? In this example I would like to remove the top right line. I already know how to select and delete lines by their lengths but that ...
0
votes
1answer
68 views

st_transform reprojection issue with R and sf

According to https://geocompr.robinlovelace.net/reproj-geo-data.html i tried to reproject world map to Lambert with st_transform from sf package library(spData) library(sf) library(tmap) # test ...
0
votes
0answers
136 views

GDAL conflicts between GDAL and PostGIS versions in R

I'm trying to learn postgis and I'm using R as an interface to make queries under Linux. I'm using GEOS 3.8.0, GDAL 3.0.4 and PROJ 7.0.0. When everything is up-to-date my R ecosytem (sp, sf, rgdal) is ...
0
votes
0answers
165 views

Raster overlay on sf object

Question: why does a raster object plot over an object of class "SpatialPolygonsDataFrame" but incorrectly over an object of class "sf"? I am working with this raster. I'd like to overlay it on a ...
1
vote
1answer
140 views

How to merge groups of touching lines to multilinestring

I would like to join groups of lines into multilinestrings if they touch. In the plot below, I should get two objects of sf class MULTILINESTRING from the 6 lines. What is an easy way of doing this (...
1
vote
1answer
138 views

Splitting overlap between polygons and assign to nearest polygon using R?

My question is how to perform the process described in the answer to this similar question in R, ideally using the sf package. In the linked case this is done using using PostGIS with some sf commands,...
1
vote
1answer
33 views

st_intersection by id

I create two buffer around points and want to intersect the two buffers by id (creating a doughnut) around each point. With st_intersection I can only manage to get all possible intersections, ...
1
vote
0answers
55 views

How do I exclude certain districts from an R `tmap` city plot using `osmdata`?

I am trying to plot only District (quan) 1 of Ho Chi Minh city, and the wards (phuong) within it, in an aesthetically pleasing way. Despite reading the osmdata vignette and help, I can't work out how ...
1
vote
1answer
316 views

Change system:index of FeatureCollection in GEE

I have a FeatureCollection with points loaded from an asset (shapefile). Since the system:index is empty, gee assigns a weird index to each feature (e.g. 000000000001, 0000000000a). This causes ...
5
votes
3answers
365 views

R - Voronoi polygons from lines

I use R (and sf, mainly) and I was wondering if it's possible to create Voronoi polygons starting from LINESTRING objects instead of POINT. For example, given a sfc such as # package library(sf) #&...
1
vote
3answers
337 views

Snapping points outside a polygon to the polygons in R

I have records of where certain species breed on mainland New Zealand and I want to model where these tend to be. However, partly due to some projection errors, as well as potential measurement errors,...
0
votes
0answers
78 views

Point to line distance using dist2Line and 'sf' library

I need to calculate the distance from a set of points to the closest line. I followed the approach outlined here. dist_plsscentroid_rail <- geosphere::dist2Line(p = st_coordinates(...
0
votes
2answers
36 views

Merge sf() shapefile with CSV using shared field (by.x)

From what I can tell, sf() merge doesn't support comparison operations by.x etc. Is there a feasible way to mesh two data sets, one of which is a simplefeature and the other a basic table from CSV or ...
2
votes
1answer
161 views

nngeo- nearest neighbor with distance dataframe

I'm working with some spatial data and I want to turn the output of the st_nn command (outputs a list) into a data frame that I can join. For example library(nngeo) library(tidyverse) cities <- ...
1
vote
1answer
182 views

R sf aggregate polygons at various geographic levels

I'm trying to aggregate polygons at different geographic levels. As a hypothetical and reproducible example, let's suppose that I want to aggregate US county data set at the state level (of course, I ...
1
vote
2answers
388 views

Why is st_buffer function not creating an R object that correctly displays in mapview?

Trying to get st_buffer function to display a buffer within mapview. Got it to work, but I had to first perform a transform (I doubt this is necessary). Looking for a more straightforward way to do ...
2
votes
0answers
99 views

Shapefile calculation error: 'list' object cannot be coerced to type 'integer'

I'm trying to identify which of two regions within a shapefile specific spatial points lie. To this I used this code. This worked well but I ended with a lot of NAs because my 1/3 of my points are ...
3
votes
1answer
153 views

Accessing ArcGIS Online feature dataset from R using R-ArcGIS Bridge

I can successfully connect to an ArcGIS Pro feature dataset stored on my local computer in a file geodatabase in R like so: library(arcgisbinding) library(sf) arc.check_product() districts <- arc....
1
vote
2answers
308 views

Using r and sf, create an concave envelope POLYGON around MULTILINESTRING

I am interested in creating the minimum possible polygon around a set of nearly parallel cross sections. For example: mls <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(...
1
vote
0answers
34 views

ggmap to get travel distance from dataframe

I am trying to use the mapdist() function from the ggmap package to get travel distances from coordinates in a dataframe. # need an api key to use the ggmap function register_google(key = "") ...
3
votes
1answer
95 views

Generate a stars object from tabular spatial temporal data?

I have tabular data with columns longitude, latitude, time, and intensity, like so: library(lubridate) ## mock example data ex <- tibble(longitude = 1:10, latitude = 10:1, ...
1
vote
1answer
71 views

Adding new polygon attribute column based on location withing another polygon in R

I have here an example with two layers - one containing two large polygons Pol_large, and second containing 4 small polygons Pol_small. For Pol_small I want now to find the location of each of the ...
1
vote
1answer
342 views

Read CSV file in R using sf()

I can see that it's possible to load in csv data to R (as per here: Load a CSV as Simple Features R), however, it appears to me that there is a limitation on the range of delimiters allowed given the ...
0
votes
1answer
161 views

Splitting overlapping polygons in a layer and creating new ones with merged attributes in R

I have a large shapefile with plenty of overlapping polygons. From the areas where they intersect, I would like to create new polygons (and thus split the original ones). I would like to also to merge ...
2
votes
0answers
59 views

Optimising use of st_within for parallelisation

I'm trying to use st_within() to calculate points within polygons on a fairly complex shapefile. This operation tends to take 4-5 hours which is a bummer for debugging the code. I have access to a ...
2
votes
2answers
811 views

Check for intersection of raster and vector in R

I have a rasterstack and a vector-geometry (sf-object). The raster's values are either ǸA or some integer. I would like to check if the raster (in the best case just as a binary response) has any ...
1
vote
1answer
48 views

Sample random points on the borders of the US states with sf package

I want to sample points (latitude-longitude pairs) on borders of the US states, or points close to borders. With the following code, I am able to sample points in an example multipolygon. How can I do ...
2
votes
2answers
127 views

For each cell with value 1 in a raster, create a raster with only that value

I have a binary raster in R. It has only 55 cells with value 1 and all the others have value 0 or NA. Now I want to write 55 rasters. For each cell with value 1, I want to write one raster. In these ...
1
vote
1answer
2k views

Converting raster layer to simple feature in R [closed]

I have read my raster data using r <- raster("F:\\Studies\\Whole2015.tif") class(r) > class(r) [1] "RasterLayer" attr(,"package") [1] "raster" How can I transform my data to simple feature? I ...
1
vote
1answer
489 views

Creating multiple polygons from a list of coordinate matrices using sf in R

I'm trying to create an sf object representing the extents of geometry objects in an existing sf object. I would expect that st_polygon() could create a list of polygon objects directly from a list of ...
-1
votes
1answer
58 views

Spatially join linestrings (which can overlap or not overlap) in R and provide output in a data format that I can add other variables

I am using R to exam road infrastructure. The sf dataset I am using is very granular e.g. for the same road two or three observations may exist that are differentiated by different coloured tarmac ...
3
votes
1answer
146 views

MapBox studio distorts and removes polygons in tileset

I'm having an issue uploading a large polygon tileset to mapbox studio from an R simple features object. From R i've projected my simple features to web mercator and i've tried saving either as shp (...
0
votes
1answer
180 views

sf :: st_intersection() returning duplicate features

Why does st_intersection add duplicate lines to my sf data frame? sf_points Simple feature collection with 156421 features and 9 fields geometry type: POINT dimension: XY bbox: xmin:...
-1
votes
1answer
49 views

Weird problem with st_polygon in the sf package

I would like to create a simple polygon using the sf package. From my understanding, I have to create a two column matrix where the last row is identical to the first one to close the ring of the ...
5
votes
3answers
2k views

R - Find “n” closest points to each point in SpatialPointsDataFrame

I am working with a dataset that is similar to this one: library(raster) library(sf) # Define CRSs crs.latlon <- "+init=epsg:4326" crs.sirgas <- "+init=epsg:5880" # define edges in somewhere ...
0
votes
2answers
206 views

Get approximately n points inside a polygon sf R

I need to get approximately n points in a pattern as regular as possible inside a polygon. Current code: library(tidyverse) library(sf) library(raster) library(ggplot2) n_points_wanted = 200 ...
0
votes
0answers
83 views

List of sf-object into one sf-object

that's a really simple question but I am kind of stuck with it. I have a list with multiple sf-objects and I want to put all sf-objects (dataframe) under each other and build one final sf-object. How ...

1 2
3
4 5
8