How to add your knowledge

Insert Data

    Table of contents
    1. 1. C#

    All providers except Gdal, Raster, WFS, and WMS allow you to insert data.

    C#

    The code sample shows how to insert a feature consisting of a data value and a geometry value.

    The following namespaces are used:

    • OSGeo.FDO.Commands
    • OSGeo.FDO.Commands.Feature
    • OSGeo.FDO.Expression
    • OSGeo.FDO.Geometry
    Identifier className = new Identifier("FeatureClass");
    IInsert insert = conn.CreateCommand(CommandType.CommandType_Insert) as IInsert;
    insert.FeatureClassName = className;
     PropertyValueCollection values = insert.PropertyValues;
    // add the Int32 value to the insert command
    int32Value = new Int32Value(5);
    int32PropVal = new PropertyValue("Int32Prop", int32Value);
    values.Add(int32PropVal);
    // add the feature geometry to the insert command
    FgfGeometryFactory geomFactory = new FgfGeometryFactory();
    DirectPositionImpl position1 = new DirectPositionImpl(1.0, 1.0);
    IPoint point = geomFactory.CreatePoint(position1);
    GeometryValue geomVal = new GeometryValue(geomFactory.GetFgf(point));
    PropertyValue geomPropVal = new PropertyValue("FeatGeomProp", geomVal);
    values.Add(geomPropVal);
    // insert the feature
    IFeatureReader reader = insert.Execute();
    reader.Close();