#read-write #shapes #gis #write-file #polyline #points #shapefiles

shapefile

Rust中读取和写入shapefile

14个不稳定版本 (6个破坏性版本)

0.6.0 2024年3月23日
0.5.0 2023年8月8日
0.4.0 2023年2月27日
0.3.0 2021年4月28日
0.0.1 2015年1月21日

#89 in 算法

Download history · Rust 包仓库 1414/week @ 2024-04-20 · Rust 包仓库 1355/week @ 2024-04-27 · Rust 包仓库 1183/week @ 2024-05-04 · Rust 包仓库 1584/week @ 2024-05-11 · Rust 包仓库 2027/week @ 2024-05-18 · Rust 包仓库 1467/week @ 2024-05-25 · Rust 包仓库 2135/week @ 2024-06-01 · Rust 包仓库 2198/week @ 2024-06-08 · Rust 包仓库 1779/week @ 2024-06-15 · Rust 包仓库 2001/week @ 2024-06-22 · Rust 包仓库 1535/week @ 2024-06-29 · Rust 包仓库 2248/week @ 2024-07-06 · Rust 包仓库 2049/week @ 2024-07-13 · Rust 包仓库 2650/week @ 2024-07-20 · Rust 包仓库 2820/week @ 2024-07-27 · Rust 包仓库 1765/week @ 2024-08-03 · Rust 包仓库

9,765 每月下载量
用于 8 crates

MIT 协议

200KB
4.5K SLoC

shapefile-rs

Rust库,用于读取和写入shapefile .dbf文件,通过dbase crate支持

let mut reader = shapefile::Reader::from_path(filename).unwrap();

for result in reader.iter_shapes_and_records() {
    let (shape, record) = result.unwrap();
    println ! ("Shape: {}, records: ", shape);
    for (name, value) in record {
        println ! ("\t{}: {:?}, ", name, value);
    }
    println ! ();
}

您可以在示例文件夹中查看示例


lib.rs:

Rust中读取Shapefile

实际上,shapefile是一个包含3个必选文件的集合

  • .shp (特征几何形状,即形状)
  • .shx (特征几何形状索引)
  • .dbf (属性信息,即记录)

由于不同的shapefile可以存储不同类型的形状(但一个shapefile只能存储同一类型的形状),此库提供两种读取形状的方法

  1. 将形状读取为Shape,然后进行match来处理不同的形状
  2. 直接将形状读取为具体形状(例如Polyline、PolylineZ、Point等),当然,这仅在文件实际上包含与请求类型匹配的形状时才有效

Shapefiles形状

PointPointMPointZ是shapefile的基本数据类型,其他形状(如Polyline, Multipoint)是这些类型的点的集合,具有不同的语义(多个部分或没有,封闭部分或没有等)

除了Multipatch 形状外,每种点类型都有自己的形状变体。(Multipatch 总是使用 PointZ) 例如:对于折线,有 PolylinePolylineMPolylineZ

读取

有关详细信息,请参阅读取器模块

写入

要写入文件,请参阅写入器模块

功能

可以通过启用geo-types功能来访问FromTryFrom实现,允许在shapefile的类型和geo_types中的类型之间相互转换(或尝试转换)

依赖项

~1MB
~22K SLoC