输出属性表内容时,由于点线面会分别生成SHAPE,OBJECTID ;SHAPE,OBJECTID,SHAPE_Length; SHAPE,OBJECTID,SHAPE_Length,SHAPE_Area这几个字段,需要将他们分别找出来去掉这几个字段和字段里的内容,
所以可以先做判断,看属性表里是否存在该字段:
bool fieldName = dgvAttributesTable.Columns.Contains("OBJECTID"); 其中dgvAttributesTable是属性表的Name;
如果存在,将其删除
if (fieldName is true)
{
dgvAttributesTable.Columns.Remove("OBJECTID");
}
之后再进行属性表的内容输出:
for (int xattribute = 0; xattribute < dgvAttributesTable.Rows.Count - 1; xattribute++)
{
for (int yattribute = 0; yattribute < dgvAttributesTable.ColumnCount; yattribute++)
ColumnAttribute[xattribute] = dgvAttributesTable.Rows[xattribute].Cells[yattribute].Value.ToString();
if (yattribute < dgvAttributesTable.ColumnCount - 1)
{
swWriteFile.Write(ColumnAttribute[xattribute] + ",");//按点输出属性表
}
else
{
swWriteFile.Write(ColumnAttribute[xattribute]);//按点输出属性表
}
}
swWriteFile.WriteLine("");
}