sf

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

喜夏-厌秋 提交于 2021-02-07 03:45:23
问题 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

r - Create linestring from two points in same row in dataframe

余生颓废 提交于 2021-02-07 02:50:33
问题 I was wondering if there is a way to create linestring from two points given in the same row in a dataframe in a new geometry column. In other words longitudes and latitudes of the two points are given in a dataframe like the following: df <- data.frame(id = c("a", "b"), lon1 = c(1,2), lat1 = c(3,4), lon2 = c(5,6), lat2 = c(7,8)) where lon1 and lat1 represent the coordinates of the first point and lon2 and lat2 are the coordinates of the second point. The desired dataframe would have two rows

Combine Categorical and Gradient Fill in Geospatial - R

随声附和 提交于 2021-01-29 13:50:42
问题 I'm trying to fill a combined categorical and continuous variable on a map. So, for instance, in my minimally reproducible example below, say I want to display the number of KrispyKreme Donut shops in each county, which is generally a continuous variable I want to fill on a gradient. But I also have counties that forbid KrispyKremes indicated by a "-1" and those that have them under construction "-2". I want to display these in a different color not mapped on the gradient. I also have NA in

ggplot, sf package, How make simple pie graph on map

被刻印的时光 ゝ 提交于 2021-01-28 11:36:02
问题 I would like to make pie graph with ggplot and sf package. I have very simple data and un think there is simple method to do. All my data are pourcent : data <- data.frame(Territory = c(1, 2, 3, 4, 5), Pins = c(25, 45, 45, 60, 75), oak = c(45, 50, 45, 20, 15), land = c(30, 5, 10, 20, 10), sum = c(100, 100, 100, 100, 100)) And my graph code : read_sf("territories.shp") %>% left_join(data, by = "Territory") %>% ggplot() + geom_sf(aes(fill = Pins), color = "black") + theme_bw() + xlab("") + ylab

installing sf package with libraries in non-standard locations

℡╲_俬逩灬. 提交于 2021-01-28 06:28:16
问题 The required libraries are in non-standard locations and I can install rgdal by the command below: install.packages('rgdal', type = "source", configure.args=c('--with-gdal-config=/home/programs/anaconda3/bin/gdal-config', '--with-proj-include=/home/programs/anaconda3/include', '--with-proj-lib=/home/programs/anaconda3/lib')) But I can't install sf package. It keeps saying configure: error: proj_api.h not found in standard or given locations. . The installation code and output is below. Do you

st_join on geometry and grouping column together

不打扰是莪最后的温柔 提交于 2021-01-28 04:02:37
问题 If you have spatial point and polygon time series data, how do you do a spatial join/merge and "normal" merge of a non-spatial variable together? Point data over years that I want to merge into yearly polygons and then summarise ( xvar ) by year: #spatial point data by year library(sf) set.seed(10) df_point <- data.frame(id = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7), year = c(2016, 2017, 2018, 2019, 2016, 2017, 2018, 2019, 2016, 2017, 2016, 2017, 2016, 2017, 2016, 2017, 2016,

st_join on geometry and grouping column together

巧了我就是萌 提交于 2021-01-28 03:44:12
问题 If you have spatial point and polygon time series data, how do you do a spatial join/merge and "normal" merge of a non-spatial variable together? Point data over years that I want to merge into yearly polygons and then summarise ( xvar ) by year: #spatial point data by year library(sf) set.seed(10) df_point <- data.frame(id = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7), year = c(2016, 2017, 2018, 2019, 2016, 2017, 2018, 2019, 2016, 2017, 2016, 2017, 2016, 2017, 2016, 2017, 2016,

How to fill map boundaries with external images?

倖福魔咒の 提交于 2021-01-28 02:30:32
问题 I am creating a map of Brazil with its state boundaries, which is straight forward to achieve using ggplot2 and geom_sf . However, this time around, instead of color filling each state with data, I want to fill each state's boundaries with an external image (png), similar to this example of the largest employer in each state. I have tried a few settings of geom_image and even geom_flag to no avail (hence why I am not posting any code here). Are there any suggestions on how to approach this

Converting polygon to sf in R

浪子不回头ぞ 提交于 2021-01-27 21:07:24
问题 Using the tutorial here: https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-2.html (in the section called "States (polygon data)"), I'm trying to convert polygons to an sf object. library("maps") states <- st_as_sf(map("state", plot = FALSE, fill = TRUE)) head(states) I get the error message: Error in as_mapper(.f, ...) : argument ".f" is missing, with no default Thank you in advance! 回答1: Looks like it's confusing map() from the purrr package with map() from the maps package. Try: states <-

Count of sampling points within a grid cell

感情迁移 提交于 2021-01-24 11:33:35
问题 Calculate the total number of sampling points within each grid cell of a spatial grid. I would like to make a grid and calculate the total count of sampling points within each grid cell. I created a randomly generated data and grid, and tried to calculate the number of records within a grid cells using both the sf and raster packages, using previous similar SO questions, but wthout success. I have also looked into the extract function. Im fairly new to spatial analysis. library(sf) library