using the read_gdal() function #777
-
I am trying to use the I have a function like this that uses GDAL virtual file systems to download some data: pub fn download<T: Downloadable>(
downloadable_type: T,
scale: Scale,
) -> Result<RecordBatchReader, GeoArrowError> {
let url = downloadable_type.get_url(&scale);
let dataset = Dataset::open(url)?;
// Get the layer (assuming there is only one layer)
let mut layer = dataset.layer(0)?;
let reader = read_gdal(&mut layer, None)?;
Ok(reader.into())
} This partially works as I can get something from the In my fn main() {
let mut reader = download(url).unwrap();
// This is working
let schema = reader.schema().unwrap();
println!("{:?}", schema);
// This is not working (see the error below)
for batch_result in reader.take().unwrap() {
match batch_result {
Ok(batch) => {
println!("Batch ----");
let value = batch.column(4);
println!("{:?}", value);
}
Err(e) => eprintln!("Error reading batch: {:?}", e),
}
}
} When I try to iterate over the Error reading batch: CDataInterface("Calling get_next() on a freed OGRLayer is not supported")
Error reading batch: CDataInterface("Calling get_next() on a freed OGRLayer is not supported") Any ideas on what am I doing wrong here? Thank you for your time and the work you are doing on this project. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
I'm not at my computer right now but I'm not exactly sure. There might be issues on either the gdal or the rust side of closing the layer object when you access the schema? Does it work if you don't access the schema first? |
Beta Was this translation helpful? Give feedback.
-
Not, it does not matter if I read or not the schema. Thanks for looking into it. |
Beta Was this translation helpful? Give feedback.
-
@PMassicotte I verified in #778 that the GDAL example in the repo still works. You can run the local GDAL example with (Note: you'll have to pull the latest main first)
and that should print
I'm not familiar with how GDAL VFS works in the Rust API. Can you first verify that the local example works for you? |
Beta Was this translation helpful? Give feedback.
-
Otherwise, I haven't used the |
Beta Was this translation helpful? Give feedback.
-
Yes, this works now! Thank you very much. Aside question, would you recommend another way to read a shape file from a URL rather than using GDAL vrt? |
Beta Was this translation helpful? Give feedback.
-
That is pretty cool. Thanks again for your work! |
Beta Was this translation helpful? Give feedback.
@PMassicotte I verified in #778 that the GDAL example in the repo still works.
You can run the local GDAL example with (Note: you'll have to pull the latest main first)
and that should print