我想为特定地理区域中的H3六角形生成shapefile 。特别是,我对分辨率为6、7和9的海湾地区感兴趣。如何为覆盖该区域的六边形创建shapefile?
我是shapefile或任何其他地理数据结构的新手。我对python和R最满意。
如果您正在寻找 中的解决方案R,该h3jsr软件包提供了对 Uber 的 H3 库的访问。可以使用函数h3jsr::polyfill()和来解决您的问题h3jsr::h3_to_polygon。
library(ggplot2)
library(h3jsr)
library(sf)
library(sf)
# read the shapefile of the polygon area you're interested in
nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
# projection
nc <- st_transform(nc, crs = 4326)
# get the unique h3 ids of the hexagons intersecting your polygon at a given resolution
nc_5 <- polyfill(nc, res = 5, simple = FALSE)
# pass the h3 ids to return the hexagonal grid
hex_grid5 <- unlist(nc_5$h3_polyfillers) %>% h3_to_polygon(simple = FALSE)
Run Code Online (Sandbox Code Playgroud)
这将返回以下多边形:
基本步骤如下:
polyfill方法以所需的分辨率用六边形填充多边形。h3ToGeoBoundary函数获得边界。ogr2ogr来转换为shapefile。Python绑定尚未发布,并且我对R绑定不熟悉,但是JavaScript版本可能如下所示:
var h3 = require('h3-js');
var bbox = [
[-123.308821530582, 38.28055644998254],
[-121.30037257250085, 38.28055644998254],
[-121.30037257250085, 37.242722073589164],
[-123.308821530582, 37.242722073589164]
];
var hexagons = h3.polyfill(bbox, 6, true);
var geojson = {
type: 'Feature',
geometry: {
type: 'MultiPolygon',
coordinates: hexagons.map(function toBoundary(hex) {
return [h3.h3ToGeoBoundary(hex, true)];
})
}
};
console.log(JSON.stringify(geojson));
Run Code Online (Sandbox Code Playgroud)
并且您将使用如下脚本:
node bbox-geojson.js | ogr2ogr -f "ESRI Shapefile" bbox-hexagons.shp /vsistdin/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |