零拷贝读写地理空间数据。
GeoZero定义了一个用于读取地理空间数据格式的API,无需中间表示。它定义了可以实现的特征,用于读取和转换为任意格式或直接渲染几何图形。
支持的几何类型:
支持的维度:X, Y, Z, M, T
| 格式 | 读取 | 写入 | 备注 |
|---|---|---|---|
| GeoJSON | ✅ | ✅ | |
| GEOS | ✅ | ✅ | |
| GDAL | ✅ | ✅ | |
| WKB | ✅ | ✅ | 支持rust-postgres、SQLx和Diesel的PostGIS几何图形。同时也支持SQLx的GeoPackage几何图 形。 |
| WKT | ✅ | ✅ | |
| CSV | ✅ | ✅ | |
| SVG | ❌ | ✅ | |
| geo-types | ✅ | ✅ | |
| MVT(Mapbox矢量瓦片) | ✅ | ✅ | |
| GPX | ✅ | ❌ | |
| Shapefile | ✅ | ❌ | 通过geozero-shpcrate可用。 |
| FlatGeobuf | ✅ | ❌ | 通过flatgeobufcrate可用。 |
| GeoArrow | ✅ | ✅ | 通过geoarrowcrate可用。 |
| GeoParquet | ✅ | ✅ | 通过geoarrowcrate可用。 |
将GeoJSON多边形转换为geo-types并计算质心:
let geojson = GeoJson(r#"{"type": "Polygon", "coordinates": [[[0, 0], [10, 0], [10, 6], [0, 6], [0, 0]]]}"#); if let Ok(Geometry::Polygon(poly)) = geojson.to_geo() { assert_eq!(poly.centroid().unwrap(), Point::new(5.0, 3.0)); }
完整源代码:geo_types.rs
将GeoJSON转换为GEOS预处理几何图形:
let geojson = GeoJson(r#"{"type": "Polygon", "coordinates": [[[0, 0], [10, 0], [10, 6], [0, 6], [0, 0]]]}"#); let geom = geojson.to_geos().expect("GEOS转换失败"); let prepared_geom = geom.to_prepared_geom().expect("to_prepared_geom失败"); let geom2 = geos::Geometry::new_from_wkt("POINT (2.5 2.5)").expect("无效几何图形"); assert_eq!(prepared_geom.contains(&geom2), Ok(true));
完整源代码:geos.rs
将FlatGeobuf子集读取为GeoJSON:
let mut file = BufReader::new(File::open("countries.fgb")?); let mut fgb = FgbReader::open(&mut file)?.select_bbox(8.8, 47.2, 9.5, 55.3)?; println!("{}", fgb.to_json()?);
完整源代码:geojson.rs
将FlatGeobuf数据读取为geo-types几何图形,并使用polylabel-rs计算标签位置:
let mut file = BufReader::new(File::open("countries.fgb")?); let mut fgb = FgbReader::open(&mut file)?.select_all()?; while let Some(feature) = fgb.next()? { let name: String = feature.property("name").unwrap(); if let Ok(Geometry::MultiPolygon(mpoly)) = feature.to_geo() { if let Some(poly) = &mpoly.0.iter().next() { let label_pos = polylabel(&poly, &0.10).unwrap(); println!("{name}: {label_pos:?}"); } } }
完整源代码:polylabel.rs
使用rust-postgres选择和插入geo-types几何图形。需要with-postgis-postgres特性:
let mut client = Client::connect(&std::env::var("DATABASE_URL").unwrap(), NoTls)?; let row = client.query_one( "SELECT 'SRID=4326;POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))'::geometry", &[], )?; let value: wkb::Decode<geo_types::Geometry<f64>> = row.get(0); if let Some(geo_types::Geometry::Polygon(poly)) = value.geometry { assert_eq!( *poly.exterior(), vec![(0.0, 0.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0), (0.0, 0.0)].into() ); } // 插入几何图形 let geom: geo_types::Geometry<f64> = geo::Point::new(1.0, 3.0).into(); let _ = client.execute( "INSERT INTO point2d (datetimefield,geom) VALUES(now(),ST_SetSRID($1,4326))", &[&wkb::Encode(geom)], );
使用SQLx选择和插入geo-types几何图形。需要with-postgis-sqlx特性:
let pool = PgPoolOptions::new() .max_connections(5) .connect(&env::var("DATABASE_URL").unwrap()) .await?;
让 row: (wkb::Decode<geo_types::Geometry<f64>>,) = sqlx::query_as("SELECT 'SRID=4326;POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))'::geometry") .fetch_one(&pool) .await?; let value = row.0; if let Some(geo_types::Geometry::Polygon(poly)) = value.geometry { assert_eq!( *poly.exterior(), vec![(0.0, 0.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0), (0.0, 0.0)].into() ); }
// 插入几何体 let geom: geo_types::Geometry<f64> = geo::Point::new(10.0, 20.0).into(); let _ = sqlx::query( "INSERT INTO point2d (datetimefield,geom) VALUES(now(),ST_SetSRID($1,4326))", ) .bind(wkb::Encode(geom)) .execute(&pool) .await?;
使用编译时验证需要[类型重写](https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type):
```rust,ignore
let _ = sqlx::query!(
"INSERT INTO point2d (datetimefield, geom) VALUES(now(), $1::geometry)",
wkb::Encode(geom) as _
)
.execute(&pool)
.await?;
struct PointRec {
pub geom: wkb::Decode<geo_types::Geometry<f64>>,
pub datetimefield: Option<OffsetDateTime>,
}
let rec = sqlx::query_as!(
PointRec,
r#"SELECT datetimefield, geom as "geom!: _" FROM point2d"#
)
.fetch_one(&pool)
.await?;
assert_eq!(
rec.geom.geometry.unwrap(),
geo::Point::new(10.0, 20.0).into()
);
完整源代码:postgis.rs
计算输入几何体的顶点数:
struct VertexCounter(u64); impl GeomProcessor for VertexCounter { fn xy(&mut self, _x: f64, _y: f64, _idx: usize) -> Result<()> { self.0 += 1; Ok(()) } } let mut vertex_counter = VertexCounter(0); geometry.process(&mut vertex_counter, GeometryType::MultiPolygon)?;
完整源代码:geozero-api.rs
寻找3D多边形中的最大高度:
struct MaxHeightFinder(f64); impl GeomProcessor for MaxHeightFinder { fn coordinate(&mut self, _x: f64, _y: f64, z: Option<f64>, _m: Option<f64>, _t: Option<f64>, _tm: Option<u64>, _idx: usize) -> Result<()> { if let Some(z) = z { if z > self.0 { self.0 = z } } Ok(()) } } let mut max_finder = MaxHeightFinder(0.0); while let Some(feature) = fgb.next()? { let geometry = feature.geometry().unwrap(); geometry.process(&mut max_finder, GeometryType::MultiPolygon)?; }
完整源代码:geozero-api.rs
渲染多边形:
struct PathDrawer<'a> { canvas: &'a mut CanvasRenderingContext2D, path: Path2D, } impl<'a> GeomProcessor for PathDrawer<'a> { fn xy(&mut self, x: f64, y: f64, idx: usize) -> Result<()> { if idx == 0 { self.path.move_to(vec2f(x, y)); } else { self.path.line_to(vec2f(x, y)); } Ok(()) } fn linestring_end(&mut self, _tagged: bool, _idx: usize) -> Result<()> { self.path.close_path(); self.canvas.fill_path( mem::replace(&mut self.path, Path2D::new()), FillRule::Winding, ); Ok(()) } }
完整源代码:flatgeobuf-gpu
使用异步HTTP客户端读取FlatGeobuf数据集,应用边界框过滤器并转换为GeoJSON:
let url = "https://flatgeobuf.org/test/data/countries.fgb"; let mut fgb = HttpFgbReader::open(url) .await? .select_bbox(8.8, 47.2, 9.5, 55.3) .await?; let mut fout = BufWriter::new(File::create("countries.json")?); let mut json = GeoJsonWriter::new(&mut fout); fgb.process_features(&mut json).await?;
完整源代码:geojson.rs
使用kdbush创建KD树索引:
struct PointIndex { pos: usize, index: KDBush, } impl geozero::GeomProcessor for PointIndex { fn xy(&mut self, x: f64, y: f64, _idx: usize) -> Result<()> { self.index.add_point(self.pos, x, y); self.pos += 1; Ok(()) } } let mut points = PointIndex { pos: 0, index: KDBush::new(1249, DEFAULT_NODE_SIZE), }; read_geojson_geom(&mut f, &mut points)?; points.index.build_index();
完整源代码:kdbush.rs


全球首个AI音乐社区
音述AI是全球首个AI音乐社区,致力让每个人都能用音乐表达自我。音述AI提供零门槛AI创作工具,独创GETI法则帮助用户精准定义音乐风格,AI润色功能支持自动优化作品质感。音述AI支持交流讨论、二次创作与价值变现。针对中文用户的语言习惯与文化背景进行专门优化,支持国风融合、C-pop等本土音乐标签,让技术更好地承载人文表达。


阿里Qoder团队推出的桌面端AI智能体
QoderWork 是阿里推出的本地优先桌面 AI 智能体,适配 macOS14+/Windows10+,以自然语言交互实现文件管理、数据分析、AI 视觉生成、浏览器自动化等办公任务,自主拆解执行复杂工作流,数据本地运行零上传,技能市场可无限扩展,是高效的 Agentic 生产力办公助手。


一站式搞定所有学习需求
不再被海量信息淹没,开始真正理解知识。Lynote 可摘要 YouTube 视频、PDF、文章等内容。即时创建笔记,检测 AI 内容并下载资料,将您的学习效率提升 10 倍。


为AI短剧协作而生
专为AI短剧协作而生的AniShort正式发布,深度重构AI短剧全流程生产模式,整合创意策划、制作执行、实时协作、在线审片、资产复用等全链路功能,独创无限画布、双轨并行工业化工作流与Ani智能体助手,集成多款主流AI大模型,破解素材零散、版本混乱、沟通低效等行业痛点,助力3人团队效率提升800%,打造标准化、可追溯的AI短剧量产体系,是AI短剧团队协同创作、提升制作效率的核心工具。


能听懂你表达的视频模型
Seedance two是基于seedance2.0的中国大模型,支持图像、视频、音频、文本四种模态输入,表达方式更丰富,生成也更可控。


国内直接访问,限时3折
输入简单文字,生成想要的图片,纳米香蕉中文站 基于 Google 模型的 AI 图片生成网站,支持文字生图、图生图。官网价格限时3折活动


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号