Create a shp file and add the feature to the shp file.

Source: Internet
Author: User

IFeatureCursor cursor;
IFeatureBuffer featureBuffer;
IFeatureClass featureClass;
FeatureClass = operateShp. CreateShapefile (path, name, polygon. GeometryType );
Cursor = featureClass. Insert (true );
FeatureBuffer = featureClass. CreateFeatureBuffer ();
FeatureBuffer. Shape = polygon;
Cursor. InsertFeature (featureBuffer );

/// <Summary>
/// Create a Shapefile and return the IFeatureClass of the file
/// </Summary>
/// <Param name = "path"> </param>
/// <Param name = "fileName"> </param>
/// <Returns> </returns>
Public IFeatureClass CreateShapefile (string path, string fileName, esriGeometryType featureType)
{
String filePathName = path + fileName;
If (File. Exists (filePathName ))
{
MessageBox. Show ("the file already exists! ");
Return null;
}
IFeatureWorkspace featureWorkspace;
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass ();
IField field = new FieldClass ();
IFieldEdit fieldEdit;
IFields fields = new FieldsClass ();
IFieldsEdit fieldsEdit = (IFieldsEdit) fields;
IGeometryDef geometryDef = new GeometryDefClass ();
IGeometryDefEdit geometryDefEdit;

FeatureWorkspace = (IFeatureWorkspace) workspaceFactory. OpenFromFile (path, 0 );
FieldEdit = (IFieldEdit) field;
FieldEdit. Name_2 = "shape ";
FieldEdit. Type_2 = esriFieldType. esriFieldTypeGeometry;
GeometryDefEdit = (IGeometryDefEdit) geometryDef;
// Switch (featureType)
//{
// Case esriGeometryType. esriGeometryMultipoint:
// GeometryDefEdit. GeometryType_2 = esriGeometryType. esriGeometryPolyline;
// Break;
// Case esriGeometryType. esriGeometryPolyline:
// GeometryDefEdit. GeometryType_2 = esriGeometryType. esriGeometryPolyline;
// Break;
// Case esriGeometryType. esriGeometryPolyline:
// GeometryDefEdit. GeometryType_2 = esriGeometryType. esriGeometryPolyline;
// Break;
//}
GeometryDefEdit. GeometryType_2 = featureType;
GeometryDefEdit. SpatialReference_2 = new UnknownCoordinateSystemClass ();
FieldEdit. GeometryDef_2 = geometryDef;
FieldsEdit. AddField (field );

Return featureWorkspace. CreateFeatureClass (fileName, fields, null, null, esriFeatureType. esriFTSimple, "shape ","");
}

 

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.