sp

Adding CRS in sp seems inconsistent

瘦欲@ 提交于 2019-12-07 22:17:50
问题 I want to use the over() function from the sp package in R . I assigne a CRS . #say that polygon is EPSG3857 (Web Mercator PROJECTION) proj4string(finalPolygon) <- CRS("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs") and all seems good. str(finalPolygon) > ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot > .. .. ..@ projargs: chr "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1

Raster image seems to be shifted using leaflet for R

喜欢而已 提交于 2019-12-07 14:26:38
问题 I want to plot some spatial data using the leaflet package in R, however the generated raster image seems to be shifted compared to a reference grid. I suspect map projection issue, but I am not expert on the topic, so any help would be appreciated. Here is a minimal code to plot the map: library(leaflet) library(sp) library(raster) set.seed(111) # create dummy data -rectangular grid with random values m = 10 n = 10 x = seq(45,48,length.out = m) y = seq(15,18,length.out = n) X = matrix(rep(x,

Plotting Cities on a GADM map with R

百般思念 提交于 2019-12-07 10:03:33
问题 I am trying to draw detailed maps of States/Districts of India with GADM data and using R. I have used the following code # Load required libraries library(sp) library(RColorBrewer) # --------------------------------------------------------------------------- # load level 2 india data downloaded from http://gadm.org/country load("IND_adm2.RData") ind2 = gadm # plotting districts of a State, in this case West Bengal wb2 = (ind2[ind2$NAME_1=="West Bengal",]) spplot(wb2,"NAME_1", main = "West

readOGR (rgdal) fails to fetch polygon names from XML

限于喜欢 提交于 2019-12-06 13:21:04
I am trying to import an KML map of CCG boundaries in England ( Available here, 200Kb ) into R using readOGR function from package rgdal . My end-goal is to create a heat-map by colouring CCGs according to some associated value. I have a list with those values next to CCG names in one data frame. I need to match CCG names in that data frame with CCG names in the imported map object, and assign colours based on the value. However, I cannot see any CCG names imported in the map object, although they are present in the KML file. This is what I am doing: library(sp) library(rgdal) library(maps)

Fastest way to determine COUNTRY from millions of GPS coordinates [R]

给你一囗甜甜゛ 提交于 2019-12-06 06:41:07
问题 I have millions of GPS coordinates and want to quickly add a column of the country of the coordinates. My current method works but is extremely slow: library(data.table) #REPRODUCE DATA data <- data.table(latitude=sample(seq(47,52,by=0.001), 1000000, replace = TRUE), longitude=sample(seq(8,23,by=0.001), 1000000, replace = TRUE)) #REQUIRED PACKAGES if (!require("sp")) install.packages("sp") if (!require("rworldmap")) install.packages("rworldmap") if (!require("sf")) install.packages("sf")

Raster image seems to be shifted using leaflet for R

夙愿已清 提交于 2019-12-05 21:03:15
I want to plot some spatial data using the leaflet package in R, however the generated raster image seems to be shifted compared to a reference grid. I suspect map projection issue, but I am not expert on the topic, so any help would be appreciated. Here is a minimal code to plot the map: library(leaflet) library(sp) library(raster) set.seed(111) # create dummy data -rectangular grid with random values m = 10 n = 10 x = seq(45,48,length.out = m) y = seq(15,18,length.out = n) X = matrix(rep(x, each = n), nrow = n) Y = matrix(rep(y, m), nrow = n) # collector dataframe points = data.frame(value =

Plotting Cities on a GADM map with R

心已入冬 提交于 2019-12-05 12:37:09
I am trying to draw detailed maps of States/Districts of India with GADM data and using R. I have used the following code # Load required libraries library(sp) library(RColorBrewer) # --------------------------------------------------------------------------- # load level 2 india data downloaded from http://gadm.org/country load("IND_adm2.RData") ind2 = gadm # plotting districts of a State, in this case West Bengal wb2 = (ind2[ind2$NAME_1=="West Bengal",]) spplot(wb2,"NAME_1", main = "West Bengal Districts", colorkey=F, scales=list(draw=T)) to generate this map I am now trying to put in a

Custom placement of spplot legend in the map

心已入冬 提交于 2019-12-05 03:33:17
Is it possible to place the spplot (spplot polygons) legend within the map, in lower left corner, like this? The closest I've been able to get is this (I am not posting my data, I just use the example data instead, so in this case, try to place the legend in top left part of the map): data(meuse.grid) gridded(meuse.grid)=~x+y spplot(meuse.grid[,'dist'], colorkey = list(space = "left", height = 0.5) ) But the legend is in the middle of the page and is outside of the map. Unfortunatelly, colorkey argument doesn't support "bottomleft", or x, y, or corner arguments (see ?levelplot ). I also tried

Android屏幕计量单位详解

佐手、 提交于 2019-12-05 02:38:36
学习 Android 这么久,马上毕业要参加工作了,一直对 px 、 dip 、 sp 、 dp 这几个单位概念似懂非懂的,这次因为工作上的需要,网上搜了点资料并整理了下,写篇日志以便以后阅读。 1.px ( pixels )(像素) : 是屏幕的物理像素点 ,与密度相关,密度大了,单位面积上的 px 会比较多。通常不推荐使用这个。 2.dip 或 dp (与密度无关的像素) : 一个基于 density 的抽象单位, 这个和设备硬件有关,通常在开发中设置一些 view 的宽高推荐用这个,一般情况下,在不同分辨率,都不会有缩放的感觉。在运行时 , Android 根据使用中的屏幕的实际密度 , 透明地处理任何所需 dip 单位的缩放。 3.sp (与刻度无关的像素) : 同 dip/dp 相似,会根据用户的字体大小偏好来缩放,主要用于设置字体的大小 。 可能很多朋友对 dip 和 px 的区别,不是很清楚,包括我自己之前都没弄清楚,下面简单讨论一下: 首先明确一点: HVGA 屏 density=160 ; QVGA 屏 density=120 ; WVGA 屏 density=240 ; WQVGA 屏 density=120 density 值表示每英寸有多少个显示点,与分辨率是两个概念。 dip 到 px 的转换公式 : px = dip * (density / 160)

Fastest way to determine COUNTRY from millions of GPS coordinates [R]

丶灬走出姿态 提交于 2019-12-04 13:45:50
I have millions of GPS coordinates and want to quickly add a column of the country of the coordinates. My current method works but is extremely slow: library(data.table) #REPRODUCE DATA data <- data.table(latitude=sample(seq(47,52,by=0.001), 1000000, replace = TRUE), longitude=sample(seq(8,23,by=0.001), 1000000, replace = TRUE)) #REQUIRED PACKAGES if (!require("sp")) install.packages("sp") if (!require("rworldmap")) install.packages("rworldmap") if (!require("sf")) install.packages("sf") library(sp) library(rworldmap) library(sf) #CURRENT SLOW FUNCTION coords2country = function(points,latcol