CodePudding user response:
using System;
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
. Using ESRI ArcGIS. Carto;
. Using ESRI ArcGIS. Controls;
. Using ESRI ArcGIS. DataSourcesFile;
. Using ESRI ArcGIS. DataSourcesGDB;
. Using ESRI ArcGIS. Display;
. Using ESRI ArcGIS. EsriSystem;
. Using ESRI ArcGIS. Geodatabase;
. Using ESRI ArcGIS. Geometry;
. Using ESRI ArcGIS. Output;
. Using ESRI ArcGIS. SystemUI;
The namespace WindowsFormsApplication1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}
//sure
Private void button1_Click (object sender, EventArgs e)
{
//create some layer
IFeatureClass pPointFeatureClass=CreateShapefile (@ "E: \ Users \ DSF \ Desktop \ point SHP", esriGeometryType. EsriGeometryPoint);
//create map layer
IFeatureClass pPolylineFeatureClass=CreateShapefile (@ "E: \ Users \ DSF \ Desktop \ polyline SHP", esriGeometryType. EsriGeometryPolyline);
//create faceted layer
IFeatureClass pPolygonFeatureClass=CreateShapefile (@ "E: \ Users \ DSF \ Desktop \ polygon SHP", esriGeometryType. EsriGeometryPolygon);
}
//create the SHP file
Private IFeatureClass CreateShapefile (string filePath, esriGeometryType geometryType)
{
ISpatialReferenceFactory pSpatialReferenceFactory=new SpatialReferenceEnvironment ();
IGeographicCoordinateSystem pGeographicCoordinateSystem=pSpatialReferenceFactory. CreateGeographicCoordinateSystem ((int) esriSRGeoCSType. EsriSRGeoCS_WGS1984);
//geometry type
IGeometryDef pGeometryDef=new GeometryDef ();
IGeometryDefEdit pGeometryDefEdit=pGeometryDef as IGeometryDefEdit;
PGeometryDefEdit. GeometryType_2=geometryType;
PGeometryDefEdit. HasM_2=false;
PGeometryDefEdit. HasZ_2=false;
PGeometryDefEdit. SpatialReference_2=pGeographicCoordinateSystem;
//field collection
IFields pFields=new Fields ();
IFieldsEdit pFieldsEdit=pFields as IFieldsEdit;
//Shape field
IField pField=new Field ();
IFieldEdit pFieldEdit=pField as IFieldEdit;
PFieldEdit. Type_2=esriFieldType. EsriFieldTypeGeometry;
PFieldEdit. GeometryDef_2=pGeometryDef;
PFieldEdit. AliasName_2="Shape";
PFieldEdit. Name_2="Shape";
PFieldEdit. IsNullable_2=false;
PFieldEdit. Required_2=true;
PFieldsEdit. AddField (pField);
//A field
PField=new Field ();
PFieldEdit=pField as IFieldEdit;
PFieldEdit. Type_2=esriFieldType. EsriFieldTypeString;
PFieldEdit. AliasName_2="A";
PFieldEdit. Name_2="A";
PFieldEdit. Length_2=254;
PFieldsEdit. AddField (pField);
//create the SHP
IWorkspaceFactory pWorkspaceFactory=new ShapefileWorkspaceFactory ();
IWorkspace pWorkspace=pWorkspaceFactory. OpenFromFile (System. IO. Path. GetDirectoryName (filePath), 0).
IFeatureWorkspace pFeatureWorkspace=pWorkspace as IFeatureWorkspace;
Return pFeatureWorkspace. CreateFeatureClass (System. IO. Path. GetFileName (filePath), pFields, null, null, esriFeatureType. EsriFTSimple, "Shape", "");
}
}
}