Error in flatgeobuf

Hi ,

use std::io::{self, BufReader};
use flatgeobuf::*;

fn main() -> io::Result<()> {
    // Open the file
    let file_result = File::open("/usr/local/geo1/test3.fgb");

    // Handle the Result to get the File
    let file = match file_result {
        Ok(f) => f,
        Err(e) => {
            eprintln!("Error opening file   ***: {}", e);
            return Err(e.into());
        }
    };

    // Create a BufReader
    let mut filein = BufReader::new(file);

    // Open the FgbReader
    let fgb_result = FgbReader::open(&mut filein);

    // Handle the Result to get the FgbReader
    let fgb = match fgb_result {
        Ok(reader) => reader,
        Err(e) => {
            eprintln!("Error creating FgbReader: {}", e);
            return Err(io::Error::new(io::ErrorKind::Other, e));
        }
    };
    let count = fgb.select_all().unwrap();
    let feature = fgb.next().unwrap();
    Ok(())
}
    ```. here is the error ``` cargo build
   Compiling geo1 v0.1.0 (/usr/local/geo1)
error[E0599]: no method named `next` found for struct `flatgeobuf::FgbReader` in the current scope
  --> src/main.rs:33:23
   |
33 |     let feature = fgb.next().unwrap();
   |                       ^^^^ method not found in `FgbReader<&mut BufReader<File>>`
 ```. But all the examples I found  use 'next`.

FgbReader doesn't have a next method, but FeatureIter has. In your snippet, you get your FeatureIter through FgbReader::select_all, which you assign to count. So you need to continue with count, not with your fgb variable:

    ...
    let count = fgb.select_all().unwrap();
-   let feature = fgb.next().unwrap();
+   let feature = count.next().unwrap();
    Ok(())
}

As a side note, please put your ``` in new lines to get the formatting right. I.e. don't have any text on the same line as your ``` are. For example:

```
works
```
``` doesn't work

```
```

``` doesn't work either
2 Likes

Thank you.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.