sf

circle around a geographic point with st_buffer

浪子不回头ぞ 提交于 2019-12-23 09:15:09
问题 I would like to plot a circle 110 NM (nautical miles) around Dublin airport using sf package. (Later on I will intersect via st_intersect that with flight position reports from ADS-B.) I have defined a new unit for NM as follows: library(units) library(tidyverse) library(sf) NM <- make_unit("NM") install_conversion_constant("NM", "km", 1.852) Then defined Dublin airport coordinates: # DUB/EIDW location, see # https://skyvector.com/airport/EIDW/Dublin-Airport # Coordinates: # N53°25.28' / W6

Save a ggplot2 coord_map() chart in shapefile

守給你的承諾、 提交于 2019-12-22 17:05:25
问题 i need to export a contour map in CARTO (aka cartodb), so i'm trying to save this stat2density chart in a geodata file format like shapefile or geojson. I'm able to save it in SVG with ggsave, but would be very helpful to convert it in a spdf or sf oblejct. library(ggplot2) library(ggmap) data("crime") crime<- head(crime,1000) gg <- ggplot(aes(x = lon, y = lat), data=crime) + stat_density2d(aes(alpha=..level.., color=..level.., fill=..level..),geom='polygon', bins = 10, size=0.5) + scale

Convert sets of spatial coordinates to polygons in R using sf

六月ゝ 毕业季﹏ 提交于 2019-12-21 20:39:48
问题 Each element of my list contains a set of spatial coordinates that I would like to convert to polygons using sf. Each set of coordinates is sorted in the order I would like to "connect the dots" and the first and last rows are identical, to close the polygons. Each list element is named with a unique identifier which I would like to retain as an attribute in the sf output. I have adapted code from the sf-related answer here: Convert sequence of longitude and latitude to polygon via sf in R

Snap a point to the closest point on a line segment using sf

*爱你&永不变心* 提交于 2019-12-21 05:49:08
问题 I would like to snap a point to the closest point on a road segment using sf::st_snap . However, the function seems to return the wrong result, it's snapping my point to a point at the start of the road segment. Any ideas on how to fix this? Reproducible example provided below, including a comparision of the results I get when using sf::st_snap vs maptools::snapPointsToLines Using sf::st_snap # Max distance cut_dist = 200 # meters # snap points to closest road new_point <- sf::st_snap(point1,

Mapping different states with geom_sf using facet wrap and scales free

自古美人都是妖i 提交于 2019-12-21 03:59:29
问题 First, I am aware of this answer : Mapping different states in R using facet wrap But I work with object of library sf . It seems that facet_wrap(scales = "free") is not available for objects plotted with geom_sf in ggplot2. I get this message: Erreur : Free scales are only supported with coord_cartesian() and coord_flip() Is there any option I have missed ? Anyone has solve the problem without being forced to use cowplot (or any other gridarrange)? Indeed, here is an example. I would like to

Dissolving polygon features with the sf package

谁说胖子不能爱 提交于 2019-12-20 21:56:32
问题 Dissolve is a common geoproccessing technique discussed as an sf approach here. I'm trying to replicate dissolve as it functions in ArcGIS. Consider counties by two groups in ArcGIS. The ArcGIS dissolve command yields two polygons, regardless of the fact that the eastern peninsula consists of additional separate polygons. Like so: This is the functionality I'd like to replicate in sf, however I cannot as demonstrated below. nc <- st_read(system.file("shape/nc.shp", package="sf")) #create two

Efficient extraction of all sub-polygons generated by self-intersecting features in a MultiPolygon

回眸只為那壹抹淺笑 提交于 2019-12-20 11:14:09
问题 Starting from a shapefile containing a fairly large number (about 20000) of potentially partially-overlapping polygons, I'd need to extract all the sub-polygons originated by intersecting their different "boundaries". In practice, starting from some mock-up data: library(tibble) library(dplyr) library(sf) ncircles <- 9 rmax <- 120 x_limits <- c(-70,70) y_limits <- c(-30,30) set.seed(100) xy <- data.frame( id = paste0("id_", 1:ncircles), x = runif(ncircles, min(x_limits), max(x_limits)), y =

Make a SpatialPointsDataFrame with sf the fast way

佐手、 提交于 2019-12-20 05:19:26
问题 The task I'm trying to do is very simple with the sp package in R but I'm trying to learn sf hence my question. I'm trying to create a shape of points in R. I have lots of points so it has to be efficient. I've succeeded doing it in both sp and sf but the sf method is slow. Being new to sf , I have a feeling I'm not doing it the most efficient way. I've made 3 different functions which do the same thing: 1) 100% sp f_rgdal <- function(dat) { coordinates(dat) <- ~x+y } 2) 100% sf (probably bad

Create sf object from two-column matrix

那年仲夏 提交于 2019-12-19 02:32:34
问题 I have a simple two-column matrix that I want to convert to an sf object where each row specifies a point: > set.seed(123);m=matrix(runif(10),ncol=2) > m [,1] [,2] [1,] 0.2875775 0.0455565 [2,] 0.7883051 0.5281055 [3,] 0.4089769 0.8924190 [4,] 0.8830174 0.5514350 [5,] 0.9404673 0.4566147 The naivest approach doesn't work, as apply mashes the points back together into a matrix and the operation just becomes a very slow transpose function: > apply(m,1,st_point) [,1] [,2] [,3] [,4] [,5] [1,] 0

how to make a data frame into a simple features data frame?

。_饼干妹妹 提交于 2019-12-18 16:53:56
问题 I've got a table with place references and x and y coordinates in a given coordinate reference system. I want to turn that into a simple features data frame. How can I create that? I thought it might be: data_frame(place = "London", lat = 51.5074, lon = 0.1278, epsg = 4326) %>% group_by(place) %>% mutate(feature = st_point(c(lon, lat))) But that leads to an error: Error in mutate_impl(.data, dots) : Column feature must be length 1 (the group size), not 2 This is probably pretty simple to do,