Stack Exchange Network

Stack Exchange network consists of 174 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
0answers
26 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
20 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
19 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 ...
0
votes
0answers
10 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 ...
0
votes
0answers
19 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
0answers
45 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
38 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 +...
0
votes
3answers
58 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
26 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
21 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
45 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
86 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
38 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
47 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
155 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
62 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
20 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))),...
2
votes
2answers
73 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
67 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
21 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
26 views

Obtaining different linear entities?

I’m trying to get a shapefile with several feature lines, after export I have the shapefile with its attribute table, it seems to be 56 features. But actually, there is just one, I cannot do selection ...
0
votes
0answers
36 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
93 views

How to style KML through LIBKML layer creation options?

I am exporting a layer from PostgreSQL to KML using the sf package in R - though I am also capable of doing it directly with ogr2ogr. I get a workable KML that looks like this. <Placemark> ...
1
vote
0answers
45 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
50 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
68 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
63 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
40 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 ...
1
vote
0answers
58 views

Building footprint polygon from LoD1 CityGML 2.0 using R and sf?

I have LoD1 building data from a federal agency in Germany in the CityGML format. I would like to import and strip the data into R to get only the footprint of the buildings and an attribut about the ...
0
votes
1answer
50 views

r - turn off automatic ordering of linestrings when applying sf::st_intersection

This question is about how while using sf::st_intersection on a LINESTRING and a set of POLYGONs to get several LINESTRINGs in the CORRECT order. sf::st_intersection automatically orders the newly ...
3
votes
1answer
70 views

sf appears to truncate a projection string

Curious how folks deal with this type of thing where sf appears to trim the spatial projection: library(sf) library(sp) nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) ...
1
vote
1answer
50 views

Selecting all polygons along northern edge of shapefile in R

I have a shapefile of Mexico composed of Admin 2 polygons. I am trying to create a buffer along the Mexico-US border, in R considering this is a shapefile of Mexico only and I want to retain the ...
1
vote
1answer
83 views

Remove Duplicate Spatial Lines in R using SF Package

I want to remove duplicated/overlapping lines from a multiline layer using the sf package in R. The layer I have has a lot of attributes, and in many cases one line is recognized as 5 overlapping ...
0
votes
2answers
116 views

Convert shapefile into lat long points and export it as CSV in R?

I have a shapefile that I extracted form a compilation of species distributions taken from IUCN. > foo Simple feature collection with 1 feature and 27 fields geometry type: MULTIPOLYGON dimension:...
2
votes
1answer
46 views

How can / should sf spatial objects be translated (i.e. moved within same projection)?

Big fan of the sf (and previously, sp) spatial packages in R. I see spTransform and st_transform as methods to reproject a spatial object into a new space. However, I have a case where I have a ...
0
votes
1answer
207 views

ReadOGR/read_sf: Can't open shapefile

I am trying to open a shapefile (or the directory of the shapefile) in the same directory as my R file. I open it the following way: x<-c(farm,field,"ec",2017) #farm and field are variables that ...
2
votes
1answer
66 views

How do I use a Simple Feature Collection (sfc) from the sf package with the elevatr package to load elevation data?

I'm trying to load elevation data from AWS using the elevatr package, with a region defined as a Simple Features Collection from the sf package. Here's a simple example: library(elevatr) library(sf) ...
1
vote
1answer
37 views

Why do these coordinates not display correctly (or intersect correctly) with this boundary file?

This is a follow up to my previous question. I wrote code that imports the boundaries of a few US states, and, for some arbitrary point within those boundaries, buffers a circle around that point and ...
2
votes
1answer
66 views

Simplify a circle into square with SF

I want to obtain a square from a circle using simplification function in sf. This is my circle: With this code, I obtain a rhombus plot(st_simplify(st_geometry(sfdf),dTolerance = 1000)) How can I ...
1
vote
2answers
144 views

Creating lines between pairs of points

I have a sf dataframe table_sf as: Classes ‘sf’, ‘tbl_df’, ‘tbl’ and 'data.frame': 12251 obs. of 5 variables: $ ID : int 1 2 3 4 5 6 7 8 9 10 ... $ NOMBRE : chr "AL011900" "AL011900" "...
1
vote
1answer
71 views

How do I create a shapefile of circles of varying radii around lat/long points and map the overlap onto another shapefile?

I have a shapefile of US counties downloaded from the Census, a set of points, and a calculated radius around each point. I'm trying to draw a circle of that radius around each point, then plot the ...
0
votes
1answer
40 views

R sf extrapolate grid from centroids

I've got a grid/raster in R that is represented as centroids of the grid instead of polygons. I am trying to merge that with points. library(sf) nc <- st_read(system.file("shape/nc.shp", package="...
0
votes
0answers
315 views

Adding polylines to leaflet map in R

I am trying to add great circle routes between various regions in R. Here's the sample data: structure(list(CommencingRegion = c("RedSea", "EastAfrica", "GulfofMexico", "FarEast", "RedSea", "...
0
votes
0answers
34 views

How to compare points joined to grid, versus points joined to grid + 15km buffer, using sf package?

I have an issue where I'm spatially joining points to grid squares, but sometimes they're just barely out of range. To address this, I want to identify which points become incorporated into these ...
1
vote
1answer
95 views

RPostgres: No applicable method for 'st_as_sfc' applied to an object of class “pq_geometry”

Setup I am using sf::st_write() to load data into a PostGIS database. In order to do this, I first had to convert the geometry column of my dataframe from a character to a sfc vector. df$geom <- ...
1
vote
1answer
112 views

Convert a linestring into a closed polygon when the points are not in order

How can I convert an open linestring into a closed polygon, but when the points are not in order? Here is the easy case, when the points are in order (from an sf vignette): library(sf) #> Linking ...
2
votes
1answer
216 views

Calculating distances between consecutive points using R?

I have a simple features collection of points, where each point represents the location of an individual. I'd like to calculate the distance between successive points in the cleanest and most ...
0
votes
1answer
272 views

Calculate sum of line lengths in R

I have object1 with polygons and object2 with lines. I am looking for a way in R (preferably with the package sf) to calculate the sum of line lengths from object2 for each polygon in object1. The ...
1
vote
0answers
60 views

Nearest point does not intersect line in 'sf' R package

This is a similar question to my recent questions on how to find the nearest point along a polyline and how to split a polyline by an intersecting point using only the sf package. My question has ...
0
votes
1answer
87 views

Error loading netCDF data using sf package in R

I'm trying to use netCDF data, and would like to use sf rather than ncdf4 if it's already built to load netCDF data into sf objects. However, I'm finding that reading the file using sf::st_read isn't ...