Hi,
I have the following code that I am using to output a shape file from all the features on a layer that I've created. The resultant points in the shape file appear fine; however, the column value information is not being written into the dbf file correctly.
DbfColumn dbfNameField = new DbfColumn("Name", DbfColumnType.String, 30, 0);
WellKnownType shapeType = WellKnownType.Point;
ShapeFileType shapeFileType = (ShapeFileType)shapeType;
ShapeFileFeatureSource.CreateShapeFile(shapeFileType,
shapeName, new DbfColumn[] { dbfNameField }, Encoding.Unicode, OverwriteMode.Overwrite);
ShapeFileFeatureSource shapeFileLayer = new ShapeFileFeatureSource(
shapeName, ShapeFileReadWriteMode.ReadWrite);
foreach (Layer layer in layerOverlay.Layers)
{
layer.Open();
InMemoryFeatureLayer fl = (InMemoryFeatureLayer)layer;
Collection<Feature> allFeatures = fl.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
Collection<FeatureSourceColumn> allColumns = fl.QueryTools.GetColumns();
foreach (Feature feature in allFeatures)
{
shapeFileLayer.Open();
Dictionary<string, string> shapeColumnValues = new Dictionary<string, string>();
BaseShape baseShape = feature.GetShape();
// Loop through all columns and add their values
foreach (FeatureSourceColumn column in allColumns)
{
string featureColumnValue = feature.ColumnValues[column.ColumnName].ToString();
shapeColumnValues.Add(column.ColumnName, featureColumnValue);
}
try
{
shapeFileLayer.BeginTransaction();
shapeFileLayer.AddFeature(baseShape, shapeColumnValues);
TransactionResult result = shapeFileLayer.CommitTransaction();
}
finally
{
shapeFileLayer.Close();
}
}
layer.Close();
}
I have validated that the data are being passed properly into the shapeColumnValues dictionary, but the resultant shape file only shows a field called "N a m e" spaced out very awkwardly and none of the 45 column values are included. I tried to upload the shape file with this message, but it said it wasn't allowed.