sp

R - Fitting a grid over a City Map and inputting data into grid squares

女生的网名这么多〃 提交于 2019-12-04 10:21:38
I'm trying to place a grid over San Jose like this: Grid of San Jose You can make the grid visually using the following code: ca_cities = tigris::places(state = "CA") #using tigris package to get shape file of all CA cities sj = ca_cities[ca_cities$NAME == "San Jose",] #specifying to San Jose UTM_ZONE = "10" #the UTM zone for San Jose, will be used to convert the proj4string of sj into UTM main_sj = sj@polygons[[1]]@Polygons[[5]] #the portion of the shape file I focus on. This is the boundary of san jose #converting the main_sj polygon into a spatialpolygondataframe using the sp package tst_ps

Value of coordinates() for a SpatialPolygonsDataFrame object?

淺唱寂寞╮ 提交于 2019-12-04 04:57:28
问题 I am trying to get a pseudo barycenter for polygons in a spatial polygon dataframe. Today I stumbled upon the coordinates function that actually returns something for a SpatialPolygonsDataFrame . Unfortunately I found nothing in the help of coordinates about the value for SpatialPolygonsDataFrame . Could somebody tell me what these coordinates are? 回答1: It is the polygon centroid. The source code is found here, look for function FindCG . The equations computed are equivalent to those found on

Changing the Projection of Shapefile

这一生的挚爱 提交于 2019-12-04 03:32:59
I am trying to change or assign the projection of a Germany-Shapefile from NA to +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 , but somehow it doesn't work well. Reproducible Example: Shapefile and other files can be downloaded here : What I tried is the following: library(maptools) library(sp) library(rgeos) library(rgdal) projection.x <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0") mapG <- readShapePoly("vg2500_lan.shp", verbose=TRUE, proj4string=projection.x) summary(mapG) mapG <- spTransform(mapG, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

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

不想你离开。 提交于 2019-12-03 16:52:34
问题 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

SpatialPoints and SpatialPointsDataframe

亡梦爱人 提交于 2019-12-03 03:52:34
问题 Working with the sp package in R. I wonder when I would use SpatialPoints and when SpatialPointsDataframe. It seems so me that there is not much difference?! Is the only difference that in a SpatialPointsDataframe I can store more attributes?! If so, can I create a SpatialPointDataframe from an existing Dataframe (if coordinates are exisiting in this dataframe) without taking the detour of creating spatialPoints? 回答1: Both SpatialPoints and SpatialPointsDataFrame objects are S4 objects. It is

Efficient extraction of all sub-polygons generated by self-intersecting features in a MultiPolygon

≡放荡痞女 提交于 2019-12-03 01:19:06
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 = runif(ncircles, min(y_limits), max(y_limits))) %>% as_tibble() polys <- st_as_sf(xy, coords = c(2,3)) %>

How to change class from data frame to spatial polygon?

 ̄綄美尐妖づ 提交于 2019-12-02 23:35:30
问题 I have found the same in here How to Convert data frame to spatial coordinates. But in my case, I got very large data. exchange longitude latitude AB 103.3281386 1.594218196 AB 103.3285929 1.593990735 AB 103.3312494 1.591424235 AB 103.3283736 1.594063254 AB 103.3536164 1.622771588 AB 103.3613242 1.627138676 AB 103.3560151 1.619455334 AB 103.3297071 1.593398614 AB 103.3269466 1.596574285 AB 103.3279517 1.593614052 AB 103.3281356 1.593848271 AB 103.3567136 1.620498495 AB 103.3668021 1.63456952

SpatialPoints and SpatialPointsDataframe

↘锁芯ラ 提交于 2019-12-02 18:45:23
Working with the sp package in R. I wonder when I would use SpatialPoints and when SpatialPointsDataframe. It seems so me that there is not much difference?! Is the only difference that in a SpatialPointsDataframe I can store more attributes?! If so, can I create a SpatialPointDataframe from an existing Dataframe (if coordinates are exisiting in this dataframe) without taking the detour of creating spatialPoints? Both SpatialPoints and SpatialPointsDataFrame objects are S4 objects. It is true that the main structural difference is that, in the latter, there is an extra slot containing the

How to change class from data frame to spatial polygon?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 14:24:25
I have found the same in here How to Convert data frame to spatial coordinates . But in my case, I got very large data. exchange longitude latitude AB 103.3281386 1.594218196 AB 103.3285929 1.593990735 AB 103.3312494 1.591424235 AB 103.3283736 1.594063254 AB 103.3536164 1.622771588 AB 103.3613242 1.627138676 AB 103.3560151 1.619455334 AB 103.3297071 1.593398614 AB 103.3269466 1.596574285 AB 103.3279517 1.593614052 AB 103.3281356 1.593848271 AB 103.3567136 1.620498495 AB 103.3668021 1.63456952 AB 103.359686 1.624821271 AB 103.3308963 1.585290892 AB 103.3319569 1.59104387 AB 103.3307149 1

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