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
2 answers
22 views

SF Collection Plots in lat/long but Geometry is Not

I'm using urbnmapr to get a county base map. I want to plot my own points on top of this map. Even though the urbnmapr map plots with lat/long on the x y axis, the lat/long points that I want to plot ...
1 vote
1 answer
59 views

Convert dataframe with polygon geometry variable into SF object

I am working with the Native Land data accessible via API: library(httr) library(jsonlite) library(raster) library(sf) library(tmap) res = GET("https://native-land.ca/api/index.php?maps=...
1 vote
1 answer
47 views

R lidR clip_roi error

I am trying to clip a LAS object based on an sf object. Now both the objects have the same CRS according to ArcGIS Pro 3, but clip_roi still returns an error that the CRS don't match. Error: Error in ...
0 votes
0 answers
28 views

How to plot Peirce Quincuncial and Spilhaus maps in R?

I am trying to project shapefiles of world maps in Peirce Quincuncial and Spilhaus. Although the projection is applied without errors, the plot function doesn't work. It seems something to do with the ...
1 vote
1 answer
51 views

Extracting variables from grid cells using R

I am trying to extract bioclimatic variables from individual grid cells. So i started loading my shapefile: # I used the Admin 0 - Countries (1:10) dataset from Natural Earth shp <- sf::st_read(&...
0 votes
1 answer
33 views

Remove ("erase") polygons by shared attribute

I need to do a pair-wise removal of a set of polygons within a larger set of polygons. pt<-data.frame("x"= c(0,0),"y"= c(0,5),pair= c("a","b")) pt<- ...
  • 9
1 vote
1 answer
42 views

Why do dist2Line and st_nn give slightly different distances?

I have some points and am finding the distance to the nearest state border. My question is: why do dist2Line and st_nn give slightly different answers for the distances? The code below is based on ...
  • 115
1 vote
2 answers
120 views

R - Finding closest point to each point and filtering which points to consider

I'm a beginner in R. I am working in R with a dataset of bird nest locations and am interested in the distribution of said nests. Specifically, I'd like to find the closest neighbor to each nest as ...
  • 13
0 votes
1 answer
125 views

R terra: [crop] SpatRaster has no values

I am attempting to use terra::crop() to crop 30 meter NLCD raster data to a bounding box. The final error that R returns is: Error: [crop] SpatRaster has no values despite the raster data containing ...
0 votes
0 answers
38 views

How do I get the proper data format for creating a tilegram -- from MULTIPOLYGONS to POLYGONS

I want to create a cartogram(specifically a tilegram like this) using data from GADM and population figures as the subject variable. Step 1: Get a json data file from GADM germany_1 <- read_sf(&...
  • 13
1 vote
1 answer
44 views

Retain spatial points outside of multiple polygons

We can use st_intesection to retain points that intersect with one or more polygons. tmp1 = st_intersection(st_as_sf(track_sp), st_as_sf(cols.buf_sp)) pts1 = as(tmp1, "Spatial") plot(pts1) ...
0 votes
1 answer
41 views

Distance between nearest neighbors R GIS

I am using nngeo to identify for each town the nearest city. Library nngeo is available here. I want to also report the distance between each town and its nearest city. I wanted to use gDistance but ...
1 vote
1 answer
37 views

Move points to different location

I have a group of points for London's train stations I've found through OSMdata: library(osmdata) library(tidyverse) osm_points <- opq ('greater london uk') %>% add_osm_feature("...
0 votes
0 answers
18 views

How to join the values shown in the ggplot legend as an added column to the spatial data frame/shapefile?

I have a dataset filled with points. The image assigns the points a value based on clusters. Is there a way to assign those values shown in the image onto the dataset itself as a new column? This ...
  • 193
0 votes
1 answer
58 views

NAs when calculating the mean of raster values per polygon using R (stars & sf)

I am trying to get the mean NDVI value for tree clusters (I've calculated them using DBSCAN) using stars and sf but, I'm getting a lot of NA values, which they don't appear if I use the Zonal ...
  • 115
0 votes
1 answer
35 views

Identify overlapping polygons within a single MULTIPOLYGON

I have a multipolygon shapefile that contains thousands of records with a spatial and temporal component. I'd like to be able to identify records that overlap (the amount of overlap doesn't really ...
  • 1,268
0 votes
1 answer
53 views

Creating custom rectangles for SF features

I am trying to create a custom rectangle for each point in my df. I am using two functions to loop through each feature and write a new polygon output. I would like one SF data frame with each of the ...
0 votes
0 answers
68 views

Recenter map that crosses international dateline with ggplot and geom_sf

Consider the map of Europe below. Parts of Russia are on the other side of the map. How might I "recenter" the map so that there is less empty space? I guess I need to somehow move the ...
0 votes
1 answer
40 views

Getting polygon coordinates for areas outside known polygons using R

I have downloaded shapefile containing polygons for urban areas. However, I am interested in polygons representing rural areas. Therefore I would like to convert the shapefile containing urban areas ...
  • 1
1 vote
1 answer
113 views

How to speed up the intersection of two large shapefiles in R with sf (or any other way)

I have two large-ish shapefiles. Shapefile 1: One can be downloaded from here: https://data.statistik.gv.at/data/OGDEXT_DSR_1_STATISTIK_AUSTRIA_20111031.zip It is ~20 MB in size Seems to be super ...
  • 717
0 votes
0 answers
21 views

tmap, always put biggest shapefiles as first layer

I am using TMAP library to generate a series of maps. The number of maps to generate is huge and the number of shapefiles to plot in each map is also big. Each shapefile is of a different size, some ...
2 votes
1 answer
52 views

Dividing square into smaller squares by using their shapes rather than their bounding boxes in R

I want to divide a square into 25 smaller squares. The square layer has a UTM coordinate system, so when plotted, it doesn't have flat bottoms and tops. When I try st_make_grid() function to overlay a ...
  • 55
2 votes
2 answers
224 views

Calculate area weighted mean values of polygons for raster cells using R

Problem I want to rasterize polygon values and assign their weighted mean to raster cells. Weighting should be done based on the polygons' cell coverage. Problem visualized Calculation for grid cell ...
  • 184
3 votes
0 answers
46 views

How to apply mean/min/max merge functions on a vector layer to create a stars raster?

Problem I would like to stars::st_rasterize a vector layers of an sf object using aggregation functions such as mean/median/max/min. raster::rasterize lets me use mean, min etc. and even define ...
  • 184
0 votes
1 answer
75 views

Select and save as shapefile feature in R using sf

How can I select the shapefile feature there is, "D3" in "New.Code" columns using sf packages in R Here is the attribute table of my shapefile:
0 votes
2 answers
78 views

Applying Moran's I across columns

So I find myself needing to apply global Moran's I across ~20 variables (as in ~20 instances of univariate autocorrelation for each variable, not attempted multivariate spatial autocorrelation). I'm ...
0 votes
0 answers
77 views

How to remove banding artifact in R after reprojecting sf with st_transform

I have several global map layers I am plotting using ggplot() + geom_sf() + etc. All data is "+proj=longlat +datum=WGS84 +no_defs". My goal is to have Eurasia be a contiguous land mass. This ...
  • 1
1 vote
1 answer
46 views

Which point lies on which linestring? [closed]

Using the {sf} package, I have two sf objects: one containing linestrings (edges), which form a linear network; one containing points, which are restricted to lie on the network. My goal ist to ...
  • 123
0 votes
0 answers
11 views

Raster intersect is duplicating polygons

I am using a raster intersect to intersect two spatialpolygonsdataframes. One is a moose home range and the other is a SPDF containing wetlands. However, when I intersect them, the total number of ...
  • 1
0 votes
0 answers
61 views

Segmenting transect lines using st_segmentize on R

I'm currently working on R for spatial analysis and trying to segment transect lines (shapefile) by 4km using sf::st_segmentize. I managed to do this following the instructions from here and here for ...
  • 11
0 votes
1 answer
45 views

Error message with Krige function: Error in as.character.default(X[[i]], ...) : no method for coercing this S4 class to a vector

I am trying to run the Krige function but I keep receiving NA values for var1.pred and var1.var. After using the warning() command, it says: Error in as.character.default(X[[i]], ...) : no method for ...
  • 1
0 votes
0 answers
212 views

using as.polygons() with patches() from terra instead of rasterToPolygons() with clump() from raster

I am trying to figure out the equivalent of contour_poly <- rasterToPolygons(clump(my_raster > 1), dissolve = TRUE) from raster to terra. I tried contour_poly <- as.polygons(patches(...
2 votes
1 answer
341 views

Create sf polygon from sf linestring and bounding box

I want to create a polygon using a linestring within the sf universe. I am generating a map of a coastline and I want the area that is water to be blue and the area that is land to be tan. Because ...
  • 2,056
0 votes
0 answers
103 views

R arc.write error

I am getting the following error while writing an sf object dataframe to a GDB. The dataframe imported is a feature class from a GDB brought in via the sf package. After some data manipulation I am ...
0 votes
1 answer
40 views

R Distance from Point to Line: Negative if within shape

I'm working with Brazilian deforestation data - specifically two sf objects: A point shapefile on environmental fines (centroid of land plots that have been fined for deforestation). A polygon of (...
  • 19
0 votes
1 answer
96 views

sf: Session aborts when reading large geopackage into R

I want to read a geopackage into R that is roughly ~ 600 mb in size. Every time I want to read it my R-Studio session aborts when doing the data = read_sf(path_geo) Is there any "trick" ...
  • 717
1 vote
1 answer
31 views

Tessellation will not display quadrat totals when plotted (spatstat, R)

I have tessellated an image, and am trying to plot the number of quadrats that appear in each tessellated region. I have two problems here: My tessellated image will not plot with my gw_ppp points, ...
2 votes
2 answers
105 views

exact_extract Coverage area wrong fcoverage fraction

I'm using R to extract the values from a raster into a polygon. It works fine for most of them, but I found this small polygon (which is smaller than the cells) where it is giving me some misleading ...
1 vote
1 answer
41 views

Is there a way to select nearest feature to a point by selected column?

I'm using crs= 2263. I have two datasets, buildings and 311. I would like to see what is the closest building to each 311 complaint. st_nearest_feature(311, Buildings) I believe this works but it ...
  • 193
1 vote
1 answer
152 views

Warnings() in functions sf package

I'm running the code below and I get several "warnings". I used the sf_use_s2(FALSE) function to work with plane coordinates following the old way of the 'sf' package but even so I keep ...
3 votes
1 answer
335 views

Rasterizing and resampling a vector object using stars::st_rasterize() and terra::rast() loses values/data

I am currently struggling with rasterizing and later, resampling a vector object using functions from stars and terra. Let's start with the example dataset here: https://drive.google.com/drive/u/2/...
  • 1,302
1 vote
1 answer
65 views

Comparing polygon areas across simple feature collections

I currently have three simple feature objects created from different shapefiles in R using the sf package. These three objects have all been projected to the same coordinate system using st_transform()...
  • 1,302
1 vote
0 answers
76 views

Reprojecting raster or vector CRS and extracting raster values based on vector boundaries

I am working with a EUR-11 CORDEX dataset of daily temperature values (nc file) from ESGF database and EUROSTAT NUTS data (from here: https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/...
  • 11
0 votes
1 answer
173 views

Rasterise sf Polygon and Assign Cell Value based on Total Area Deforested

I'm a relatively new to working with spatial data in R. I'm working with Deforestation data (EPSG: 5880) for the Brazilian Amazon - consisting of 70,000 polygons of deforested land that covers all of ...
  • 19
0 votes
2 answers
243 views

sf::st_read() and terra::vect() reading in different extents from the same shapefile

I am currently working with multiple shapefiles in R and working towards rasterizing them using a combination of functions from sf,terra and stars. However, I noticed while reading in a shapefile that ...
  • 1,302
0 votes
1 answer
87 views

Extract a network from spatstat to graph object in igraph using R

I am looking for an efficient way to transfer a linear network (class linnet) from spatstat, e. g. library(spatstat); data('chicago'); net <- spatstat.linnet::domain.lpp(chicago) to a 'graph' ...
  • 123
1 vote
2 answers
135 views

Calculate sum/average of variable within each group of neighboring counties using R

I am trying to calculate the sum and/or average value of a variable for each group of neighboring counties in the US. I realized this needs at least two steps: For every county, find the set of ...
0 votes
0 answers
112 views

Error when trying to mask raster to shapefile after interpolation using R - "sp supports Z dimension only for POINT and MULTIPOINT"

I am trying to mask an interpolated raster to a shapefile with the same coordinate reference system using R, but I keep getting an error. The error is shown below. How can I overcome this error and ...
1 vote
2 answers
238 views

Using R, how can I find the average slope of a raster with land use area information?

I am new to GIS in R. I have two input rasters (an elevation DEM and a land use classified raster), and I am tasked with reprojecting, aggregating into courser resolution, and finally calculating the ...
1 vote
1 answer
126 views

How to subset columns based on row values in R?

I have extracted ERA5 temperature data for specific points that contain the day of the year when the temperature exceeds 10 degrees celsius. And now I want to see how the temperature develops ...
  • 798

1
2 3 4 5
11