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)

0
votes
2answers
45 views

Dissolve only overlapping polygons in R using sf

I extracted information from open street map that contains many polygons, some of them overlapping. I want to union all polygons that overlap with other polygons. This question has been asked before ...
2
votes
2answers
33 views

st_transform producing spurious ribbons across region

I am trying to use st_transform on PERZONES shapefile available here . In its native projection, it looks like this: However, when I run the command: tansformedPF<-st_transform(PF,"+proj=sinu +...
1
vote
2answers
32 views

Create a circle in R, and plot it in a shapefile

I want to plot a circle with a radius of 5 miles around a hospital in Massachusetts. I was using some previous answers found here, but it is not working. st_buffer shows an error. library(sp) ...
3
votes
1answer
51 views

Same equal area projection results in different areas when shifting the center of projection

I found that using an equal area projection results in different areas for the same polygons if you shift the center of projection (ie to minimize the distortion of your area of interest when you ...
0
votes
1answer
25 views

Using st_read to create an owin in R

I have updated a program because readShapePoly has been replaced by st_read. Changing from: unzip(paste(mdir, "AU_Vic_POA_2011.zip", sep = "")) boundary.shp <- readShapePoly("...
1
vote
2answers
26 views

Errors fitting a Markvov Random Field GAM with multiple samples per Polygon

all, after reviewing this excellent tutorial, I'm trying to expand out my use of GAMs for space and time. I'm trying to use the Pennsylvania smoking and cancer data, but am running into a problem when ...
0
votes
1answer
46 views

Creating coordinate points based on polygon

I am trying to create coordinate points based on a polygon that I've created in Google Maps and imported into R as an sf object. Specifically I have sample points of physical samples I've taken, but ...
0
votes
2answers
28 views

How to save a plot to disc with tmap in R

I have made a plot with these lines mainland print(Bornhold, vp = viewport(x = 0.7, y = 0.5, width = 0.3, height = 0.2)) One is mainland and the other an island. How can I save it to one one png ...
0
votes
1answer
21 views

Using sf to combine polygons that share borders?

I have rows of respondents with their residential census tract polygon and am trying to generate first-order aggregated areas. Meaning I want a given respondent’s census tract polygon to be merged ...
1
vote
1answer
19 views

Avoiding/cleaning buffer artifacts in R

I'm trying to create a buffer around a multi-linestring object with st_buffer. Here's my initial attempt: library(rnaturalearth) library(dplyr) library(sf) library(rmapshaper) proj_sahel <- "+...
3
votes
1answer
54 views

Convert XYZ to stars curvilinear grid and plot

I have data in XYZ format (long, lat, elevation) that does not fit on a rectangular grid, but I would like to plot it as grid cells of different sizes. To illustrate what I mean, the last two plots ...
1
vote
2answers
62 views

Combining st_join with st_nn to include all points within, as well as within a given distance of a polygon

This is a follow up to my earlier question (Spatial join in R - Adding points to polygons with multiple corresponding points). I have successfully joined a spatial points file to a polygon file in R ...
0
votes
0answers
22 views

Aligning grid to polygon R sf

I am attempting to create a dataframe of point locations based on a polygon. Specifically, I am trying to estimate the locations of trees in an orchard. So I need regularly spaced points within this ...
1
vote
0answers
27 views

Problem of reversed coordinates (XY) when importing WFS data with st_read

This question was originally posted in StackOverflow. I am trying to use French spatial data distributed using WFS. I want to use these data in a Shiny app that allows the user to update the data, ...
0
votes
1answer
29 views

ArcGIS GeoPackage ArcMap Drawing Error [closed]

I am trying to understand the meaning of this error. I created spatial data using the sf package in R and wrote out the data as a GeoPackage (i.e. a .gpkg). However, whenever I add the data into ...
2
votes
1answer
30 views

Why does fasterize gives different output for multipolygons with and without internally resolved boundaries?

I was thrilled to be clued into the package fasterize, which speeds up the rasterization process in R tremendously. However, I cannot figure out why the fasterize() function outputs two different ...
0
votes
0answers
16 views

Convert DWG to Shapefile Using FME and R

I converted a DWG file to an ESRI Shapefile using FME Workbench. Now I wish to create an elevation raster. I'm not sure how to extract the elevation info. library(sp) library(raster) # https://www....
2
votes
1answer
29 views

Transform CRS of Shapefile in R

I started with an AutoCAD DWG file and used FME Workbench to extract elevation data into a shapefile. read_sf yields: > shapename Simple feature collection with 41620 features and 1 field (with ...
1
vote
1answer
29 views

Appending polygons in R using sf

I'm trying to create a multipolygon dataset where each row is identifiable. Example below library(sf) library(raster) # example raster data r <- brick(nl = 2, nrows = 5, ncols = 10) set.seed(54);...
1
vote
0answers
19 views

Set attribute length when exporting features with st_write

I have sf features that I have created/manipulated in R that I need to export to shapefile (my client only accepts shapefile format so I cannot use .gpkg or other formats). I have used st_write to ...
1
vote
0answers
62 views

Why shapefiles created with sf package (in R) do not display same CRS in ArcMap?

I have created a polygon shapefile in ArcMap using 7 points(lat,lon) then read this shapefile into R to obtain the CRS. I then created a shape file in R using the sf package (and the 7 points) and ...
0
votes
0answers
35 views

Calculate shortest path distance on a network with R, sf and stplanr

I want to estimate a spatial logistic regression model for car crashes in Milan using R. I downloaded data from OSM for several highways segments in Milan using the R package osmdata. The response ...
2
votes
2answers
94 views

Is there a way to clip a layer with a shape from another layer in `sf`?

I would like to get the greens polygons that intersects (or overlapsed) the red outlined polygon (see image below). I tried sf::st_intersection() but the polygon in yellow (yes that just one polygon) ...
0
votes
1answer
19 views

Plotting Geographical Grid from Long/Lat Coordinates in R

I have a file of coordinates (Long/Lat) that should enable me to plot a series of 10km grid squares covering the UK. However, for each grid square I have five sets of coordinates by way of plotting ...
3
votes
1answer
33 views

gIntersection error: linearRing not created

I am trying to do something relatively simple but with large shapefiles. I have a shapefile of protected areas in the USA: and watershed boundaries: I want to calculate the percentage and ...
1
vote
1answer
105 views

R sf count number of Polygons in Multipolygon

How can I count the number of polygons that are present in a multipolygon with the R package sf? Example: In the following image that represents a multipolygon I count 3 polygons. I want to be able to ...
0
votes
1answer
16 views

Set same dimensions multipolygon and point data

I'm trying to plot point data (coördinates) on a multipolygoon map. But I can't get them on top of each other and in the right shape. Underlying projection data of the Netherlands multipolygon data: ...
2
votes
2answers
39 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
61 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 ...
1
vote
1answer
29 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
47 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 ...
2
votes
1answer
55 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
57 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
80 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
44 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
83 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 ...
2
votes
1answer
97 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
82 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
45 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
41 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
264 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
32 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
171 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
89 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
52 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
76 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
42 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
174 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
71 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
43 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 ...