sf

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

。_饼干妹妹 提交于 2019-12-18 16:53:12
问题 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,

Changing CRS of a SF object

落花浮王杯 提交于 2019-12-14 01:50:23
问题 I have some 'roads' as a sp object: class : SpatialLinesDataFrame features : 17360 extent : 490176.4, 567680.9, 148639.1, 212821 (xmin, xmax, ymin, ymax) coord. ref. : +init=epsg:27700 +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 variables : 4 names : osm_id, lanes, type, width min values : 73, 2, motorway, 6.3 max values : 587969162, 6, trunk, 18.9 I convert

Overlaps of all objects within the same dataset in arcpy (st_overlaps)

谁说我不能喝 提交于 2019-12-13 18:15:06
问题 The R Package sf has an amazing set of functions under the title "Geometric binary predicates" which are described in detail here. As stated in the link, the functions are recursively applied to all geometries within the same dataset if only one sf -object is provided (see example below) If y is missing, st_predicate(x, x) is effectively called, and a square matrix is returned with diagonal elements st_predicate(x[i], x[i]) . Right now however, I'm building some tools where I am bound to

Transform a Multipolygon SF object in R from XY coordinates to lat/lon

别说谁变了你拦得住时间么 提交于 2019-12-13 07:47:26
问题 I have a shapefile where the coordinates are (I think) NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet (see Spatial Reference here ). I want to read the shapefile in using the sf package, then convert the MULTIPOLYGON geometry to lat/lon coordinates. Specifically, I want to convert to: NEW YORK LONG ISLAND STATE PLANE PROJECTION see: http://spatialreference.org/ref/esri/102718/ Example: library(tidyverse) library(sf) x<- structure(list(Borough = "MN", Block = 1L, Lot = 201L, ZipCode =

r gis: identify inner borders between polygons with sf

独自空忆成欢 提交于 2019-12-12 11:23:34
问题 This is an update of my previous similar question, the same task only I need to do it within sf framework. I need to identify the inner boundaries between polygons, red lines in this map. Within sp framework I used to utilize a self written function that wrapped @Spacedman's answer. Here it is: identify_borders <- function(SPolyDF){ require(rgeos) require(sp) borders <- gDifference( as(SPolyDF,"SpatialLines"), as(gUnaryUnion(SPolyDF),"SpatialLines"), byid=TRUE) df <- data.frame(len = sapply(1

Filter shapefile polygons by area

牧云@^-^@ 提交于 2019-12-12 04:44:04
问题 I have the following boundary dataset for the United Kingdom, which shows all the counties: library(raster) library(sp) library(ggplot) # Download the data GB <- getData('GADM', country="gbr", level=2) Using the subset function it is really easy to filter the shapefile polygons by an attribute in the data. For example, if I want to exclude Northern Ireland: GB_sub <- subset(UK, NAME_1 != "Northern Ireland") However, there are lots of small islands which distort the scale data range, as shown

SF on R 3.5 can't find correct version of gdal

谁说胖子不能爱 提交于 2019-12-12 00:54:33
问题 I had the sf package installed and working on r 3.4.3 on Centos 7. It was complicated to get the right version of GDAL but it was working and I was able to use tidycensus to make maps. However when I upgraded to R 3.5 and then attempted to upgrade or reinstall sf, I started getting this message: checking for gdal-config... /bin/gdal-config checking gdal-config usability... yes configure: GDAL: 1.11.4 checking GDAL version >= 2.0.0... no configure: error: sf is not compatible with GDAL

Unable to install ‘sf’ R package on Ubuntu 16.04 LTS

喜夏-厌秋 提交于 2019-12-11 15:28:53
问题 I'm not able to install sf R package on Ubuntu 16.04 LTS . I tried install.packages("sf") as well as devtools::install_github("r-spatial/sf") after running sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get update sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev Getting the following error message: configure: error: gdal-config not found or not executable. ERROR: configuration failed for package ‘sf’ Wonder what is the way to install sf ? 回答1: This

Drawing thicker state borders and thiner county borders for US map using GADM shapefile

这一生的挚爱 提交于 2019-12-11 14:59:31
问题 I have an earlier post here on drawing US maps using shape file from GADM while at the same time removing color mapping onto the Great Lakes region. The issue was solved following suggestion by @Majid. Now, I further want thicker state boders and thinner county borders. I did so by plotting county-level choropleth map first and then add additional lays of non-filled state/nation-level border: library(sf) library(tidyverse) library(RColorBrewer) #for some nice color palettes # US map

Custom key added to sf plot fails

陌路散爱 提交于 2019-12-11 07:45:41
问题 Trying to resolve this question I came up with this: library(sf) library(magrittr) library(RColorBrewer) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(crs = 4326) points <- data.frame(p = seq(15, 75, 15), long = c(-85, -80, -78, -75, -82), lat = c(34, 36, 37, 38, 35)) %>% st_as_sf(coords = c('long', 'lat'), crs = 4326) points$p_cut <- cut(points$p, seq(0, 100, 20)) layout(matrix(1:2, ncol = 2), widths = c(1, lcm(2))) # sf object with the extent of the points