georust/gdal

can't read shp file.

yuyang-ok opened this issue · 2 comments

Hey I am newbee to gdal.
I have this code.

fn main() {
    use gdal::{Dataset, Metadata};
    use std::path::Path;

    let driver = gdal::DriverManager::get_driver_by_name("ESRI Shapefile").unwrap();
    println!("driver description: {:?}", driver.description());

    let path = Path::new("/home/yuyang/Downloads/map.shp");
    let dataset = Dataset::open(path).unwrap();
    println!("dataset description: {:?}", dataset.description());

    let key = "INTERLEAVE";
    let domain = "IMAGE_STRUCTURE";
    let meta = dataset.metadata_item(key, domain);
    println!("domain: {domain:?} key: {key:?} -> value: {meta:?}");
}
driver description: Ok("ESRI Shapefile")
ERROR 4: Unable to open /home/yuyang/Downloads/map.shx or /home/yuyang/Downloads/map.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it.
thread 'main' panicked at src/main.rs:9:39:
called `Result::unwrap()` on an `Err` value: NullPointer { method_name: "GDALOpenEx", msg: "Unable to open /home/yuyang/Downloads/map.shx or /home/yuyang/Downloads/map.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it." }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1652:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1077:23
   4: gdal_test::main
             at ./src/main.rs:9:19
   5: core::ops::function::FnOnce::call_once
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I have this file

yuyang@yuyang-virtual-machine:~/sometests/gdal_test$ file /home/yuyang/Downloads/map.shp 
/home/yuyang/Downloads/map.shp: ESRI Shapefile version 1000 length 170042 type Polygon

Shapefiles are actually sets of multiple files. You don't need the shx, as the message says, but you're still going to miss the attributes. It would be best to ask for the full set of files.

And if you run ogrinfo, you'll get the same error.

@lnicola Thanks。