1 个不稳定版本
0.1.0 | 2023年1月11日 |
---|
4 在 #gdal 中
310KB
905 行
包含 (Zip文件,5KB) test_data/stations_shapefile.shp.zip
将GDAL兼容的地理空间数据读写到 Polars 和 GeoPolars。
支持将以下地理空间格式读写到/从Polars DataFrame中
- GeoJSON
- ShapeFiles
- 带有经纬度的CSV
- FlatGeobuf
- KML
- GPX
- PostGIS(通过网络)
- SpatialLite
- ... 以及 许多更多
示例1:来自文件的DataFrame
use polars_gdal::df_from_resource;
let df = df_from_resource("my_shapefile.shp", None).unwrap();
println!("{}", df);
示例2:来自原始字节的DataFrame
use polars_gdal::df_from_bytes;
let geojson = r#"{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"foo"},"geometry":{"type":"Point","coordinates":[1,2]}},{"type":"Feature","properties":{"name":"bar"},"geometry":{"type":"Point","coordinates":[3,4]}}]}"#.as_bytes();
let df = df_from_bytes(geojson, None, None).unwrap();
println!("{}", df);
示例3:来自GDAL层的DataFrame,带有过滤查询
use polars_gdal::{df_from_layer, gdal};
use gdal::vector::sql;
let dataset = gdal::Dataset::open("my_shapefile.shp")?;
let query = "SELECT kind, is_bridge, highway FROM my_shapefile WHERE highway = 'pedestrian'";
let mut result_set = dataset.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
let df = df_from_layer(&mut result_set, None).unwrap();
println!("{}", df);
示例4:来自具有自定义解析选项的经纬度CSV的DataFrame
let mut params = polars_gdal::Params::default();
let csv_parsing_options = ["EMPTY_STRING_AS_NULL=YES", "KEEP_GEOM_COLUMNS=NO", "X_POSSIBLE_NAMES=Lon*", "Y_POSSIBLE_NAMES=Lat*"];
params.open_options = Some(&csv_parsing_options);
let df = df_from_resource("lat_lon_countries.csv", Some(params)).unwrap();
println!("{}", df);
示例5:来自PostGIS表的DataFrame
use polars_gdal::{df_from_resource, Params};
let mut params = Params::default();
params.layer_name = Some("some_table_name");
let df = df_from_resource("postgresql://user:pass@host/db_name", Some(params)).unwrap();
println!("{}", df);
示例6:来自DataFrame的GeoJSON字节
use polars_gdal::{gdal, gdal_bytes_from_df, WriteParams};
let df: DataFrame = ...;
let json_driver = gdal::DriverManager::get_driver_by_name("GeoJSON")?;
let geojson_bytes = gdal_bytes_from_df(&df, &json_driver, None)?;
示例7:从DataFrame将shapefile写入磁盘
use polars_gdal::{gdal, gdal_resource_from_df, WriteParams};
let df: DataFrame = ...;
let shapefile_driver = gdal::DriverManager::get_driver_by_name("ESRI Shapefile")?;
let _dataset = gdal_resource_from_df(&df, &shapefile_driver, "/some/path/on/disk/my_shapefile.shp", None)?;
依赖关系
~32MB
~586K SLoC