Questions tagged [sf]

The motivation behind the `sf` package is to provide a complete, standardized implementation of simple features in R, with links to GDAL, GEOS and Proj.4. There is a also https://gis.stackexchange.com/ for spatial R questions.

Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

Inconsistent results when matching closest lat/long points in r using sf and st_distance()

I have a large dataset where each row is a station. I need to find the closest station within each year but where a different type of equipment was used. I then want to either combine these rows into ...
  • 23
1 vote
0 answers
32 views

GitHub Actions can't install R package 'sf' because gdal-config not found or not executable

I'm using GitHub Actions to automate the updating of a GitHub pages that I host. I used R to create the functionality and produce the R Markdown document that acts as the webpage I'm hosting. ...
  • 11
0 votes
0 answers
32 views

Extracting pixel values based on condition

I have one raster file on land cover (30x30m pixels), one raster file on soil organic carbon (SOC) (250x250m pixels), and one vector file with contiguous polygons of different sizes. What I require is ...
  • 401
0 votes
1 answer
40 views

Subsetting column of data frame by rows where the column is an empty list

I have an sf object data frame in R with a column that is a list of characters and character lists itself. For some rows the column is an empty list. I want to subset to only those rows where the ...
  • 143
2 votes
0 answers
33 views

Is it possible to create an irregular raster in R with terra package?

I have a dataset which represents a global grid with latitude and longitude and the length of each pixel along the x and y axis. These are simply lat/long CRS. Like this head(latlong) x y ...
0 votes
0 answers
31 views

The longitude and latitude coordinates on an sf/ggplot map are displaying with boxes rather than degree symbols

map with incorrect degree symbol I am creating a geographical map of Germany in R with gggplot2 and sf for the first time which takes geographic data from a shape file and numerical data from a csv. I ...
0 votes
1 answer
28 views

Fastest method for spatial differencing (st_difference) a large dataset

I have a large dataset of polygons where I would like to subtract a unique buffer width from each one, and then difference the buffer from the original polygon. I am working with HydroSHEDS' ...
  • 102
0 votes
0 answers
29 views

Filtering st_intersect to only consider rows in the data which are the same country in R

I have got a data frame / tibble, which contains the Lat/Long and Country for each data point. Currently, st_intersect is being used to output the row numbers for each row which intersect within the ...
  • 1
-1 votes
1 answer
60 views

Move rivers located in AK and HI to match plot_usmap

I made a lovely chloropleth using plot_usmap from the usmap package: plot_usmap(data = state_difference, values = "my_variable") + theme(legend.position = "bottom") + ...
  • 49
1 vote
0 answers
44 views

How to optimize speed in spatial thinning in r

The problem I am embarking on a project were I will need to build more or less 30,000 species distribution models (SDM), and I have been testing several ideas. Right now my bottleneck is to speed up ...
0 votes
0 answers
32 views

Skewed geography plotting census shapefiles in R

I've pulled US census data by block and merged the block shapefile on it manually with the sf and rgdal packages. When I plot the resulting sf object it's showing a skewed map despite the crs ...
  • 143
0 votes
0 answers
25 views

edit geometry attribute with mapedit in R

I aim to draw simple rectangle on a leaflet map in R using the mapview and mapedit package. However, does someone has an idea how to directly add a specific numeric value to each geometry just after ...
  • 1
-1 votes
1 answer
40 views

fill polygon with points in R

I have a polygon which I would like to put some point on its perimeter and inside, with minimum distance as constraint. here is my shape file : sh = structure(list(farmId = "NO39", Name ...
  • 1,915
0 votes
0 answers
42 views

C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -lblosc -lkea -lsz ERROR: compilation failed for package 'sf' in R

I'm updating sf version from 1.0-9 to 1.0-10 by using install.packages("sf") in Rstudio, but an error occured as follows: C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -...
0 votes
1 answer
67 views

Map editing with ggplot in R

I have a geodataframe (gdf), imported with sf, which have information about 1874 districts of a country. It have this structure: Classes ‘sf’ and 'data.frame': 1874 obs. of 8 variables: $ NOMBDIST: ...
0 votes
1 answer
38 views

R: st_buffer is giving a wildly inaccurate result when projected to CRS WSG84

I have a latitude and longitude that I am treating as a center point. I want to draw a 100 nautical mile circle around that point. Since 1 degree of lat/lon is approximately 60 nautical miles, I would ...
0 votes
0 answers
24 views

Error when installing 'sf' and related packages on Macbook (Monterey)

**I have reinstalled R (R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"). I have tried each version of 'sf' and 'rgdal' and I continue to get errors. I did try each version in the ...
0 votes
0 answers
30 views

Matching geolocated (long & lat) month-specific drought values (SPEI) from one data frame with geolocated and timestamped conflict events in another

This question is related to R and geocoding. I have two data frames: Drought data (from SPEI) in the following format (Column 1: Longitude, Column 2: Latitude, Column 3 - 1442: numerical drought ...
0 votes
0 answers
28 views

Add text based on shape of the map on map 3D (with Rayshader)

i want to add label text on map 3D based on shape the map. the output my expect i use this code nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) pts <- ...
  • 25
0 votes
3 answers
42 views

Filter and update point geometry

I have a large sf point dataset. For any x or y coordinate that ends in 000 I want to randomly add or subtract 1 from it (this is top stop a single point intersecting with multiple grid geometries). ...
  • 1,127
0 votes
1 answer
34 views

How do I plot lines joining each pair of centroids of polygons in the `tmap`

How do I plot lines joining each pairs of centroids of countries in the tmap? The color (or transparency) of line should represent the the total population of countries joined. Example of how map ...
  • 1,323
0 votes
2 answers
37 views

How to find the row number based on a set of SFC coordinates, in order to pull out the value from another column

I am new to geodetic data in R, so apologies if this is way off. I have got a dataset, with a column (geometry), which contains SFC points, and a second column (IntersectingPoints): IntersectingPoints ...
  • 1
0 votes
0 answers
37 views

Spatial join in R using st_join based on time and space criteria

I have two spatial dataframes of points, one is nest locations of a rare bird and its associated breeding data for each year (i.e. how many young were produced at each nest) and the other is tropical ...
0 votes
2 answers
42 views

Jaccard index: R not letting me convert raster to numeric?

I'm trying to calculate the Jaccard index for my data, which is for two presence/absence rasters (of two different species). I also have a third raster, that contains the overlap of the species ranges....
1 vote
0 answers
47 views

Save a sf object in r as a shapefile with embedded style

I use R to manipulate my data then take the vector files I generate into a GIS platform such as QGIS (because my datasets are large and cannot be easily interrogated using leaflet, mapview, etc. I ...
  • 613
0 votes
2 answers
42 views

Converting WSG84 to UTM, rgdal alternatives

I have numerous existing scripts in which I used project() from the rgdal package to convert WSG84 Latitude/Longitude coordinates into UTM. rgdal has intermittently been giving me headaches by ...
  • 507
0 votes
0 answers
35 views

How to read kml files in R without any error?

I am trying to read the .kml which I downloaded from the link below: https://data.opencity.in/dataset/delhi-metro-map/resource/delhi-metro-lines-map However, I keep getting an error. Here is a snippet ...
0 votes
1 answer
25 views

Increase number of nodes defining polygon for correct projection

I have an issue when making a map with R using sf. I need to use a LAEA projection (CRS 3035), but one of my horizontal line is straight whereas it should be curved (the one in the middle): I ...
  • 300
0 votes
0 answers
36 views

Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options)

I am using sf package to do some geospatial analysis on a geodatabase. But Whenever I try to save the results as shapefile, I get "Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(...
0 votes
0 answers
33 views

How to remove direction in sf network in r (make a directed network undirected)?

I am using a road data to build sf network. On top of that I am planning to create a walking road from some facilities to the closest road (straight line from facility location to closest road). I did ...
  • 23
0 votes
1 answer
39 views

How to select specific rows by subsetting the accompanying geometry column with a certain range of coordinates in R

Recently, I am trying to make a river map for a certain region. To this end, I obtained the river data from HydroRivers and I would like to subset this data with a certain range of coordinates so that ...
  • 169
0 votes
1 answer
57 views

plotting percentages upon a country's region in ggplot2

I have collected some data on a Survey in which I asked from what Brazil's region the participants were. I have Brazil's map and its states with ne_states but I'm struggling with ploting the ...
0 votes
1 answer
65 views

sf::st_intersection not implement all points

I have two sf files: x & Riv I would like to obtain the intersection of 'x' polylines with 'Riv' Linestring. For that, I used the function sf::st_intersection(x,Riv). Nevertheless, the output does ...
  • 395
1 vote
1 answer
42 views

Interactive map plotly from shapefile

I would like to create an interactive map, using the plotly package in R. However, I face the issue now that my geodata is contained in a shx shapefile, which the plot_ly() function seems to have ...
0 votes
1 answer
39 views

st_buffer with geometry sfc_POINT

I'm working with geospatial data and for one part of the analysis I need to use coordinate points of regions that I get from an excel and turn that data into sf object using st_as_sf. When I tried to ...
0 votes
1 answer
37 views

Find the length of a road in R

Question I have a dataframe df which contains cartesian coordinates of a hypothetical road. I want to find the length of the road. Following is a plot: library(ggplot2) ggplot(df) + geom_point(aes(x,...
0 votes
1 answer
42 views

r - readOGR(), terra::vect and sf::st_read : cannot open shapefile while file.exists = TRUE and .shp, .dbf and .shx files in the same folder

I don't understand why I get the error : "Cannot open data source" while my path should have been at least once correct and that the .shp, .dbf and .shx files are in the same folder. I've ...
  • 3
0 votes
0 answers
34 views

cropping and masking raster using US shapefile covering the entire globe

library(terra) library(geodata) us_county <- geodata::gadm('USA', level = 2, path = getwd()) plot(us_county) I have an underlying raster that covers the entire globe temp_raster <- terra::rast(...
  • 3,319
0 votes
1 answer
50 views

Dealing with Sentinel-3 data with R

I'm struggling to deal with sentinel-3 data in R, of 300 meters resolution. I would like to extract TSM (Total Suspended Matter concentration) in each cell. Data are provided in a archive, with many ...
0 votes
1 answer
25 views

Creating column of intersected objects

I have two objects overlapping each other: Multipolygons Polylines Like this: I need to add a column in the Multipolygons object with the intersected rows from the other object, something like this:...
  • 121
0 votes
1 answer
45 views

Aggregating points in dataframe based on distance

I have a set of Lat/Long points with numerical values attached to each point. Essentially I want to perform basic calculations on the numerical values within 300,000m of each point, but initially just ...
  • 1
2 votes
2 answers
60 views

ggplot: different scale_fill_gradient by facet

I'm using ggplot() and geom_sf() to plot a faceted map (s. below code) and color units along a scale_fill_gradient() by a variable (value in the example below), before faceting by another variable (...
  • 3,792
0 votes
1 answer
31 views

use `sf` to plot state map (of Germany) according to variable

I'm new to geoplotting and I want to use sf to plot a map of Germany on the state level, with state values colored by a variable in a separate data set. How do I best go about this? I have loaded the ...
  • 3,792
0 votes
1 answer
55 views

How to correctly use st_difference() in combination with mutate()?

I have a simple feature dataset with lines, and I am trying to find the parts of the lines that are more than 30m away from their respective Endpoints with the sf package and R. This is what I tried ...
  • 3
0 votes
1 answer
38 views

Splitting a multipolygon into polygons with edges that don't intersect

I am working with spatial data and I need to split a multipolygon into polygons with no intersecting edges. For instance, consider this multipolygon mp: p <- st_polygon(list(rbind( c(0, 0), ...
  • 287
1 vote
1 answer
41 views

How to get rid of the "Error in CPL_write_ogr" error when using "st_write" to export a sf object?

I'm trying to intersect two sf objects for the US (one at the township level and the other one at the census tract level). I'm getting both using tigris and tidycensys. My final goal is to have an ...
0 votes
1 answer
68 views

Zoom in rectangularly in map

I'm trying to have a rectangular "zoom in" into my chart. So far, I can create the chart itself and a smaller version, but I haven't figured out how to zoom in rectangularly. (Builds on 1 ...
  • 1,198
0 votes
2 answers
32 views

ggplot and sf - category by color

when plotting this very simple sf multipoint feature gm.multipoints <- st_multipoint(rbind( c(0.1, 51.5), c(11.3, 44.4), c(-3.7, 40.4), c(2.3, 48.8) )) df.attr <- data.frame( name = c(...
0 votes
2 answers
98 views

R Optimisation of the calculation of the geographical distance between a large number of polygons (>11.000)

How can I optimise in R the calculation of the geographical distance between millions of pairs of centroids of polygons? The polygons represent 111 km x 111 km grid cells covering the entire Earth. I'...
3 votes
1 answer
65 views

How to remove "almost holes" from polygons using R sf?

I have a polygon with some holes and some "almost holes" that are long, skinny inlets into the polygon. (polygon files HERE) field <- sf::read_sf("example_field.kml") ggplot() + ...
  • 471

1
2 3 4 5
36