用ae创建点图层

 public void CreateShapefiles()
        {
            //指定路径
            string strShapeFolder = AppDomain.CurrentDomain.BaseDirectory;
            //文件名
            string strShapeName = "DisasterShow";

            string path = strShapeFolder + strShapeName + ".shp";
            if (File.Exists(path))
            {
                string strFilePath = System.IO.Path.GetDirectoryName(path);
                string strFileName = System.IO.Path.GetFileNameWithoutExtension(path);
                _application.MapControl2D.AddShapeFile(strFilePath, strFileName);
                _application.MapControl2D.Refresh();
                return;
            }

            //打开工作空间 
            const string strShapeFieldName = "shape";
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
           
            IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(strShapeFolder, 0);

            //设置字段集 
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            //设置字段 
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            //创建类型为几何类型的字段 
            pFieldEdit.Name_2 = strShapeFieldName;
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            //为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照  
            IGeometryDef pGeoDef = new GeometryDefClass();     //The geometry definition for the field if IsGeometry is TRUE. 
            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            pGeoDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();

            pFieldEdit.GeometryDef_2 = pGeoDef;
            pFieldsEdit.AddField(pField);

            //添加其他的字段 
            pField = new FieldClass();
            pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "WaterLevel";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldEdit.Precision_2 = 7;//数值精度 
            pFieldEdit.Scale_2 = 3;//小数点位数 
            pFieldsEdit.AddField(pField);

            //创建shapefile 
            pWS.CreateFeatureClass(strShapeName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");

            string strFilePaths = System.IO.Path.GetDirectoryName(path);
            string strFileNames = System.IO.Path.GetFileNameWithoutExtension(path);
            _application.MapControl2D.AddShapeFile(strFilePaths, strFileNames);
            _application.MapControl2D.Refresh();
        }

posted @ 2013-07-30 17:41  ◆紅袖  阅读(477)  评论(0)    收藏  举报