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

Identify intersecting but not bordering polygons using SF package in R

I am trying to identify the set of polygons (census tracts) that intersect another polygon (a police district). When I use the sf_intersects function, I get all the polygons I expect but also a bunch ...
0
votes
1answer
14 views

Base-R legend for quick plot of sf-objects

I have two sf-objects that are polygons and one that is a layer of points. The attributes (columns) don't really matter for quick visualization purposes. I just want to make a basic legend and give ...
1
vote
1answer
38 views

Use sf::st_intersects for interiors of polygons, not boundary?

I need to run an error-check in R on polygons imported from shape files via sf::st_read. Polygons that share some boundary points are fine, but I need to throw an error if there are polygons that ...
0
votes
1answer
20 views

Check for NAs in `RasterLayer` and plot them in different colour

I know it's an easy question. But how can I find out whats the distribution of my NA-Values to non NA-Values? And how could I plot my raster normally and make the NA values appear in a different ...
1
vote
1answer
20 views

Remove z-value from XYZ point in sf

I have a sfc-object consisting of just points. Unfortunately, when I read in the shapefile, it created points of type XYZ. Now I removed some points and can't figure out how to export the remaining ...
2
votes
0answers
23 views

BoundingBox around plot in mapview

I wanted to plot some raster-data with mapview. I always get this greyish bounding box around my data though. Anybody an idea of what this might be? I just call mapview(<raster>)
2
votes
1answer
31 views

Measuring percentage overlap between home ranges and another shape file in R

I have tracking data from multiple animals and I have created kernel density estimates of their home ranges. I want to find out the proportion of each home range area that falls within protected areas....
1
vote
1answer
42 views

How to count the proportion of points in protected areas shape file using R packages?

I have some GPS relocation data and I want to calculate the proportion of those points that fall within protected areas. I'm downloading the protected areas using the wdpar package which uses sf to ...
1
vote
1answer
25 views

Calculating density within a shapefile (in R)

I'm trying to calculate density within a shapefile, but I'm fairly confident I'm doing it wrong. The idea is to figure out which geographical regions there have been the most sales by density. Here ...
1
vote
0answers
19 views

Is it necessary to use projected coordinate system for sf (function: st_nearest_feature) package? [closed]

I have two csv files, each with lat/long coordinates. I converted them into sf objects, giving each GCS (geographic coordinate system) crs. When I use the st_nearest_feature function, I get this ...
1
vote
0answers
8 views

Extrapolating point values to raster, excluding NAs

I have a raster generated from drone imagery that has been classified into water (river channel) and NA (all areas outside the wetted channel). I have a point file running down the center of the river ...
1
vote
1answer
25 views

Grouping by with multipolygon geometry with sf (using R)

I have a custom shapefile I put together. It works fine when I plot it all at once. But I'd like to group by certain variables to plot specific shaped regions. For example: +-------------+--------+---...
0
votes
1answer
47 views

Strange buffer of polygons in sf st_buffer()

I am trying out the R package sf function st_buffer(): outbuf <- st_buffer(inpoly,10) and get a buffer which looks strange. The buffer seems to be gridded in some way and does not cover the ...
1
vote
1answer
22 views

sf polygon to raster workflow to calculate least cost distance with gdistance in R

I need to calclulate the shortest distance from a set of points to other sets of points in a marine area. Travelling on land must not be possible so I understand I need to calculate the least cost ...
1
vote
0answers
18 views

Combining points that are close in space and time using R

I have table of data that contain 5 columns: Unique_ID, Date_time, Lat, Long, Incident_Count The sensors that supply this data often take what should be one occurrence, and split it up into several. ...
0
votes
1answer
23 views

Custom Legend Mapview

I want to add a really simple legend to my mapview-map. I have a sfc_MULTILINESTRING-object called path and a sfc_POINT-object called places. I just wanted to have a legend that shows a line and says "...
3
votes
0answers
42 views

Implementing PostGIS query using sf in R to make ST_Intersection faster

I'm trying to implement this query that speeds up st_intersections by using faster functions, namely ST_Contains and ST_Within, to do ST_Intersection only where absolutely necessary, from PostGIS to R ...
1
vote
0answers
32 views

Replicated Point Pattern: Get Density Variance Between Replicated Patterns and Subtract from Composite

I have written a lengthy code that dissects differently shaped/sized windows into recognizable components (individual cells in the image), gets the point density within each cell, then builds a whole ...
1
vote
1answer
40 views

Shapefile reprojection with “sf” R package doesn't work

I am using the sf R package to work with a shapefile (with a species distribution). > sp #this is the shapefile returns: Simple feature collection with 1 feature and 1 field geometry type: ...
2
votes
1answer
36 views

Updating GeoPackage records with R

I'd like to update records of a GeoPackage containing vector information in R. I've tried this: library(sf) library(RSQLite) nc <- st_read(system.file("shape/nc.shp", package="sf")) # Write Geo ...
1
vote
1answer
56 views

Weighted kernel density estimate mapping in R

I am trying to reproduce ArcGIS' kernel density in R. Specifically, I'd like to make a weighted kernel density map, like you see in Census OnTheMap (example). I am running into a lot of dead ends, ...
3
votes
1answer
42 views

Distance from multilinestring with sf

I have a MULTILINESTRING sf object, corresponding to rivers and I would like to create a raster containing the distance values to the closest river. I managed to get this with a single river but when ...
2
votes
1answer
44 views

Remove points that are close to a border when building a grid

I want to remove the points that are close to a boarder when building a grid, i am using the sf library from R. library(sf) library(raster) library(ggplot2) shp <- getData('GADM', country = 'aut',...
2
votes
1answer
86 views

calculate distance of points from centroid

I have a spatialpoints object, and a spatialpolygonsdataframe, composed of rectangular cells, and which the spatialpoints fall into. What I would like is to determine which polygon in the ...
2
votes
1answer
28 views

Convert sfc-column into two columns with their corresponding x and y coordinates

I have a sfc-column with just 6 points. I'd like to make these point to markers in a leaflet-map in R. So I thought that it would be a nice idea to convert them into two columns: x and y. The sfc-...
1
vote
1answer
28 views

ggplot2lend for sf-objects

I wanted to make a simple plot of four sf-objects which don't contain much more than the sfc-column and some postal-code information. The sf-objects have the names level 1-4 and plz. What I would ...
0
votes
0answers
38 views

Creating a pattern with certain parameters [R, spatstat, spatial, sf]

Let's say I want to create a pattern, that is based on numerous other patterns with similar shaped areas. Other than an average of the point densities in the rectangles, is there other patterning ...
1
vote
0answers
48 views

Cannot bind Legend layer to Polygon layer in Leaflet/R

I try to plot a map of concentrations of chemicals. These have very different ranges, so a shared legend is not feasible. The ultimate goal is to have the different layers for the different chemicals ...
0
votes
0answers
57 views

Is it possible to query a geopackage (.gpkg) for features within a given bounding box?

I have GIS data with a very large layer stored within a geopackage from where I want to select features that fall within a bounding box calculated in my R session. I begin by creating a query string: ...
1
vote
2answers
53 views

R sf Polygon subtract 1000 from x coordinates

My aim is to subtract a value of 1000 from all x coordinates of an R sf object. How can I achieve this? When running the following code the value 1000 is subtracted from all coordinates (x and y ...
1
vote
0answers
74 views

Unknown proj4: how to create custom proj4 from wkt?

I have a shapefile with a .prj file I've never seen before. In fact, it seems that GDAL doesn't even know what it is (see below). Therefore, when I read it into R with raster::shapefile() the CRS isn'...
0
votes
1answer
37 views

Error message when joining two dataframes with sf -Error: y should be a data.frame; for spatial joins, use st_join

In R, I'm trying to count the number of points which fall within a buffer around polygons and add the count result to the original shapefile from which the polygon file was created. I've followed the ...
1
vote
1answer
28 views

Connecting spatiallines or SpatialPoints based on minimum distance using R

Does anybody know of a way to create a single polygon (that will eventually be converted to an Owin) from either a spatialpoints object or a spatiallines object? Here is an example of each: Here's ...
2
votes
1answer
27 views

Aligning Multiple Polygons (Based on centroid possibly) [Spatstat, sf, sp]

I'm trying to create a composite/average of multiple similarly shaped polygons. I think the first step is most likely to align them via the centroid of each polygon. Does anybody know of a tool to ...
1
vote
1answer
33 views

Selecting polygons within another polygons [duplicate]

I have the same city map (BH city) for two different shapefiles with different locations. The first one is the "shared management", this one have bigger polygons, as we can see shared_management <-...
3
votes
1answer
75 views

'st_touches' from 'sf' R package does not return all boundaries

I am trying to get the total length of all the shared boundaries between cells in a grid (following this post). However, I noticed that some of the objects have no associated boundaries, even though ...
3
votes
1answer
44 views

Inconsistencies in st_contains function in R sf package

I am trying to identify, from a set of overlapping buffers, the smallest of their intersections. In other words (easier to understand if you look at the picture below), identify amonst all the ...
3
votes
2answers
91 views

Apply st_bbox() for each feature in sf

I have a set of polygons and I want to find the bbox for each polygon using sf. With st_bbox I obtain the bbox for the whole set of features but I want to obtain bbox for each feature. I try to use ...
1
vote
0answers
27 views

Iteratively join linestrings that intersect?

I'm struggling to iteratively join intersecting linestrings of a geometry collection using st_join, meaning I want to join intersecting linestrings, but want to build on that join (i.e. joining all ...
2
votes
1answer
40 views

Calculating destination point using sf package

I have the following data: lat <- c(-1.404361, -1.403221,-1.387369) long <- c(35.35373, 35.35047,35.35171 ) distance <- c(220,150,300) bearing <- c(67,27,159) df <- data.frame(lat,...
1
vote
1answer
33 views

Generating pattern in each of set of polygons using sp (r)?

I have an object of class SpatialPolygonsDataFrame, and for each polygon in the dataframe I have a number of points I would like to generate in that polygon (e.g. I have 130 polygons, and I have a ...
2
votes
0answers
36 views

Row-wise Reprojection of SPDF in R [closed]

I have multipolygons that span across the globe. I was wondering if it was possible to re-project each row, i.e. each country/ ISO3 to a local projection, using a central grouping mechanism. For ...
2
votes
1answer
137 views

R (spatstat, sp, sf): Grid a single polygon, divide, alphanumeric labels based on column/row

I am trying to take a polygon and add grid lines over top, then divide the polygon into many polygons based on the grids. I've accomplished this through st_make_grid() and raster::intersect(). The ...
0
votes
0answers
24 views

Calculate the sinuoisty of a line

I have an sf polyline layer in R an would like to calculate the sinuosity (i.e. actual length of segment divided by the shortest distance between start and endpoint). Does anyone know of a function ...
2
votes
2answers
53 views

Loading shapefiles for reprojection using sf

I'm trying to automate my workflow, but having trouble with one step. My data come as processed shapefiles saved in .RDA files; I load them to a PostGIS system, cleaning up little issues (spTransform()...
1
vote
1answer
100 views

How to convert a polygon to a polyline using the sf package in R?

I have some simple polygons that I would like to convert to polylines using the sf package in R. I have found st_polygonize to convert polylines to polygons but I cannot but the reserve operation. ...
1
vote
0answers
111 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
72 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
54 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 ...
1
vote
0answers
62 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 ...