Cristian,
I would be happy to show you a sample. Just to explain a little bit about how our API works. The layers that you typically use are a wrapper for a FeatureSource which supplies the data. The Layer itself like a ShapeFileLayer provides the zoom levels etc but it is the FeatureSource contained in it that is the heart of working with the data. The FeatureSource is a property of all vector oriented layers and you can get it by code like myShapeFileLayer.FeatureSource.
One important note is that FeatureSource is really an abstract class so the important APIs that are specific to that type of layer are on the specific FeatureSource. For example on a ShapefileLayer there is a FeatureSource but the FeatureSource it returns is really a ShapeFileFeatureSource so to get to the shape file specific stuff you need to cast it as below. Once you cast it you will find all kinds of useful functions that are shape file related. We didn't want to full expose them on the ShapeFileLayer as it would have added too many members to the object and we wanted the Layer itself to be easy to use and not so technical.
BuildRecId(@"C:\SomeShapefile.shp","RecId");
private void BuildRecId(string shapeFileName, string recIdColumnName)
{
ShapeFileFeatureSource featureSource = null;
try
{
// Open the shape file
featureSource = new ShapeFileFeatureSource(shapeFileName, ShapeFileReadWriteMode.ReadWrite);
featureSource.Open();
// Check to see if the RecId column exists
Collection<FeatureSourceColumn> columns = featureSource.GetColumns();
bool foundRecIdColumn = false;
foreach (FeatureSourceColumn column in columns)
{
if (string.Compare(column.ColumnName, recIdColumnName, true) == 0)
{
foundRecIdColumn = true;
break;
}
}
// If the RecId column is not found then we need to add it.
if (!foundRecIdColumn)
{
featureSource.AddColumnInteger(recIdColumnName.ToUpperInvariant(), 7);
}
// Loop through all of the records and update RecId column
int recordCount = featureSource.GetCount();
for (int i = 0; i < recordCount; i++)
{
featureSource.UpdateDbfData(i.ToString(), recIdColumnName.ToUpperInvariant(), (i + 1).ToString());
}
}
finally
{
if (featureSource != null && featureSource.IsOpen)
{
featureSource.Close();
}
}
}
David