1

I tried searching the web to find a sample of showing how to add a Field to attribute table of an existing shapefile. For example I have a Shapefile at

C://data/Streets.shp

and need to add two field L_CITY and R_CITY both text and 50 characters limit. How can I do this in DotSpatial?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mona Coder
  • 6,212
  • 18
  • 66
  • 128

1 Answers1

1

The first thing you need to do is add a reference to System.Data. Otherwise, the type definition for the DataTable is not available and it may not be obvious what you can do to modify the schema.

Then you can use standard DataTable programming like the following code:

    public void AddFieldExample()
    {
        IFeatureSet fs = FeatureSet.OpenFile("C:\\YourShapefile.shp");
        DataTable table = fs.DataTable;
        DataColumn lCity = table.Columns.Add("L_CITY");
        lCity.MaxLength = 50;
        DataColumn rCity = table.Columns.Add("R_CITY");
        rCity.MaxLength = 50;

    }
Ted
  • 3,212
  • 25
  • 20