sf

Plotting static base map underneath a sf object

≯℡__Kan透↙ 提交于 2021-02-18 21:01:48
问题 I'm trying to plot a static base map underneath my sf object (for print). When using ggmap I first get a lot of errors, then I can't seem to figure out how to chain the base map to my ggplot2 object with a geom_sf . library(sf) # devtools::install_github("tidyverse/ggplot2") library(ggplot2) library(ggmap) nc <- st_read(system.file("shape/nc.shp", package="sf")) nc_map <- get_map(location = "North Carolina, NC", zoom = 7) ggmap(nc_map) nc_centers <- st_centroid(nc) nc_centers %>% ggplot() +

Merging polygons and summing their values

女生的网名这么多〃 提交于 2021-02-17 05:47:28
问题 I have a dataframe with many overlapping polygons that I would like to combine into a single shape with the value that equates to the sum of the values given to each infividual polygon. some example data: df <- data.frame(x = c(0.5, 1.5, 4.5, 5.5), y = c(1, 1, 1, 1), id = c('a', 'b', 'c', 'd'), score = c(1, 3, 2, 4)) s_df <- SpatialPointsDataFrame(df[, c('x', 'y')], df[, 3:4]) %>% as('sf') %>% st_buffer(dist = 1) plot(s_df) I can get the union of these polygons by using the st_union function

How to plot MULTILINESTRING in leaflet addPolylines?

梦想的初衷 提交于 2021-02-11 15:53:31
问题 The leaflet documentation says: Line and polygon data can come from a variety of sources: [...] MULTIPOLYGON, POLYGON, MULTILINESTRING, and LINESTRING objects (from the sf package) Yet how do I make use of such objects in leaflet? Here is a MULTILINESTRING example: # attach packages--------------------------------------------------------------- library(dplyr) library(sf) library(leaflet) # set up data ------------------------------------------------------------------ set.seed(5) data <-

Test intersection of two MULTIPOLYGONS based on year cycles in R

筅森魡賤 提交于 2021-02-10 17:36:23
问题 I have two multipolygons and I want to test intersections between their geometries based on groups of years. Basically I have a flood multipolygon that contains flood events and their geometry and an election dataset which has each election as ward*year units, containing the geometry of that ward. I want to see if there are any intersections in the electoral ward each cycle prior to each election. So if the election was in 2009 and the cycle was 2007-2009 I want to see if its ward was flooded

Querying SQL Server geospatial data from R

狂风中的少年 提交于 2021-02-08 20:52:47
问题 Edited: I have added login details to a demo SQL Server 2017. I am querying an SQL Server from R using the FreeTDS driver (preferred over the Microsoft odbc driver as it supports Windows authentication in Linux). I'm struggling to interpret the geometry column with st_read . The connection is initiated as such: library(odbc) library(DBI) library(sf) username <- 'SO-user' sql_server_ip <- '35.214.169.110' password <- 'SQLaskingfortrouble?!' con <- dbConnect(odbc(), Driver = "FreeTDS", Server =

remove mapedit features programmatically

依然范特西╮ 提交于 2021-02-08 20:33:39
问题 With mapedit it is possible to clear drawn features using the 'trash' icon built into the drawbar UI. It is also possible to clear features associated with the leaflet map using clearMarkers() and leafletProxy() , as laid out in this issue. However, leafletProxy does not clear any features drawn by the user. How do I programmatically clear these features? (e.g. after clicking an actionButton). Here is a simple shiny app and more explanation: library(mapedit) library(mapview) library(shiny) ui

remove mapedit features programmatically

喜你入骨 提交于 2021-02-08 20:29:31
问题 With mapedit it is possible to clear drawn features using the 'trash' icon built into the drawbar UI. It is also possible to clear features associated with the leaflet map using clearMarkers() and leafletProxy() , as laid out in this issue. However, leafletProxy does not clear any features drawn by the user. How do I programmatically clear these features? (e.g. after clicking an actionButton). Here is a simple shiny app and more explanation: library(mapedit) library(mapview) library(shiny) ui

compute pointwise distance by group in R with sf dplyr

怎甘沉沦 提交于 2021-02-07 23:02:14
问题 I have 2 dataframes. I want to compute the distance between all POINT geometries if the first frame with respect to a certain POINT in the second dataframe. The main feature of this problem is that I have a grouping variable in the first dataframe, and I would like to select the corresponding point to measure the distance to (in the second dataframe) according to this grouping indicator. I tried with group_by : library(sf) library(dplyr) d = data.frame(x = 1:10,y = 1:10, g = rep(c("a","b")

compute pointwise distance by group in R with sf dplyr

烈酒焚心 提交于 2021-02-07 23:01:14
问题 I have 2 dataframes. I want to compute the distance between all POINT geometries if the first frame with respect to a certain POINT in the second dataframe. The main feature of this problem is that I have a grouping variable in the first dataframe, and I would like to select the corresponding point to measure the distance to (in the second dataframe) according to this grouping indicator. I tried with group_by : library(sf) library(dplyr) d = data.frame(x = 1:10,y = 1:10, g = rep(c("a","b")

Select multiple items using map_click in leaflet, linked to selectizeInput() in shiny app (R)

一世执手 提交于 2021-02-07 03:46:37
问题 I would like to create a leaflet map where you can select multiple polygons and this will update the selectizeInput() in a shiny app. This would including removing a selected polygon, when it is removed in the selectizeInput() . I have slightly changed/updated the code from the answer here (use of sf instead of sp and more dplyr where I could work out what the base R was). The polygons could probably be updated with an observeEvent tied in with input$clicked_locations , but not sure exactly