Questions tagged [sf]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
25 views

Get rid of overhang beyond masking border in ggmap?

I built a terrain map of Nevada and plot the state border around it. The resulting map has a buffer-like overhang across the state border which I used to mask the raster. How can I get rid of the ...
0
votes
2answers
35 views

R and sf - How to know this exists, data(us_states), without first using, (requireNamespace(“sf”, quietly = TRUE))

I am not new to using R, but I am newer to using the sf package, or any other similar geospatial packages. I can easily explore and subset the world dataset and then plot the map of the US - which ...
0
votes
0answers
13 views

How do you create a column computing area in SF with a SpatialPolygonDataFrame?

I am attempting to add a column that provides the area of my HUC_12 watershed polygons to a watershed data set, but the only code online that demonstrates how to do this is using the raster library, ...
1
vote
0answers
25 views

Calculating nearest distance with nngeo

I need to calculate the nearest distance between objects (schools). I have two sf-data-frames with lon/lat. The way I understand the output of st_nn is, that dist gives me the minimum distance to the ...
0
votes
0answers
31 views

Why is st_write not saving this dataframe as a shapefile?

I have been working with sf package for several weeks now. I have been able to figure out the solution of problems by myself or searching on forums. However, this one has been demanding too much time ...
1
vote
1answer
30 views

Finding vertices of polygons for calculating offsets in R

I am working on an application where a user can select a land plot (sf_POLYGON) by clicking on it. Once selected (highlighted plot no. 6 in the figure), I then need to calculate some "offsets&...
1
vote
1answer
25 views

How to save polygons generated from raster extents to shapefile in R

I'm looping through a list of rasters, getting the bounding box for each from raster@extent, and storing the matrices representing each polygon in a list. I'd ultimately like to save to shapefile ...
1
vote
1answer
20 views

Adding an “M” coordinate (dimension) to an sf object in R?

Is there a way to add an "M" coordinate (dimension) to an sf object in R? As far as I can tell, currently, only the "Z" coordinate can be added using the "st_zm()" function.
2
votes
1answer
52 views

Why does the area of overlap with st_intersection not match my expectation?

I'm using the protected area shape files from Protected Planet for Swaziland/ Eswatini. I calculate a home range (95% kernel density) and want to measure the overlap in area between this and the ...
2
votes
1answer
27 views

Axis labels with geom_sf & ggmap

I'm trying to create a map using a basemap pulled in using ggmap (get_stamenmap) with some shapefiles plopped on top (geom_sf). I want to change axis labels! Why's it so difficult! When I only plot ...
0
votes
0answers
27 views

Reading nested .kmz files

I'm trying to read a folder containing ~80,000 .kmz files of vector data using sf::st_read. The top-level folder contains a single large .kml file that I expect ties all of the other folders/data ...
0
votes
1answer
37 views

sf: SpatialGridDataFrame vs SpatialPixelsDataFrame: Processing, Visualization and Storage

I'm trying to understand what are the differences between an SpatialGridDataFrame and SpatialPixelsDataFrame. My final goal is to process some raster (readed with raster package and tif format) and ...
1
vote
1answer
58 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
33 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
85 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
36 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
42 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
48 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
26 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
26 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
49 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
40 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
43 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 ...
0
votes
1answer
22 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
31 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
15 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
33 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
47 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
61 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
30 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
56 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
25 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
27 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
75 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
2answers
221 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
183 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
38 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
33 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
78 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
59 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 ...
0
votes
2answers
116 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
39 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
56 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....
0
votes
2answers
118 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
33 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
58 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
38 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
103 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
65 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
49 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 ...

1
2 3 4 5 6