sf

Create a map with colored polygons and coordinate points by using a .shp file in combination with another dataframe with coordinates

妖精的绣舞 提交于 2019-12-02 08:30:04
I have the following map boundaries in this .gdb folder and here I have a csv which contains the variables that I want to plot and the coordinates of the points that need to be displayed on the map. My final goal is to create a map with polygons and inside every polygon there should be points according to the coordinates. Every polygon should be colored according to the count of studentid (students) for the year 2019. Any alternative is accepted I believe that the 1st code chunk below is correct: library(sf) library(tidyverse) library(data.table) library(tigris) library(leaflet) library

Make a SpatialPointsDataFrame with sf the fast way

两盒软妹~` 提交于 2019-12-02 05:22:24
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...) f_sf <- function(dat) { dat <- st_sfc( lapply( apply(dat[,c("x", "y")], 1, list), function(xx) st

Using st_read to import large geojson in iterations R

笑着哭i 提交于 2019-12-01 12:35:47
I want to import a very large geojson into a simple features object using st_read in R, however the hardware demands seem to be large when converting from geojson to sf. for example, importing the microsoft data for building footprints for Ohio ( https://github.com/Microsoft/USBuildingFootprints ) which is a 1.2 GB geojson eats up over 32 GB of RAM when converting. Is their a method for iterating through rows of a geojson in a function so I can import parts of the whole file without eating up all that RAM, similar to skip rows in read.csv? Using library(geojsonsf) seems to work without issue

Using st_read to import large geojson in iterations R

这一生的挚爱 提交于 2019-12-01 11:17:05
问题 I want to import a very large geojson into a simple features object using st_read in R, however the hardware demands seem to be large when converting from geojson to sf. for example, importing the microsoft data for building footprints for Ohio (https://github.com/Microsoft/USBuildingFootprints) which is a 1.2 GB geojson eats up over 32 GB of RAM when converting. Is their a method for iterating through rows of a geojson in a function so I can import parts of the whole file without eating up

Can't remove gridlines when plotting with geom_sf

℡╲_俬逩灬. 提交于 2019-12-01 03:14:48
The standard means of removing gridlines seem futile when plotting with geom_sf . For instance, if we plot a simple ggplot object, this works to remove the grid library(tidyverse) library(sf) mtcars %>% ggplot( aes(disp, hp) ) + geom_point() + theme( panel.grid.major = element_blank(), panel.grid.minor = element_blank() ) returns but the same code fails to remove the grid when you plot using geom_sf "shape/nc.shp" %>% system.file( package = "sf" ) %>% st_read( quiet = TRUE ) %>% ggplot() + geom_sf(aes(fill = AREA)) + theme( panel.grid.major = element_blank(), panel.grid.minor = element_blank()

Creating a regular polygon grid over a spatial extent, rotated by a given angle

我的梦境 提交于 2019-11-30 08:55:49
Hi all, I am struggling with this and hope someone could come out with a simple solution. My objective is to create a regular polygon grid over the extent of a polygon, but rotated by a user-defined angle . I know that I can easily create a North/South polygon grid in sf using for example: library(sf) #> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3 inpoly <- st_read(system.file("shape/nc.shp", package="sf"))[1,] %>% sf::st_transform(3857) %>% sf::st_geometry() grd <- sf::st_make_grid(inpoly, cellsize = 3000) plot(inpoly, col = "blue") plot(grd, add = TRUE) I also know that I can easily

Add line legend to geom_sf

给你一囗甜甜゛ 提交于 2019-11-28 08:25:24
问题 I have a couple spatial shape files with various public transport routes and I would like to make a map using ggplot2 and sf libraries. The issue here is that I manually assign colors to a few specific routes but I couldn't manage to add a legend to the plot. Any idea on how to do this using geom_sf ? Reproducible example library(sf) library(ggplot2) # reproducible data lon<-c(5.121420, 6.566502, 4.895168, 7.626135) lat<-c(52.09074, 53.21938, 52.37022, 51.96066) cities<-c('utrecht','groningen

How to put a geom_sf produced map on top of a ggmap produced raster

跟風遠走 提交于 2019-11-28 07:46:30
I tried the following code: library(ggplot2) library(ggmap) library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) str(nc) Classes ‘sf’ and 'data.frame': 100 obs. of 15 variables: $ AREA : num 0.114 0.061 0.143 0.07 0.153 0.097 0.062 0.091 0.118 0.124 ... $ PERIMETER: num 1.44 1.23 1.63 2.97 2.21 ... $ CNTY_ : num 1825 1827 1828 1831 1832 ... $ CNTY_ID : num 1825 1827 1828 1831 1832 ... $ NAME : Factor w/ 100 levels "Alamance","Alexander",..: 5 3 86 27 66 46 15 37 93 85 ... $ FIPS : Factor w/ 100 levels "37001","37003",..: 5 3 86 27 66 46 15 37 93 85 ... $ FIPSNO : num 37009

Convert sequence of longitude and latitude to polygon via sf in R

▼魔方 西西 提交于 2019-11-27 22:30:49
问题 I have five longitude and latitude that form a shape like this. df <- c(order=1:5, lon=c(119.4,119.4,119.4,119.5,119.5), lat=c(-5.192,-5.192,-5.187,-5.187,-5.191)) How could I easily convert them into an sf polygon data frame using sf package like this? ## Simple feature collection with 1 feature and 0 fields ## geometry type: POLYGON ## dimension: XY ## bbox: xmin: 119.4 ymin: -5.192 xmax: 119.5 ymax: -5.187 ## epsg (SRID): 4326 ## proj4string: +proj=longlat +datum=WGS84 +no_defs ## geometry

How to put a geom_sf produced map on top of a ggmap produced raster

自作多情 提交于 2019-11-26 16:35:38
问题 I tried the following code: library(ggplot2) library(ggmap) library(sf) nc <- st_read(system.file("shape/nc.shp", package = "sf")) str(nc) Classes ‘sf’ and 'data.frame': 100 obs. of 15 variables: $ AREA : num 0.114 0.061 0.143 0.07 0.153 0.097 0.062 0.091 0.118 0.124 ... $ PERIMETER: num 1.44 1.23 1.63 2.97 2.21 ... $ CNTY_ : num 1825 1827 1828 1831 1832 ... $ CNTY_ID : num 1825 1827 1828 1831 1832 ... $ NAME : Factor w/ 100 levels "Alamance","Alexander",..: 5 3 86 27 66 46 15 37 93 85 ... $