Design Interface
Create class
The Code is as follows:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Threading. tasks;
Using ESRI. ArcGIS. controls;
Using system. Data;
Using ESRI. ArcGIS. CARTO;
Using ESRI. ArcGIS. Geodatabase;
Using ESRI. ArcGIS. geometry;
Namespace Test
{
Public class datahelper
{
# Region read the mapcontrol Attribute Table
Public static datatable getattribute (axmapcontrol)
{
Int layercount = axmapcontrol. Map. layercount;
// Ifeature pfeature;
String fieldname = string. empty;
Int fieldcount;
Bool firstthroght = true;
Datatable = new datatable ();
// Loop layer to obtain data for each layer
For (int l = 0; L <layercount; l ++)
{
Ifeaturelayer pfeaturelayer = axmapcontrol. Map. get_layer (l) as ifeaturelayer;
Ifeatureclass pfeatureclass = pfeaturelayer. featureclass;
Fieldcount = pfeatureclass. Fields. fieldcount;
Int featurecount = pfeatureclass. featurecount (New queryfilterclass ());
If (firstthroght)
{
For (INT I = 0; I <fieldcount; I ++)
{
String fieldheadname = pfeatureclass. Fields. get_field (I). aliasname;
Datatable. Columns. Add (fieldheadname );
}
Firstthroght = false;
}
// Determine the feature type
Int indexofshape = pfeatureclass. findfield ("shape ");
ESRI. ArcGIS. Geometry. esrigeometrytype pfeatureclassshapetype = pfeatureclass. shapetype;
For (INT I = 0; I <featurecount; I ++)
{
Datarow = datatable. newrow ();
For (Int J = 0; j <fieldcount; j ++)
{
If (j = indexofshape)
{
// Geometroy. shapetype Conversion
Switch (pfeatureclassshapetype)
{
Case esrigeometrytype. esrigeometrypoint:
Fieldname = "point ";
Break;
Case esrigeometrytype. esrigeometrypolyline:
Fieldname = "polyline ";
Break;
Case esrigeometrytype. esrigeometrypolygon:
Fieldname = "polygon ";
Break;
Default:
Break;
}
// Fieldname = pfeatureclass. getfeature (I). get_value (j). tostring ();
// Datatable. Columns. Add (fieldname );
Datarow [J] = fieldname;
}
Else
{
// Add a non-shape field to the table
Fieldname = pfeatureclass. getfeature (I). get_value (j). tostring ();
// Datatable. Columns. Add (fieldname );
Datarow [J] = fieldname;
}
// Datatable [I] [J] = fieldname;
}
Datatable. Rows. Add (datarow );
}
}
Return datatable;
}
# Endregion
}
}
Attributes of arc engiene reading documents