Error in creating SHP (error from hresult: 0 × 80010105 (rpc_e_serverfault ))

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.