Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sf]

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

1
vote
1answer
16 views

How do I combine geometries in a shapefile based on a grouping variable?

Here is a simple example. I have a shapefile of three US states: This is the code that creates the shapefile. library(USAboundaries) library(sf) library(dplyr) states <- us_states(map_date = "...
0
votes
1answer
34 views

Create polygons (representing boundaries) from lines

I received a file of municipality boundaries, where the boundaries are represented as lines. I would like to convert this to a set of polygons, each representing a municipality. In other words, from ...
0
votes
1answer
23 views

How to read WKB from a PostGIS table with the sf package in R [on hold]

I'm working with OpenStreetMap data, for the manipulation of which I mostly use raw SQL queries to a PostgreSQL/PostGIS database. However this is not the most productive workflow, and I would like to ...
1
vote
1answer
21 views

Why does this R code that maps points into polygons cause a segmentation fault?

As in this question/answer, I have a data frame of points (which also includes some necessary, non-coordinate data columns) and a shapefile. In this case the shapes are US states. The last line of the ...
0
votes
0answers
25 views

R sf package - link to GDAL

Is it possible to ask R {sf} package to use a GDAL installation I prefer? So far I found how to check external software it uses: library(sf) sf_extSoftVersion() # GEOS GDAL ...
1
vote
1answer
21 views

Writing a table (no geometry) to GeoPackage using R

I'm trying to do something so incredibly simple: write a table (with no geometry) to a GeoPackage. I can store tables in a GeoPackage using QGIS, so it stands to reason I'd be able to write one from R....
1
vote
2answers
35 views

Does GeoPackage impose a maximum number of (non-geometry) columns per feature?

Working in R, I tried to write a simple feature file with 402 rows and 1170 columns (only one geometry column) and got the following error: > dim(sf_object) ## [1] 402 1170 > sf::write_sf(...
2
votes
1answer
59 views

Why does R set CRS inconsistently?

I'm running into a situation (using R on MacOS) where sf() is giving different levels of precision on the CRS. This causes problems for geospatial operations, as indicated below with st_crop(). Can ...
0
votes
0answers
28 views

Randomly move (and rotate) an sf polygon within a broader extent using R

I have an area of interest within which I have multiple polygons (two in the example below). I would like to randomly move each of the polygons so that they are completely within the larger extent and ...
0
votes
1answer
30 views

Convert geometry set to simple features collection using `sf` in R

How can geometry set objects be converted to simple features collection objects with the package sf in R? I want to add attribute data to the geometry but am prevented from doing so because geometry ...
-1
votes
0answers
35 views

Creating and combining polygons in R with sf

I'm getting a bit confused by a few supposedly basic tasks involving polygons in R. I'm tying to keep everything in sf, but if I need to switch to sp that's ok. Firstly, I'm creating some polygons ...
2
votes
1answer
76 views

Error from aggregate function from the R package sf

I am currently reading the new (and free!) book by Edzer Pebesma and Roger Bivand (you can find it here). In chapter four they describe how one can aggregate all the measurement stations within one ...
1
vote
2answers
28 views

R - Create multiple linestrings from multiple coordinates

I have a dataframe with two sets of coordinates X,Y and prevXal,prevYval and I would like to make linestrings column wise, and create an sf object of the same number of linestrings as rows in the ...
3
votes
1answer
36 views

clustered st_convex_hull

I am trying to obtain a polygon from each group of points "G" but I obtain only one single polygon for all the points. I grouped data by the G variable but it doesn't work. library(sf) library(...
3
votes
1answer
38 views

How might one optimise geospatial operations on complex polygons, especially plots in R?

Question: I'm attempting to run some simple plots on some shapefiles with a high number of complex polygons. These aren't massive files - for the example below, the shapefile is 70mb (15872 obs), but ...
1
vote
1answer
90 views

How to use st_buffer?

I would like to calculate a buffer of 5km around country polygons. However, I somehow always get a warning and an error. Here is a reproducible example code. library(sp) library(sf) library(tmap) ...
0
votes
2answers
24 views

sf polygon goes black in for loop in R

I'm making this loop, it's part of a script I'm making to illustrate a percentage in a polygon (let's say instead of a pie) but then I realized it looks good as an animation; when I start plotting, ...
4
votes
2answers
102 views

How do I calculate the Terrain Ruggedness Index for each county in the United States in R?

I have a shapefile of US counties and high-resolution elevation data that spans the entire contiguous United States. My goal is to calculate a terrain ruggedness index for each county. The functions (...
0
votes
1answer
42 views

Legend color scale problem with tmap for island

Bornholm_data <- geo_RH %>% filter(KOMNAVN=="Bornholm") tm_shape(geo_RH) + tm_fill(col="Befolkning") + tm_borders() mainland <- tm_shape(mainland_data, projection = 0) + ...
-1
votes
1answer
42 views

Dealing with Islands with sf objects and the tmap package [closed]

I have the bounderies for the municipalities in the "capital region" of Denmark. The acctual map looks like this: The yellow island is the fourth row in my sf object. I am trying to folllow the ...
0
votes
1answer
32 views

How to I limit the x and y axes with tmap in r

I have made this plot with the following code: library(tmap) tm_shape(RH2) + tm_fill(col="AREAL") + tm_borders() But there is a dot on the far right (an island) which I don't ...
1
vote
1answer
30 views

Cluster geometries that touch each other

I'm trying to cluster the geometries in a sf object that touch each other. For the moment I'm using the same approach that it's explained in the answer here, but the problem is that the same idea ...
0
votes
0answers
48 views

Transforming CRS of Spatial Polygon Data Frame?

The code below shows the outline of Canada obtained from GDAM as a Spatial Polygons Dataframe with a CRS of EPSG:4326. I wish to transform this to EPSG:3857 (Mercator). Yet, I obtain the following ...
0
votes
0answers
47 views

Transforming multilinestrings to single linestring using R sf?

how to transform the following multilinestring in a linestring featuring the same aspect of the multilinestring (check against plot)? ml<-structure(list(geometry = structure(list(structure(list(...
1
vote
0answers
42 views

Performing PostGIS spatial joins with remote host?

I have approximately 600,000 points that must be joined to ~12 million polygons. This process happens weekly, with the potential to happen daily. The polygon data never changes, and is stored in a ...
0
votes
1answer
26 views

st_read option does not work if parameter is separated from equal (=) sign

This is a small pet peeve. I'm reading a latin1 encoded shapefile in R using st_read and the encoding option. I just found out that if I write encoding=latin1 everything works as expected but, if I ...
0
votes
1answer
34 views

Manipulating Elevation Data from the USGS National Map

I am trying out @tylermorganwall Rayshader R library. Some instructions are given here by tylermw8 to get elevation data from the USGS National Map. I am interested in obtaining data around the ...
1
vote
0answers
29 views

R Clip Simple Features Multiple Polygons with a Polygon (or another multi-polygon)

I have two polygon layers, a set of aquifer polygons and a set of district boundaries. I'm trying to clip the aquifer layers to be in only the districts that I want. From examining the other posts ...
1
vote
1answer
66 views

Snap to grid with sf in R

Is there a snap to grid function available in sf for R similar to ST_SnapToGrid(geometry geomA, float size)in PostGIS? It is mentioned as a solution to non-noded intersection problem for PostGIS and ...
1
vote
1answer
115 views

Inconsistencies in R rasterize polygons, packages raster and sf

I was trying to calculate species richness from IUCN distribution data in R, and I decided to check my results with two different methods, both of which rely on rasterize function from the raster ...
0
votes
0answers
204 views

spTransform error (unable to find inherited method for function spTransform)

I am trying to reproject a shapefile. For example, the land shapefile from Natural Earth. library(sf) shape <- read_sf(".../ne_10m_land.shp") shape_proj<-spTransform(shape, CRS("+proj=gnom +...
1
vote
3answers
131 views

st_intersection failing for overlapping multipolygons in sf

I'm working with some user classification data on a citizen science platform. The way our workflow works is to take multiple user classifications of areas, overlay them on one another, and then look ...
0
votes
1answer
37 views

How to create and empty SpatialLinesDataFrame in R

I need to create and SpatialLinesDataFrame with a predefined structure (9 fields). I'm performing a function over a list of shp which I want to append to this empty spatiallinesdataframe. I already ...
0
votes
1answer
38 views

How to use st_geometry_type() to filter an sf object in r?

Put together this code to filter an sf object by geometry type as suggested by @Spacedman here Posting here for others and for myself in case there are better ways to do this. types <- ...
2
votes
1answer
113 views

Load a CSV as Simple Features R

Is there a direct way to load a CSV as an sf? I've looked through the sf documentation and nothing jumps out at me, currently using: my_csv <- read.csv('my_data.csv', header = TRUE) my_sp <- ...
0
votes
1answer
217 views

Save/loading shapefiles with SF in R: no simple features geometry column present [closed]

I have this code: library('sf') #init data xes = c(-122.133533701866, -122.141590665524, -122.382782560179, -122.302227764504, -122.347524548303) yes = c(47.617342005802, 47.6102707417054, 47....
1
vote
1answer
75 views

Finding shortest path without barriers using the sf package in R

Say I have three ships near PNG in the pacific. I want to know the shortest path between all three, while not going aground. This can be done with the ArcGIS function "cost distance" and "shortest ...
0
votes
1answer
61 views

Count number of points on a line in R

I have a SpatialLinesDataFrame and a SpatialPointsDataFrame. I want to calculate the number of points that fall on a line by a specific field in the lines data frame. Example: I have a river network ...
1
vote
2answers
361 views

How to buffer a pair of longitude and latitude coordinates in R?

I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet or mapview. st_buffer, however, does not correctly buffer longitude/latitude data. ...
0
votes
0answers
129 views

using st_join for a spatial join

I am using the sf_package to work around spatial data in r. At this stage, I want to make a spatial join so that the tax lots of my area of study inherit the attributes of the floodplain on which they ...
1
vote
1answer
65 views

How to filter polygons by long/lat values using sf package in R?

Suppose t is: t <- structure(list(structure(list(structure(c(-89.990791, -89.990772, -89.990901, -89.99092, -89.990791, 30.727025, 30.727083, 30.727114, 30.727057, 30.727025), .Dim = c(5L, 2L))),...
3
votes
2answers
113 views

Sort data in an ascending order based on the geometry of an sf object in R (Sort by Lat/Long)

I am trying to sort my data based on the latitude and longitude. I have an sf object in R, which essentially stores the latitude and longitude as a separate column called geometry. See below: > ...
3
votes
2answers
115 views

conditional st_join and st_intersection in R (sf)

I just started working with the R sf package and am trying to rewrite a simple procedure from PostGIS to extract shared borders between polygons. In PostGIS, I usually do a "conditional" self-join ...
0
votes
1answer
40 views

Can't find my zip codes in TIGER/tigris

(This is my first attempt to use R, so I apologize for any stupidity. Also, please let me know if this is better posted in Stack Overflow.) I'm trying to use the Microsoft building footprint dataset ...
0
votes
0answers
48 views

Creating sf multiploygon from subset of points in grouped data?

I have a reproducible dataset with relocations of two animals (data below). For each location there is a DateTime stamp and a general season IndYearCorePeriod (Winter, Summer, and None). > head(...
1
vote
0answers
48 views

Spatial pattern analysis in R

This is a post originally posted on stacksoverflow, but I was recommended to post it here also. I have a lot of position data from fishing vessels, from where I would like to detect fishing ...
0
votes
0answers
64 views

The R sf package in spark using sparklyr

I am trying to use the sf package in R on a Spark cluster. Apperently the sf data.frame is not compatible with the spark RDD dataframe but I do not understand why this is. Question why is the list ...
0
votes
1answer
83 views

Taking 2 overlapping spatial polygon layers and creating 1 with features from one replacing those of other layer?

I have two sf multipolygon layers - one is a 5km buffer along the Mexico-US border and the other is an administrative 2-level layer of Mexico. I am trying to figure out how to layer these on top of ...
1
vote
1answer
68 views

Generating lines from coordinate file using R?

I have got an excel sheet with X and Y coordinates, actually Y is constant, since it is a straight line. I want a Shapefile with as many features as distance between points. I only get one line from ...
0
votes
1answer
55 views

Using R and SQL together in sf - what is an efficient workflow?

Do anyone have any tips/tricks/workflows for working with an SQL query within a read_sf/st_read function call in RStudio? (I am struggling to figure out how to make a postgrsql/postgis example ...