- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 r 的新手,也是这个网站的新手。我在当前的分发项目中遇到了一些麻烦。我的目标是创建一个具有六边形的 map ,这些六边形具有基于不同属性的颜色渐变。例如六边形中的记录数、物种数、稀疏度等。我从两个 shapefile 开始。
一个是六边形:
具有 10242 个特征和 4 个字段的简单特征集合
几何类型:多边形
维度:XY
bbox: xmin: -180 ymin: -90 xmax: 180 ymax: 90
CRS:4326
前 10 个特征:
ID CENTRELAT CENTRELON AREA geometry
1 -43.06618 41.95708 41583.14 MULTIPOLYGON (((43.50039 -4...
2 -73.41802 -144.73583 41836.20 MULTIPOLYGON (((-147.695 -7...
4862 -82.71189 -73.45815 50247.96 MULTIPOLYGON (((-78.89901 -...
7162 88.01938 53.07438 50258.17 MULTIPOLYGON (((36.63494 87...
3 -75.32015 -145.44626 50215.61 MULTIPOLYGON (((-148.815 -7...
4 -77.21239 -146.36437 50225.85 MULTIPOLYGON (((-150.2982 -...
5 -79.11698 -147.60550 50234.84 MULTIPOLYGON (((-152.3518 -...
6 -81.03039 -149.37750 50242.49 MULTIPOLYGON (((-155.3729 -...
7 -82.94618 -152.11105 50248.70 MULTIPOLYGON (((-160.2168 -...
8 -84.84996 -156.85274 50253.03 MULTIPOLYGON (((-169.0374 -...
还有一张 map :几何类型:POLYGON;维度:XY; bbox:xmin:-180 ymin:-90 xmax:180 ymax:83.64513; CRS:4326
这是来自此链接的土地形状文件: natural earth data
我用 st_read 函数加载了它们。并使用以下代码创建了一个 map :
ggplot() +
geom_sf(data = hex5) +
geom_sf(data = land) +
coord_sf(1, xlim = c(100, 180), ylim = c(0, 90))
我有一个包含物种名称、经度和纬度的数据框。大约 6300 个条目。
scientific lat lon
1 Acoetes melanonota 11.75690 124.8010
2 Acoetes melanonota 11.97500 102.7350
3 Acoetes melanonota 13.33000 100.9200
4 Acrocirrus muroranensis 42.31400 140.9670
5 Acrocirrus uchidai 43.04800 144.8560
6 Acrocirrus validus 35.30000 139.4830
7 Acutomunna minuta 29.84047 130.9178
8 Admetella longipedata 13.35830 120.5090
9 Admetella longipedata 13.60310 120.7570
10 Aega acuticauda 11.95750 124.1780
如何将这些数据分箱到 map 的六边形中并使用渐变色为它们着色?
非常感谢!
最佳答案
据我了解,您有一些点和一些多边形。你想通过它们所在的多边形来总结点的值。我做了一个可能解决方案的可重现示例:
library(sf)
library(data.table)
library(dplyr)
# Create an exagonal grid
sfc = sf::st_sfc(sf::st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0)))))
G = sf::st_make_grid(sfc, cellsize = .1, square = FALSE)
# Convert to sf object
G = sf::st_as_sf(data.table(id_hex=1:76, geom=sf::st_as_text(G)), wkt='geom')
# Create random points on the grid with random value
n=500
p = data.table(id_point=1:n,
value = rnorm(n),
x=sample(seq(0,1,0.01), n, replace=T),
y=sample(seq(0,1,0.01), n, replace=T)
)
p = p[x >= y]
P = sf::st_as_sf(p, coords=c('x', 'y'))
# Plot geometry
plot(sf::st_geometry(G))
plot(P, add=TRUE)
# Join the geometries to associate each polygon to the points it contains
# Group by and summarise
J = sf::st_join(G, P, join=sf::st_contains) %>%
dplyr::group_by(id_hex) %>%
dplyr::summarise(sum_value=sum(value, na.rm=F),
count_value=length(value),
mean_value=mean(value, na.rm=F))
plot(J)
# Plot interactive map with mapview package
mapview::mapview(J, zcol="count_value") +
mapview::mapview(P)
由 reprex package 创建于 2020-04-25 (v0.3.0)
关于r - 如何将数据分箱到 shapefile 的六边形中并绘制它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61414897/
我想为 H3 生成 shapefile特定地理区域的六边形。特别是,我对分辨率为 6、7 和 9 的湾区感兴趣。如何为覆盖该区域的六边形创建 shapefile? 我是 shapefile 或任何其他
我有一个形状文件 (Sample.shp) 以及其他两个文件(Sample.shx 和 Sample.dbf),其中为孟买的 15 个 pincode 定义了几何图形(多边形)。 我可以使用快速入门教
我已经在这方面工作了一段时间并且取得了一些成功,但是在重写文件时,我没有。 我正在使用的 shapefile 是都市和小都市地区的多边形形状文件,但我对小都市地区不感兴趣,所以我正在使用 R 中的 s
我下载了波士顿的 shapefile,并想使用下面的代码将其绘制出来。然而它给了我一个错误 ValueError: lat_0 必须在 -90.000000 和 90.000000 度之间 原来coo
我正在使用 {raster} 来根据不规则形状文件(亚马逊生物群落)剪辑(或裁剪)栅格,但输出始终具有矩形范围。但是,我需要形状文件的完全相同的几何形状的输出。有小费吗?干杯。 library(ras
在 fiona 1.5.0 上(我很困惑为什么各种文件(例如 .dbf 和 .gdb)不打印我的“不是 Shapefile!”(这是我想要的文件不是 . shp) 退出前警告。 import fion
我正在尝试使用 python 中的 matplotlib 在世界地图上绘制国家/地区的填充多边形。 我有一个包含每个国家/地区边界坐标的 shapefile。现在,我想使用 matplotlib 将这
我使用 postgresql 9.1,postgis 2.0.1。为了将 shapefile 导入我的数据库,我使用 shp2pgsql。我尝试了很多导入这些 shapefile 的方法(shp2pg
有没有办法读取具有特定字符编码的形状文件?我正在尝试读取在某些名称中包含特殊(法语)字符的加拿大 shapefile。我可以手动转换它们,但如果我对某处的设置一无所知,我宁愿不这样做。 # manua
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
library(raster) admin <- getData('GADM', country='FRA', level=2) set.seed(123) id <- data.frame(ID_2
我目前有一个英国的 shapefile,并绘制了英国不同地区的物种种群。到目前为止,我刚刚绘制了 3 个物种种群水平,并将它们着色为红色 = 高、橙色 = 中、绿色 = 低。但我想做的是有一个渐变图,
Facebook 构建了它所谓的 relative wealth index适用于全局 > 1900 万个微型区域(2.4 公里网格单元)。他们已经 shared the data ( zip ) 在
在阅读了大量帖子和网站后,我无法找到如何从我的经纬度数据表中创建多边形 shapefile。我想创建这样的 map 。 我的csv数据文件包含地中海1000个点的经度、纬度和属性。我想按属性创建 sh
你好我尝试实现传单插入,以显示本地托管的 shapefile。 shapefile 的显示有效,但我想添加一个图层控件(用于切换 shapefile 图层)。插件链接:https://github.c
使用下面的代码,我可以创建一条折线并将其写入形状文件。但我也想读取Polyline类型的形状文件并将Point转换为x:f64和y:f64。 use shapefile::{Point, Polyli
我有一个包含亚马逊大河的 shapefile。仅 shapefile 就有 37.9 MB,连同属性表高达 42.1 MB。我正在生成所有巴西亚马逊的 PNG 图像,每个 1260x940 像素,sh
我正在尝试导入这样的形状文件: fn <- "Proj1" my_shp <- readShapeSpatial(fn) 在 Windows 计算机(32 位)上它工作正常,但是当我在 Ubuntu
我有一个导出 ArcGIS map 点的应用程序。 Spring MVC Controller 中的接收点。 我的指针有一个可变的属性列表。属性是具有两个值(名称和值)的字符串列表。代码: publi
我正在编写一个 map 应用程序,用于导入人口普查和 USGS 信息并将其显示为 Google map 上的叠加层。我想导出这些项目的混搭并导出为 Shapefile . 我使用 geotools 库
我是一名优秀的程序员,十分优秀!