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
37 views

Adequate CRS when creating a grid over a whole continent in R

I'm trying to generate a grid of 6.72 km by 6.72 km points over the whole continent of Africa, but I'm having a lot of trouble in doing so. I'm mainly running into 2 problems: My first issue arises ...
2
votes
1answer
28 views

How do we use the agr argument in st_sf()?

I am using the sf package to create new spatial datasets, via the st_sf() function. I do not understand the use of the attribute-geometry relationship argument of this function. The help file ...
3
votes
0answers
24 views
+50

How to split several lines by one polygon and get the distance of each part using sf?

The question "How to split one line by several polygons" already has an answer here. My question is similar but different: How to split several lines by one polygon? The context: I have a ...
1
vote
2answers
46 views

Split lines by a polygon - Why are “internal” lines split in parts using sf/st_split

The context: I have a border and routes followed by vehicles. I want to decompose the routes, cutting them everytime they cross a border, and for each part, know what are the distances performed. ...
0
votes
1answer
13 views

Identify if point over land or ocean using lat/lon in R with confidence metric

How can I determine whether a coordinate is above land or ocean with a confidence metric in R? I've used the sf package method described in another question: Given Lat and Lon identify if point over ...
0
votes
1answer
32 views

R: Using st_intersects to classify points inside, outside and within a buffer

I have two objects, a shapefile of location points, points, and a shapefile of polygons, world_buffer (both +proj=utm +datum=WGS84). The world_buffer is the world's coastlines, found here, with a 5 km ...
0
votes
0answers
15 views

Areal interpolation with mostly missing data in R

I am attempting to preform an areal interpolation using R with the sf package's st_interpolate_aw. Of note, my sampling scheme for my areal units is such that I have many missing values. When using ...
0
votes
1answer
39 views

R packge sp to sf QGIS 3.14

I have several scripts written in R language with package "sp" for Qgis. However I am stuck in the old versions (2.18) because whenever I use this same package in current versions 3.14 the ...
4
votes
1answer
37 views

Plot two layers (raster and polygon-vector) with ggplot and use the fill-scale* for both layers

I am a little lost. I have a stars object where I would like to use the first attribute and map it to the scale_fill*-function in ggplot. I also have an polygon-object of class sf that has an ...
0
votes
1answer
32 views

“Unknown datum” opening GRS80 Transverse Mercator in R

I am working with a shapefile (available here as a 15MB ZIP) with a projection defined as follows: GEOGCS["GCS_GRS_1980",DATUM["D_GRS_1980",SPHEROID["GRS_1980",6378137,...
1
vote
1answer
35 views

How to append variables to shapefile in R?

I want to create a map of China that demonstrates the value of the ethnic heterogeneity index. I want to generate the map as in this webpage, https://mgimond.github.io/Spatial/mapping-data-in-r.html I ...
-1
votes
2answers
85 views

Extract in R Raster Package incredibly slow [duplicate]

I am using the extract function from the raster package in R. The extract function is taking incredibly long to assign the values to the polygon. In ArcMap, this process is much faster (but of course ...
0
votes
0answers
15 views

Combine named list of stars object into one new stars object with the names being a new dimension

I have a list of stars objects that I created in a loop. This little example is more or less replicating my situation. library(stars) tif = system.file("tif/lc.tif", package = "stars&...
1
vote
1answer
30 views

R/sf - Transform a geometry column made of POINTs and MULTIPOINTs into xy-coordinates columns (x1, y1, x2, y2, …)

After intersecting a set of routes (LINESTRING) with a perimeter (say the border of a country) using st_intersection from sf package, I get a list of points and multipoints: there is one point when ...
0
votes
0answers
17 views

Generating sf dataframe from raster based on intersection with polygons and distance from polygons

I'm working on a project looking at the effect of a particular housing policy applied on a very micro scale in Berlin, but I'm dealing with a number of different geometries; my plan is to have my ...
0
votes
1answer
37 views

Using R to convert British National Grid to/from WGS84 without creating spatial object

I have several million coordinates (which are either British National Grid or Long/Lat) and need to convert them. I know using R you can do this in a spatial operation (such as in my example below ...
1
vote
1answer
33 views

Choosing efficient output format for spatial data in R

I'm assembling a moderately large spatial dataset as simple features in R (4.0.5). Is there a good way to select the most performance-efficient output format/OGR driver to save my assembled data? I'm ...
2
votes
1answer
31 views

Load data from GPKG incrementally in R

I need to process a GPKG file in R, but it's too large (50GB) to load the entire thing into memory at once. Is there any way to incrementally load the results? Right now we are loading it with a ...
1
vote
1answer
28 views

Stats for forest cover change over 10 years in R

I am rather new to GIS and I don't know how to perform the following operation: [ R programming language] I am developing a project evaluating forest cover change over 10 years (2010-2020) for a ...
0
votes
2answers
48 views

Raster extent based on SpatialPolygonsDataFrame generating incorrect extent

I'm trying to rasterize data from Berlin's average price per parcel data. I've downloaded the shapefile from their data portal using an API with a function that generates an sf object, and then ...
0
votes
1answer
24 views

st_combine and st_union produce empty attribute table for shapefile (how to edit before st_write?)

I am starting with R programming and I am having a hard time figuring out how to edit the attribute table of a shapefile after using st_combine and st_union. My shapefile has multiple polygons and I ...
0
votes
1answer
25 views

Reading WFS layer with sf::st_read. Is it possible to apply a filter along with the request?

I'd like to read a large WFS layer in R. But since I don't need the entire layer, I'd like to filter it by some value in the attribute table. I know how to read the entire WFS layer with sf::st_read. ...
2
votes
2answers
150 views

R st_centroid GEOS error Unknown WKB type 12

I’m trying to calculate centroids of polygons of postcode areas (wfs shapefile), but I’m getting the following error message: Error in CPL_geos_op(“centroid”, x, numeric(0), integer(0), numeric(0), : ...
0
votes
0answers
27 views

Compute mean of two stars objects in R

I have two stars-objects and I simply would like to calculate the mean for each pixel. I am not really sure how to do that and if my approach is correct. At the moment I'm doing the follwing: I have &...
1
vote
0answers
23 views

Focal operations / aggregations on stars_proxy object in R

I have many NetCDF-files that I read in as stars_proxy-object. I also have a geopackage that is a multipolygon. I Would not like to extract the mean value for each polygon for each stars_proxy-object. ...
0
votes
0answers
9 views

Difference in CRS when reading with read_stars und read_ncdf

I have a NetCDF file that I would like to load into a stars object. The two functions st::read_stars and st::read_ncdf both load it in, but the data ends up in different locations when I plot it using ...
2
votes
3answers
102 views

Creating smallest-circle covering polygon using R with sf

How can I create the smallest-possible circle which covers a polygon geometry using the sf (preferred) or sp packages in R? One reprex using GADM data: # Load packages library(sf) # Load Nigeria ...
3
votes
1answer
64 views

How to read .csv polygon data with sf?

I am trying to read a .csv file where each row contains information about a polygon. The polygon geometry information is stored in a shape column such as 'longitude latitude altitude accuracy; ...'. ...
1
vote
1answer
235 views

sf::st_transform() gives “crs not found” error

I am using sf package version 0.9-6. I define a new object in ESRI:4326 and then try to reproject it to an Albers projection. I get an error, despite explicitly setting the crs when defining the ...
1
vote
0answers
17 views

How to create your own CRS using sf package in R

I am trying to map basketball shots using the sf package in R to create interactive maps for players and coaches. I have managed to create a basketball court as a spatial object using Todd Schneider's ...
0
votes
0answers
21 views

Checking if the point lies within the polygon in R using sf package

I have a point's coordinates as well as an object with the class of sfc_polygon in R. I would like to check if this point lies inside that polygon or not. I created an object with the class of ...
0
votes
1answer
48 views

abind Error when converting a .tif raster data object to an sf object using st_as_sf() in R

When I try to convert a .tif raster data object to an sf object using st_as_sf() in R, I get the following error: Error in abind(x, along = length(dim(x)) + 1) : along must be between 0 and 2 Does ...
0
votes
1answer
22 views

Calculating nearest distance between two Linestrings using R

I have two simulated linestrings, one that represents a satellite ground-track and the other representing a linear surface feature (e.g., a road or river). I am trying to calculate the minimum ...
3
votes
1answer
168 views

sf geometry column naming differences R

I've got several shapefiles stored as geopackages and I want to merge all of them by using rbind. But unfortunately the geometry columns are namend differently as "geometry or "geom" ...
1
vote
1answer
58 views

Intersect points and polygons

I have a dataset where I'm trying to look determine determine which polygons my sampling locations occur in. I have been following the example here: https://gis.stackexchange.com/questions/282750/...
1
vote
1answer
30 views

Obtain percentage of overlap with another multipolygon in R

I have two MULTYPOLYGONS, one where a row is a election district*year pair, and the other is a collection of flood events. district.df year ward_ons cycle geometry ...
1
vote
2answers
167 views

Fastest way to perform focal operations using R

I know there are already some questions out there discussing this issue, for example: How parallelize the extract function for raster files in R? Increasing speed of crop, mask, & extract raster ...
0
votes
0answers
29 views

Intersection of line with z-line

I want to intersect a Z-line with a non-Z-line to obtain the intersection point with the z-value from the Z-line. However, it doesn't work for these two lines: my_line <- st_linestring(matrix(c(...
2
votes
2answers
456 views

Mask and crop a raster to multiple polygons in R

Is it possible to mask and/or crop a raster to multiple polygons, with the output being multiple raster's (i.e., a raster stack)? Here's a reproducible example: library(tidyverse) library(raster) ...
1
vote
0answers
39 views

How to “split” a single MULTILINESTRING into multiple MULTILINESTRINGs that intersect?

I'm trying to solve this problem using the R sf package, but I assume that an answer in PostGIS could also help me get to an answer in R. Basically, I have a shapefile with the following columns: &...
1
vote
0answers
12 views

Clever way of calculating and storing cumulative rainfall for each polygon of a MULTIPOLYGON sf-object

What I have is this sf-object: Simple feature collection with 50 features and 8 fields geometry type: POLYGON dimension: XY bbox: xmin: 611398.7 ymin: 5122699 xmax: 745144.8 ymax: ...
0
votes
0answers
30 views

How to tile and mosaic spatial vector data in R?

Processing large vector data requires a way to tile the input data and mosaic the output. The following example only targets the tile creation and final mosaic step. Tiling the data has the reason ...
1
vote
1answer
33 views

st_difference creates two linestrings, how can I keep only one?

I am using R and the sf package to manipulate shapefiles. I have transect lines that intersect an island going a few hundred meters inland (see image below). The objective of my project is to trim ...
3
votes
1answer
1k views

How to update CRS r object from PROJ4 to PROJ6

I have a script which contains several r objects which are CRSs that I use for transforming spatial objects. After updating R and many packages, there is a warning which wasn't there before. LCC <- ...
1
vote
1answer
79 views

Using sf to combine polygons that share border with a polygon, but dropping the central polygon? [closed]

I have rows of respondents within census polygons and am trying to generate first-order aggregated polygons, excluding the census unit a respondent resides in. Put another way, I want to combine ...
1
vote
1answer
686 views

R Error in sp::CRS(SRS_string = from$wkt): unused argument (SRS_string = from$wkt)

A previous script that I had is no longer working after the sf package major change. I am using sf 0.9.6 and raster 3.0.2. I have tried to modify my code but cannot run raster::extract(). My previous ...
2
votes
1answer
32 views

Pivot sf geometry column such that each row contains a single polygon

I am trying to calculate the average distance to all habitat patches within a landscape from a site point (sf object). To do this, I have polygonized my habitat raster (dissolving to get patches) and ...
0
votes
1answer
71 views

st_rasterize (template smaller than sf object)

I need to rasterize an sf object that at the end must have the same cell size and be on the same grid of a defined raster object "template", because, eventually, I want to merge them. The ...
1
vote
0answers
24 views

Finding which census tracts lie within a given shape?

I'm new to GIS in R, and I am trying to create a crosswalk that maps the communities drawn in these shapefiles to census tract shapefiles for Los Angeles County that I've gathered from the Tigris ...
1
vote
1answer
25 views

Working with .geo of GEE in R

I am doing something similar to a previous post on stack exchange regarding exporting data from GEE to csv. Once I have the .geo column, how do I work with it in R? I would like to create a shapefile ...

1
2 3 4 5
9