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
0answers
236 views

Correct Buffers crossing dateline in sf package in R

Using the global coral reef distribution data provided by UNEP https://data.unep-wcmc.org/datasets/1 I have been attempting to buffer around the points and polygons of coral reefs. The point buffers (...
1
vote
0answers
127 views

ggplot with island (“Alaska problem”)

The data for this example can be found here: https://github.com/davidbaniadam/maps The problem is essentially the same with Alaska and mainland USA, i.e. I want the size of Alaska to be correct in ...
1
vote
1answer
64 views

Point.in.polygon function in sf package miscalculate the distribution of points

I am using point.in.polygon function in sf package to determine whether a set of data fall within a polygon or not. Here is a snippet of the data and polygon visualization As the figure shows, there ...
2
votes
0answers
300 views

Union by new category using R and sf

I'd like to create a new shapefile or a new geometry variable that allows me to plot borders around regions in R. I'm using the sf and mapping with tmap. Basically, I'm adding a character vector to an ...
4
votes
1answer
605 views

Spatial 1 to 1 join by proximity in sf and R?

I'm trying to join a Simple Feature of POINT geometry type to another Simple Feature of POLYGON geometry type using st_join and nngeo::st_nn as the person asking this other question also did. The ...
6
votes
2answers
2k views

Converting points to polygons by group

I have a dataframe with around 40 points. They are grouped by an ID variable (their name), which four points in each group. I'm trying to turn these points into polygons, but I've had a lot of trouble ...
2
votes
1answer
1k views

Is it possible to independently adjust the simple size in the legend for tmap?

When trying to plot a dotmap with tmap: tm_shape(points)+ tm_dots(col="Party")+ tm_shape(districts)+ tm_borders(alpha=0.5)+ tm_legend() I want the points to remain at their original scale, but ...
0
votes
1answer
483 views

Draw a spatial grid with the lat/longs at the center of the grid using R

I looked through multiple posts on the same, and most of them end up drawing a grid connnecting the points or a grid connecting the bounding box of the coordinates. I need a grid with each of these ...
1
vote
0answers
24 views

Using for-loop to count intersections with bbox

I'm working on a project that involves counting how many crimes of a certain type happen within 150 meters or 500 meters of a list of addresses. While I've been able to do this successfully without a ...
1
vote
1answer
186 views

Making a for loop to count crimes within a certain distance

I'm working on a project that involves counting how many crimes of a certain type happen within 150 meters or 500 meters of a list of addresses. While I've been able to do this successfully without a ...
2
votes
2answers
2k views

Removing empty polygon from sf object in R?

I have such object: > p_mb Simple feature collection with 52 features and 0 fields (with 9 geometries empty) geometry type: GEOMETRY dimension: XY bbox: xmin: 585001.4 ymin: 211001....
3
votes
1answer
216 views

CRS validity and PROJ versions

I'm not sure where the right place to raise this is, so: The PROJ strings for EPSG codes 4151 and 4283 are identical: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs which is a hassle ...
1
vote
1answer
258 views

Randomly sample existing points from within polygons in SF | R

I have a set of existing sf points and want to randomly sample 1 point from each of a 1km2 grid cell over a landscape. I can create a grid of 1km2 polygons, but I can't work out in sf how to then ...
1
vote
1answer
568 views

st_write fails for object created with st_difference using R?

Using publicly available sea area shapefiles bahamas: http://www.marineregions.org/gazetteer.php?p=details&id=8404 ("eez.zip") watl: http://www.marineregions.org/gazetteer.php?p=details&id=...
0
votes
1answer
45 views

Finding datasets embedded in R GISTools package?

How can I find the embedded datasets in R package GISTools? I can find examples of datasets (Georgia, Newhaven etc.), but I cannot see exactly which datasets are available.
1
vote
0answers
496 views

Finding centrelines from polygons in R sf

Has anyone found a solution for turning polygons into centrelines using R? It has to be in R as I'm deploying it in parallel on a UNIX cluster. I've got as far as: library(sf) centreline <- ...
2
votes
1answer
133 views

Banding appears when reprojecting shapefiles using R?

I have downloaded a shape file (Marine Ecoregions (last one on the page)) from the nature conservancy http://maps.tnc.org/gis_data.html I am then using R and the sf package to project this shapefile. ...
2
votes
0answers
393 views

How to divide LINESTRING spatial network into equal length segments using R/sf?

I'm working on a project to model car crashes within the municipality of Milan using different statistical methods. I have a big dataset of all geocoded car accidents that happenend within the ...
1
vote
0answers
19 views

How to recognize original group from unified set of polygons in R

I have simple question. How can I know the original group after apply z = sf::st_union(x, y)? I have 2 sets: length(x[[1]]) = 4253, length(y[[1]]) = 91. Finally, I have z of lenght 411 but don't know ...
1
vote
1answer
543 views

How to build polygons from buffered points and merge overlapping ones using R?

I have a sample of 3 groups of points which are similarly spread within their groups. > pts x y [1,] 453067.5 364073.5 [2,] 453066.5 364072.5 [3,] 453068.5 364072.5 [4,] ...
2
votes
1answer
1k views

Using tmap for points in R?

I'm having a problem using tmaps to map out points in R. The data is taken from the Chicago data portal, and I was able to turn it into a sf object using the code below. However, when I try to use ...
0
votes
0answers
28 views

Using R for analysing relations between administrative borders (neighborhood of polygons) and voting results (or void votes)

What would be the relatively simple way to verify if there is a relationship between administrative borders (polygons) and voting results (like: void votes). This would be used to verify if voting ...
4
votes
1answer
3k views

sp::over vs sf::st_intersection in r

I was wondering why sf::st_intersection() takes too much time, in comparison with sp::over(); I use sf for pretty much all of my geospatial workflows (I was used to sp as well), and more and more ...
1
vote
1answer
1k views

Union, merge, intersection, join layers - logical difference and clear explanation for QGIS

I note that there are answers available on the difference between join and merge (e.g., Difference between 'join' and 'merge'?) that link to ArcGIS resources as a reference. However, I ...
0
votes
1answer
962 views

Use sf (R) to return the overlapping area between two polygons by rows?

I have two sfc data frames with the same number of rows (individual IDs), but each data frame contains a polygon assigned to the individual. For example, dataframe1 may have a circle assigned neared ...
2
votes
0answers
421 views

st_buffer() not preserving the shape of the original polygons [closed]

I am currently trying to create buffers of 5km around polygons of the region of interest. However, every time I increase the radius from 500 metres to 5000 metres, the shape of the buffer is not ...
1
vote
0answers
147 views

After installation of gdal (to enable PostGIS tools) on Windows, sf gives warnings about dependencies?

To get a PostgreSQL/PostGIS setup working on my Windows 10 machine I had to manually install GDAL using these instructions: https://sandbox.idre.ucla.edu/sandbox/tutorials/installing-gdal-for-windows ...
5
votes
1answer
3k views

Counting points in polygons with sf package of R? [closed]

I'm quite new to R and especially GIS with R. So recently I had to proceed to a quite simple analysis: counting health centers (points) per administrative unit (polygons). Quite common process in ...
3
votes
2answers
2k 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 ...
3
votes
2answers
116 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
406 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
88 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 ...
3
votes
1answer
402 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
3answers
129 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
188 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
49 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 ...
2
votes
2answers
3k 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
48 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 <- "+...
4
votes
1answer
341 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 ...
5
votes
2answers
2k 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 ...
1
vote
0answers
312 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
75 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
589 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
161 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
354 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
497 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
48 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
125 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 ...
3
votes
2answers
2k 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
340 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 ...

1
4
5
6 7 8