fn example_2() -> Result<(), Error> {
    let _ = fs::remove_file("/tmp/output2.geojson");
    let driver = Driver::get("GeoJSON")?;
    let mut ds = driver.create(Path::new("/tmp/output2.geojson"))?;
    let layer = ds.create_layer()?;

    layer.create_defn_fields(&[
        ("Name", OGRFieldType::OFTString),
        ("Value", OGRFieldType::OFTReal),
    ])?;

    layer.create_feature_fields(
        Geometry::from_wkt("POINT (45.21 21.76)")?,
        &["Name", "Value"],
        &[
            FieldValue::StringValue("Feature 1".to_string()),
            FieldValue::RealValue(45.78),
        ],
    )?;

    layer.create_feature_fields(
        Geometry::from_wkt("POINT (46.50 22.50)")?,
        &["Name", "Value"],
        &[
            FieldValue::StringValue("Feature 2".to_string()),
            FieldValue::RealValue(0.789),
        ],
    )?;

    // Feature creation triggering an error due to a wrong field name:
    match layer.create_feature_fields(
        Geometry::from_wkt("POINT (46.50 22.50)")?,
        &["Abcd", "Value"],
        &[
            FieldValue::StringValue("Feature 2".to_string()),
            FieldValue::RealValue(0.789),
        ],
    ) {
        Ok(v) => v,
        Err(err) => println!("{}", err),
    };

    Ok(())
}
/// Example 2, same output, shortened way:
Example 2, same output, shortened way.
Example 2 same output shortened way .
fn example_2() -> Result<(), Error> {
    let _ = fs::remove_file("/tmp/output2.geojson");
    let driver = Driver::get("GeoJSON")?;
    let mut ds = driver.create(Path::new("/tmp/output2.geojson"))?;
    let layer = ds.create_layer()?;
    layer.create_defn_fields(&[
        ("Name", OGRFieldType::OFTString),
        ("Value", OGRFieldType::OFTReal),
    ])?;
    layer.create_feature_fields(
        Geometry::from_wkt("POINT (45.21 21.76)")?,
        &["Name", "Value"],
        &[
            FieldValue::StringValue("Feature 1".to_string()),
            FieldValue::RealValue(45.78),
        ],
    )?;
    layer.create_feature_fields(
        Geometry::from_wkt("POINT (46.50 22.50)")?,
        &["Name", "Value"],
        &[
            FieldValue::StringValue("Feature 2".to_string()),
            FieldValue::RealValue(0.789),
        ],
    )?;
    // Feature creation triggering an error due to a wrong field name:
    match layer.create_feature_fields(
        Geometry::from_wkt("POINT (46.50 22.50)")?,
        &["Abcd", "Value"],
        &[
            FieldValue::StringValue("Feature 2".to_string()),
            FieldValue::RealValue(0.789),
        ],
    ) {
        Ok(v) => v,
        Err(err) => println!("{}", err),
    };
    Ok(())
}
fn example_2 ( ) -> Result < ( ) , Error > { let _ = fs :: remove_file ( " " ) ; let driver = Driver :: get ( " " ) ? ; let mut ds = driver . create ( Path :: new ( " " ) ) ? ; let layer = ds . create_layer ( ) ? ; layer . create_defn_fields ( & [ ( " " , OGRFieldType :: OFTString ) , ( " " , OGRFieldType :: OFTReal ) , ] ) ? ; layer . create_feature_fields ( Geometry :: from_wkt ( " " ) ? , & [ " " , " " ] , & [ FieldValue :: StringValue ( " " . to_string ( ) ) , FieldValue :: RealValue ( 45.78 ) , ] , ) ? ; layer . create_feature_fields ( Geometry :: from_wkt ( " " ) ? , & [ " " , " " ] , & [ FieldValue :: StringValue ( " " . to_string ( ) ) , FieldValue :: RealValue ( 0.789 ) , ] , ) ? ; // Feature creation triggering an error due to a wrong field name: match layer . create_feature_fields ( Geometry :: from_wkt ( " " ) ? , & [ " " , " " ] , & [ FieldValue :: StringValue ( " " . to_string ( ) ) , FieldValue :: RealValue ( 0.789 ) , ] , ) { Ok ( v ) => v , Err ( err ) => println ! ( " " err ) , } ; Ok ( ( ) ) }
Example 2, same output, shortened way:
Example 2 same output shortened way :