Iworkspacefactory pworkspacefactory = new shapefileworkspacefactoryclass ();
Ifeatureworkspace pfws = pworkspacefactory. openfromfile (strfolder, 0) as ifeatureworkspace;
# Region field assembly
// Field set object Declaration
Ifields fields = new fieldsclass ();
Ifieldsedit fieldsedit = (ifieldsedit) fields;
Fieldsedit. fieldcount_2 = 7;
// Geometric object Declaration
Igeometrydef geodef = new geometrydefclass ();
Igeometrydefedit geometrydefedit = (igeometrydefedit) geodef;
Geometrydefedit. avgnumpoints_2 = 1;
Geometrydefedit. gridcount_2 = 0;
Geometrydefedit. geometrytype_2 = esrigeometrytype. esrigeometrypoint;
// Field point, line, and surface object Declaration
Ifield shapefield = new fieldclass ();
Ifieldedit shapefieldedit = (ifieldedit) shapefield;
Shapefieldedit. name_2 = strshapefieldname;
Shapefieldedit. isnullable_2 = true;
Shapefieldedit. type_2 = esrifieldtype. esrifieldtypegeometry;
Shapefieldedit. geometrydef_2 = geodef;
Shapefieldedit. required_2 = true;
// Environment object declaration is used to set the Coordinate System
Spatialreferenceenvironment = new spatialreferenceenvironment ();
Igeographiccoordinatesystem geographiccoordinatesystem = spatialreferenceenvironment. creategeographiccoordinatesystem (INT) esrisrgeocstype. esrisrgeocs_wgs1984 );
Geometrydefedit. spatialreference_2 = geographiccoordinatesystem;
// Field object Declaration
Ifield idfield = new fieldclass ();
Ifieldedit idfieldedit = (ifieldedit) idfield;
Idfieldedit. name_2 = "ID ";
Idfieldedit. aliasname_2 = "ID ";
Idfieldedit. type_2 = esrifieldtype. esrifieldtypeinteger;
// Field object Declaration
Ifield oidfield = new fieldclass ();
Ifieldedit oidfieldedit = (ifieldedit) oidfield;
Oidfieldedit. name_2 = "objectid ";
Oidfieldedit. aliasname_2 = "FID ";
Oidfieldedit. type_2 = esrifieldtype. esrifieldtypeoid;
Fieldsedit. set_field (0, oidfield );
Fieldsedit. set_field (1, shapefield );
Fieldsedit. set_field (2, idfield );
String [] staname = new string [] {"staname", "statype", "stactype", "stayear "};
// Configure the SHP field cyclically
For (INT I = 0; I <staname. length; I ++)
{
Ifield tempfield = new fieldclass ();
Ifieldedit tempfieldedit = (ifieldedit) tempfield;
Tempfieldedit. name_2 = staname [I];
Tempfieldedit. aliasname_2 = staname [I];
Tempfieldedit. type_2 = esrifieldtype. esrifieldtypestring;
Fieldsedit. set_field (3 + I, tempfield );
}
# Endregion
Ifeatureclass featureclass = pfws. createfeatureclass (strname, fields, null, null, esrifeaturetype. esriftsimple, strshapefieldname, null); // This error is reported because the strname contains the '_' symbol in the SHP file name.
# Region assignment
Ifeaturecursor fcsornew = featureclass. insert (true );
Ifeaturebuffer fbuf = featureclass. createfeaturebuffer ();
Foreach (hb_stateentity HS in alst)
{
Ipoint Pt = new pointclass ();
Igeometry shape = pt;
PT. x = HS. sta_long.pdf;
PT. Y = HS. sta_latitude;
Fbuf. Shape = shape;
Fbuf. set_value (3, HS. sta_name );
Fbuf. set_value (4, HS. sta_type );
Fbuf. set_value (5, HS. sta_description );
Fbuf. set_value (6, dyear );
Fcsornew. insertfeature (fbuf );
}
Fcsornew. Flush ();
System. runtime. interopservices. Marshal. releasecomobject (fcsornew );
# Endregion
If (pfws! = NULL) system. runtime. interopservices. Marshal. releasecomobject (pfws );
If (pworkspacefactory! = NULL) system. runtime. interopservices. Marshal. releasecomobject (pworkspacefactory );
GC. Collect ();