sp

Using a simple for loop on spatial data

大憨熊 提交于 2020-01-03 15:37:06
问题 I'm sorry this is going to be a for loop 101 question. I am struggling to write a simple for loop to generate a table of distances between cities based upon longitude-latitude data locations <-read.csv("distances.csv") locations returns the following table: City Type long lat 1 Sheffield EUR -1.470085 53.38113 2 HK WRLD 114.109497 22.39643 3 Venice EUR 12.315515 45.44085 4 New York WRLD -74.005941 40.71278 My goal in this particular part of the task is to produce a table of the distances (in

Batch convert .csv files to .shp files in R

。_饼干妹妹 提交于 2019-12-25 06:39:23
问题 I am trying to convert a large number (>500) of text files into shapefiles. I can successfully convert a single .csv into a projected shapefile. And I can get lapply and 'for' loops to work when just loading, cleaning up, and exporting the text files. But the code fails when I add in steps to convert to shapefiles within the loops. Below are two ways I've tried tackling the problem and the associated error messages: General processing/definitions- library(rgdal) library(sp) crs.geo<-CRS("

How to calculate geographic distance between two points along a line in R?

女生的网名这么多〃 提交于 2019-12-24 07:26:12
问题 Inputs I have two shapefiles that I Import into R, so that I end up with. A spatiallinesdataframe containing bus routes. A spatialpointsdataframe containing bus stops. Plotting a given route with its stops looks like this. Sample Data This link includes two shapefiles to download as a zip with a sample two routes. Target My aim is to calculate the geographic distance in meters between every pair of stops: Stop 1 to Stop 2, Stop 2 to Stop 3, etc. across the length of the underlying bus route.

Is there an efficient way to group nearby locations based on longitude and latitude?

房东的猫 提交于 2019-12-24 03:45:10
问题 I'm trying to figure out a way to cluster multiple addresses based on proximity. I have latitude and longitude, which in this case is ideal, as some of the clusters would cross City/Zip boundaries. What I would have as a starting point is similar to this, but up to 10,000 rows within the table: Hospital.Addresses <- tibble(Hospital_Name = c("Massachusetts General Hospital","MGH - Blake Building","Shriners Hospitals for Children — Boston","Yale-New Haven Medical Center", "Memorial Sloan

Error: could not find function “overlay” after reinstall

二次信任 提交于 2019-12-24 00:35:51
问题 I reinstalled my pc and also reinstalled R, but I somehow get an error when running my R program: Error: could not find function "overlay" which was fine on the previous installation. The new R version is 3.2.4., so I tried to downgrade the version to 3.1.* and 3.0.*, but this was not helpful. Libraries I used are: library(sp) library(maptools) library(gstat) library(rgdal) library(sm) library(png) It seems like overlay is included in the sp package. I don't know what to do. 回答1: overlay is

Projection differences in R using sf and sp

余生颓废 提交于 2019-12-23 22:22:29
问题 I have a grid I have converted from GeoTIFFs to a shapefile. I would like to convert and export the shapefile as a GeoPackage and change the projection so it uses the British National Grid as the geographic coordinate system when opened in a GIS. However this only seems to work using sp and not sf (which does not appear to retain aspects like the datum). This is a problem as I would like to export GeoPackages containing multiple layers which you can only currently do in sf and not sp . Am I

Create square polygons from single centre coordinates and area in R

若如初见. 提交于 2019-12-23 12:34:30
问题 I am having issues plotting true to geographic extent pixels in R. the files come with a list of daily single coordinates and pixel size (area). There is also a Z element separate from this. The data structure looks this way: X <- c(1,3,6,7) Y <- c(3,2,7,8) Z <- c(38,23,12,12) Area <- c(32,23,45,67) The X and Y are in degrees longitude and latitude while the area is in square kilometres. I create the point features easily using: library(sp) A <- cbind(X,Y,Z,Area) B <- SpatialPoints(A) I plot

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

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