Questions tagged [sf]
Use this tag when asking questions about the R package sf (Simple Features for R)
679
questions
0
votes
2
answers
34
views
Create a sf from bounding box coordinates (and compare to another sf) in R
I want to create a sf from bounding box coordinates and compare it to another sf to see if it intersects. When I use the code below it doesn't seem to work:
I can't plot the sf as I get the error ...
0
votes
1
answer
19
views
Color code sf points object by category in R
I am trying to color code an sf points object in R, but can't quite figure out how to do it. I want the NAs to show up as a separate category. Here is the code I have so far.
dat = data.frame(utmn = c(...
0
votes
1
answer
31
views
R - sf package - custom proj4string
I am doing some geospatial analysis and am having a difficult time finding an appropriate CRS to transform the data to. I am using two resources to look up CRS codes.
https://resources.arcgis.com/en/...
0
votes
1
answer
68
views
How to speed up a spatial filter query for polygon-features that intersect with a sf-POINTs object in R
I have large geopackage (around 2.5 million features, about 3Gb) with spatial polygons representing all agricultural fields in my country. Most of them are shaped rectangular-ish. I don't need this ...
0
votes
0
answers
47
views
Create an i graph object with sf objects using the i graph package in R to perform a network analysis
I would like to create an i graph object out of two sf objects. The first one includes the edges represented by polylines, in that case rivers. The second one includes vertices that lie on the river ...
2
votes
2
answers
55
views
Filtering hexagons using sf
I stumbled across this answer because I want to create a fine hexagon grid. The answer works; however, R freezes when I try to filter a large amount of hexagons (smaller ones) using the provided code
...
1
vote
1
answer
72
views
Why do st_union and dplyr::summarise produce different results, with summarise giving me the object I want?
I have a file with 2013 geographical boundaries for NZ. The file looks like:
and the file overview is
I used to work with the rgdal and rgeos packages, and am now updating the code so that it works ...
0
votes
1
answer
173
views
How to bind two sf objects based on matching values in one column in r
I have two sf objects. The first has one object with 3 variables and the second 2 objects with 3 variables. The data looks like this:
Table 1
| River | length | geometry |
| ------ | ------ | --...
0
votes
0
answers
42
views
How can I move each polygon in a multipolygon file to a random new location within bbox?
I am trying to reassign the coordinates for every polygon in a multipolygon file, so that each would be placed in a random new location in a defined bounding box, while preserving its attributes. The ...
0
votes
1
answer
121
views
Using st_buffer and st_intersection on geocode point geometries in R
I am starting with a CSV of addresses that have been put through a geocoding software to give lat and long. I want to turn that in an sf object, create a buffer and see the intersections with polygon ...
0
votes
1
answer
48
views
Polygons in shapefile that are close are drawn far away: how make the close polygons be drawn together?
I have a shapefile with terrestrial birds conservation regions (https://birdscanada.org/download/gislab/bcr_terrestrial_shape.zip?_ga=2.173557475.1349516436.1715087042-735583731.1713557857) from the ...
0
votes
0
answers
13
views
I am using BioOracle data and reducing it to 1 point per cell but when I try to covert to a sf grid, I end up having issues
I am using multiple BioOracle layers as geotiff files and reducing it to 1 point per cell, but when I try to convert to an SF grid, I end up having issues. I keep receiving an error stating:
Error in ...
0
votes
1
answer
66
views
Creating lines between points with the same ID and calculating centroid in R
I have the following dataframe with an ID column and XY point coordinates. It's a simple case with only two points per line (dataframe only has ID pairs):
data <- data.frame(
id = c("1C1&...
1
vote
0
answers
64
views
How to properly use BlockCV method of cross validation in dismo MaxEnt model in R?
This is what I have right now, but the model looks exactly the same as it does without the cross validation. The .html it spits out has no "training" data in the ROC curve or sensitivity ...
0
votes
1
answer
68
views
St_nearest_point
I have two dataframe with coordination values, I want to match each point of my dataset2 with the nearest point in my dataset1, then use its value.
I tried transfered them into sf object then using ...
3
votes
1
answer
101
views
Transforming an sf feature without M-values into one with M-values
Basic question
Working with the sf library in R, how can I add M-values to a geometry that doesn't already have them?
Or put differently, given an sf feature without M-values, how can I create a new ...
1
vote
3
answers
229
views
Convert vector data to terra raster where vector points are center of tiles with irregular grid
I would think there should be a simple solution to this, but I can't figure it out.
I have a csv file with the following data
wealth_data <- read.csv(text ="latitude,longitude,rwi,error
-2....
1
vote
0
answers
92
views
How to create subnetworks with sfnetworks in R
I would like to create subnetworks from a spatial network:
library(sfnetworks)
library(sf)
library(tidygraph)
library(igraph)
net = as_sfnetwork(roxel, directed = FALSE) %>%
...
0
votes
1
answer
56
views
Aggregation with st_buffer in EPSG 4326 versus other CRS
I am trying to find the total sum of homicides within a 1km buffer around each police agency where the homicides were reported. I tried the R code below and it seemed to produce numbers that made ...
0
votes
0
answers
83
views
R How to Split MULTISTRING sf objects Based on Points
I have grouped connected lines and now would like to split these lines into smaller groups based on points. I have found a couple of examples of how to do this with LINESTRING geometries but not with ...
2
votes
1
answer
133
views
Splitting a polyline with multiple features on specific point locations with the function st_split in R
I would like to split a river network with points that locate directly on the river network itself (Snapped them in QGIS). I used the st_split function sufficiently in R, however the function also ...
0
votes
1
answer
150
views
R st_intersects gives out sgbp file [closed]
Basically I have a data frame with coordinates variables and other variables, and another SHP file provides polygones geographic information:
I want to find out which points are inside these polygones ...
0
votes
1
answer
99
views
Transforming R data.frame with column of GeoJSON strings into sf object
Suppose I have a data.frame object that has a column called geojson with GeoJSON strings in each row.
How can I transform this data.frame into an sf object that would allow me to perform geospatial ...
0
votes
3
answers
83
views
Add a point to an existing (multi)linestring
This question is related to this one.
I want to clip a polygon to a line, but that line doesn't fully bisect my polygon. If I could add another point to the line, the lwgeos::st_split() function ...
1
vote
1
answer
142
views
How to convert simple feature collections of geometry type POLYHEDRALSURFACE to MULTIPOLYGON?
Messing around with CityGML data in order to obtain building footprints, I found a solution using ogr2ogr to extract individual layers to "more common" vector data formats some time ago in a ...
0
votes
1
answer
114
views
Split "MULTILINESTRING" by its own vertices using SF in R
I need to split a multilinestring layer by the vertices:
I've been trying to do this and nothing seems to work. I'm sure this is something really simple to do.
Using this example:
# Load required ...
0
votes
1
answer
113
views
SF Tessellation not working [closed]
I am fairly new to using sf and R in general and I keep running into a frustrating problem. I'm using the method outlined in this tutorial and I am getting the following messages:
Warning messages:
1: ...
0
votes
1
answer
92
views
Generating polygons with a target area from points using st_buffer
I have some point geometries which I want to turn into polygons using st_buffer. For each point I have a target area that the resulting polygon should have. Here's an example using R:
library(sf)
# ...
0
votes
0
answers
93
views
st_intersection is duplicating rows
I'm using the sf package in R to understand how land cover changed from forest fires in BC, by overlapping burned areas (NBAC) with data from Dynamic World (DW). I have the DW data in the form of 5km ...
0
votes
0
answers
53
views
Splitting sf layer into individual segments like QGIS explodelines tool does
I have loaded my road network data into R as an sf object. I would like to split each line into individual segments (split at each vertex).
I have used the qgisprocess package and it works. Here is ...
0
votes
1
answer
506
views
Clipping sf vector by terra raster extent with R
I am trying to do something fairly simple: I want to clip a vector with point features down to only features that are contained within a raster extent. For raster I am using the package terra, for ...
0
votes
0
answers
89
views
R sf package - upgrade PROJ
Using Rstudio, I need a projection that is not available in the PROJ version I have (see that question).
> library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
I would ...
0
votes
0
answers
60
views
Using 'rasterize' to create raster of overlapping polygons
I have found similar questions, but most use different packages.
I have a shapefile with 20 multipolygons, with a few attributes.
All I want is to create a raster whereby each raster cell's value is ...
0
votes
1
answer
50
views
Rotate stars raster object around the centroid in st_geotransform
I'd like to use an affine transformation to translate and rotate a stars object around the centroid. As far as I understand, the general approach is to i) translate the object so that the centroid ...
0
votes
1
answer
132
views
How do I reproject without an EPSG code?
I have a set of points that I need to project, but can't find the EPSG code.
(EPSG have made it so easy I never had to work with non-built-in codes..)
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, ...
0
votes
0
answers
41
views
How to represent and manage polygons in the polar region that cross from East Russia to North America?
I'm trying to create a map of the Eastern part of Russia and the northern part of North America and I need to clip the coastline around that area. However, when I am trying to cut the section using sf ...
0
votes
1
answer
168
views
New Zealand map that includes Chatham Islands
I am trying to create a map of New Zealand in R (sf, ggplot2), that includes Chatham Island. I am accessing the online New Zealand map from Natural Earth. Online I can see the Chatham Islands on the ...
0
votes
0
answers
70
views
How to set the dTolerance parameter of sf::st_simplify()
I am reading the help files of sf::st_simplify() function and I got this passage that confused me about how to set the dTolerance parameter:
If you run st_simplify, the input data is specified with ...
0
votes
2
answers
125
views
R classification of ADM0, ADM1, ADM2 and cities into 1x1 grid [closed]
I want to work on linking temperature to socioeconomic variables. there are wonderful databases offering 1deg x 1deg spatial resolution for temperature (such as CRU and the Berkeley BEST data base).
...
0
votes
0
answers
27
views
ArcGIS Pro 3.1 errors out on lidR sf object Hulls exported as a polygon shapefile
So I am trying to write a Hulls object created from the crown_metrics function to a shapefile using st_write. Now, with st_write to resolve the 3D error in regards to a shapefile, I first used st_zm.
...
0
votes
0
answers
48
views
plot lidR Hull object with geom_sf with a basemap
So I am trying to create a static map by overlaying the tree canopy hulls (created using crown_metrics function) as hollow polygons with yellow color on a ESRI basemap.
How can I resolve the error? I ...
0
votes
1
answer
36
views
Calling entire row from irregular grid using R (sp, sf)
I have
library(world)
library(ggplot)
library(sf)
world_coords<-map_data("world")
afghan<-world_coordinates[which(world_coordinates$region=="Afghanistan"),]
afghanshape<-...
1
vote
2
answers
70
views
Finding features of connected lines to simplify line elements
I have a dataset of spatial line element where each line is classified as a certain vegetation type. The issue is that there are quite few instances where different vegetation types are recorded for ...
2
votes
1
answer
139
views
Is there a comprehensive list of mapnprojections implemented in R?
I would like to experiment a bit with different and less-frequently used projections in R for global maps, but I am playing a guessing game as of which are actually working.
I tried to look up ESRI or ...
-1
votes
1
answer
193
views
Count points inside polygons using R [closed]
I have imported two shapefiles in R, one with polygons and other with points. Each polygon has an identifier different from the others, and each point also.
The polygons and points identifiers are not ...
0
votes
1
answer
133
views
Querying the USGS National Map from R
I'm trying to download watershed boundary dataset geometries from the USGS National Map. Right now, I'm just trying to download 2 digit HU layers. You can see what I'm looking for here and here is a ...
2
votes
1
answer
120
views
Why do a line and polygon still intersect after using st_difference() in R?
I have a line that intersects a polygon, and I would like to get only the portion of the line that does not intersect the polygon. Using sf::st_difference() does indeed trim the line, but the result ...
0
votes
1
answer
190
views
Find cells with maximum value per dimension in stars object (R)
I would like to find the cells, and their corresponding centroid, that hold the maximum value for each band in a multiband raster.
Converting the stars-object to a sf-dataframe makes this easy somehow....
0
votes
0
answers
89
views
ggplot and sf package: broken polygons after projection
My standard hack for fixing broken polygons after re-projection (see https://stackoverflow.com/questions/77298627/strange-behavior-with-ggplot-sf-package-and-orthographic-projection) does NOT seem to ...
0
votes
0
answers
53
views
Combine and plot multiple stars proxy objects (being read by read_ncdf)
Here is a great ressource on how to combine data in the stars package: https://tmieno2.github.io/R-as-GIS-for-Economists/merging-stars-objects-using-c-and-st-mosaic.html
And here is a great ressource ...