fn example_1() -> Result<(), Error> {
    let _ = fs::remove_file("/tmp/output1.geojson");
    let drv = Driver::get("GeoJSON")?;
    let mut ds = drv.create(Path::new("/tmp/output1.geojson"))?;

    let lyr = ds.create_layer()?;

    let field_defn = FieldDefn::new("Name", OGRFieldType::OFTString)?;
    field_defn.set_width(80);
    field_defn.add_to_layer(lyr)?;

    let field_defn = FieldDefn::new("Value", OGRFieldType::OFTReal)?;
    field_defn.add_to_layer(lyr)?;

    let defn = Defn::from_layer(lyr);

    // 1st feature:
    let mut ft = Feature::new(&defn)?;
    ft.set_geometry(Geometry::from_wkt("POINT (45.21 21.76)")?)?;
    ft.set_field_string("Name", "Feature 1")?;
    ft.set_field_double("Value", 45.78)?;
    ft.create(lyr)?;

    // 2nd feature:
    let mut ft = Feature::new(&defn)?;
    ft.set_field_double("Value", 0.789)?;
    ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
    ft.set_field_string("Name", "Feature 2")?;
    ft.create(lyr)?;

    // Feature triggering an error due to a wrong field name:
    let mut ft = Feature::new(&defn)?;
    ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
    ft.set_field_string("Name", "Feature 2")?;
    match ft.set_field_double("Values", 0.789) {
        Ok(v) => v,
        Err(err) => println!("{}", err),
    };
    ft.create(lyr)?;

    Ok(())
}
/// Example 1, the detailed way:
Example 1, the detailed way.
Example 1 the detailed way .
fn example_1() -> Result<(), Error> {
    let _ = fs::remove_file("/tmp/output1.geojson");
    let drv = Driver::get("GeoJSON")?;
    let mut ds = drv.create(Path::new("/tmp/output1.geojson"))?;
    let lyr = ds.create_layer()?;
    let field_defn = FieldDefn::new("Name", OGRFieldType::OFTString)?;
    field_defn.set_width(80);
    field_defn.add_to_layer(lyr)?;
    let field_defn = FieldDefn::new("Value", OGRFieldType::OFTReal)?;
    field_defn.add_to_layer(lyr)?;
    let defn = Defn::from_layer(lyr);
    // 1st feature:
    let mut ft = Feature::new(&defn)?;
    ft.set_geometry(Geometry::from_wkt("POINT (45.21 21.76)")?)?;
    ft.set_field_string("Name", "Feature 1")?;
    ft.set_field_double("Value", 45.78)?;
    ft.create(lyr)?;
    // 2nd feature:
    let mut ft = Feature::new(&defn)?;
    ft.set_field_double("Value", 0.789)?;
    ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
    ft.set_field_string("Name", "Feature 2")?;
    ft.create(lyr)?;
    // Feature triggering an error due to a wrong field name:
    let mut ft = Feature::new(&defn)?;
    ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
    ft.set_field_string("Name", "Feature 2")?;
    match ft.set_field_double("Values", 0.789) {
        Ok(v) => v,
        Err(err) => println!("{}", err),
    };
    ft.create(lyr)?;
    Ok(())
}
fn example_1 ( ) -> Result < ( ) , Error > { let _ = fs :: remove_file ( " " ) ; let drv = Driver :: get ( " " ) ? ; let mut ds = drv . create ( Path :: new ( " " ) ) ? ; let lyr = ds . create_layer ( ) ? ; let field_defn = FieldDefn :: new ( " " , OGRFieldType :: OFTString ) ? ; field_defn . set_width ( 80 ) ; field_defn . add_to_layer ( lyr ) ? ; let field_defn = FieldDefn :: new ( " " , OGRFieldType :: OFTReal ) ? ; field_defn . add_to_layer ( lyr ) ? ; let defn = Defn :: from_layer ( lyr ) ; // 1st feature: let mut ft = Feature :: new ( & defn ) ? ; ft . set_geometry ( Geometry :: from_wkt ( " " ) ? ) ? ; ft . set_field_string ( " " , " " ) ? ; ft . set_field_double ( " " , 45.78 ) ? ; ft . create ( lyr ) ? ; // 2nd feature: let mut ft = Feature :: new ( & defn ) ? ; ft . set_field_double ( " " , 0.789 ) ? ; ft . set_geometry ( Geometry :: from_wkt ( " " ) ? ) ? ; ft . set_field_string ( " " , " " ) ? ; ft . create ( lyr ) ? ; // Feature triggering an error due to a wrong field name: let mut ft = Feature :: new ( & defn ) ? ; ft . set_geometry ( Geometry :: from_wkt ( " " ) ? ) ? ; ft . set_field_string ( " " , " " ) ? ; match ft . set_field_double ( " " , 0.789 ) { Ok ( v ) => v , Err ( err ) => println ! ( " " err ) , } ; ft . create ( lyr ) ? ; Ok ( ( ) ) }
Example 1, the detailed way:
Example 1 the detailed way :