예제 #1
1
        private void 添加点型图层ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //创建要素类
            #region 创建新的内存工作空间
            IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0);

            IName pName = (IName)pWSName;
            IWorkspace pMemoryWS = (IWorkspace)pName.Open();
            #endregion

            IField oField = new FieldClass();
            IFields oFields = new FieldsClass();
            IFieldsEdit oFieldsEdit = null;
            IFieldEdit oFieldEdit = null;
            IFeatureClass oFeatureClass = null;
            IFeatureLayer oFeatureLayer = null;

            oFieldsEdit = oFields as IFieldsEdit;
            oFieldEdit = oField as IFieldEdit;
            oFieldEdit.Name_2 = "OBJECTID";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            oFieldEdit.IsNullable_2 = false;
            oFieldEdit.Required_2 = false;
            oFieldsEdit.AddField(oField);

            oField = new FieldClass();
            oFieldEdit = oField as IFieldEdit;
            IGeometryDef pGeoDef = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
            pGeoDefEdit.AvgNumPoints_2 = 5;
            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            pGeoDefEdit.GridCount_2 = 1;
            pGeoDefEdit.HasM_2 = false;
            pGeoDefEdit.HasZ_2 = false;
            pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;
            oFieldEdit.Name_2 = "SHAPE";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            oFieldEdit.GeometryDef_2 = pGeoDef;
            oFieldEdit.IsNullable_2 = true;
            oFieldEdit.Required_2 = true;
            oFieldsEdit.AddField(oField);

            oField = new FieldClass();
            oFieldEdit = oField as IFieldEdit;
            oFieldEdit.Name_2 = "Code";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            //oFieldEdit.Length = 10;
            oFieldEdit.IsNullable_2 = true;
            oFieldsEdit.AddField(oField);
            //创建要素类
            oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            oFeatureLayer = new FeatureLayerClass();
            oFeatureLayer.Name = "PointLayer";
            oFeatureLayer.FeatureClass = oFeatureClass;
            //创建唯一值符号化对象


            IUniqueValueRenderer pURender = new UniqueValueRendererClass();
            pURender.FieldCount = 1;
            pURender.set_Field(0, "Code");
            pURender.UseDefaultSymbol = false;
            //创建SimpleMarkerSymbolClass对象
            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
            //创建RgbColorClass对象为pSimpleMarkerSymbol设置颜色
            IRgbColor pRgbColor = new RgbColorClass();
            pRgbColor.Red = 255;
            pSimpleMarkerSymbol.Color = pRgbColor as IColor;
            //设置pSimpleMarkerSymbol对象的符号类型,选择钻石
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
            //设置pSimpleMarkerSymbol对象大小,设置为5
            pSimpleMarkerSymbol.Size = 5;
            //显示外框线
            pSimpleMarkerSymbol.Outline = true;
            //为外框线设置颜色
            IRgbColor pLineRgbColor = new RgbColorClass();
            pLineRgbColor.Green = 255;
            pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor;
            //设置外框线的宽度
            pSimpleMarkerSymbol.OutlineSize = 1; 

            //半透明颜色

 


            pURender.AddValue("1", "", pSimpleMarkerSymbol as ISymbol);

            //唯一值符号化内存图层
            (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer;
            ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects;
            //透明度
            pLyrEffect.Transparency = 0;


            oFeatureLayer.Visible = true;

            this.axMapControl1.AddLayer(oFeatureLayer,axMapControl1.LayerCount);
            insertpoint = true;
        }
        /// <summary> 
        /// Create the polyline feature class 
        /// </summary> 
        /// <param name="featWorkspace">IFeatureWorkspace</param> 
        /// <param name="name">Name of the featureclass</param> 
        /// <returns>IFeatureClass</returns> 
        private IFeatureClass CreatePolylineFeatureClass(IFeatureWorkspace featWorkspace, string name)
        {
            IFieldsEdit pFldsEdt = new FieldsClass();
            IFieldEdit pFldEdt = new FieldClass();

            pFldEdt = new FieldClass();
            pFldEdt.Type_2 = esriFieldType.esriFieldTypeOID;
            pFldEdt.Name_2 = "OBJECTID";
            pFldEdt.AliasName_2 = "OBJECTID";
            pFldsEdt.AddField(pFldEdt);

            IGeometryDefEdit pGeoDef;
            pGeoDef = new GeometryDefClass();
            pGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            pGeoDef.SpatialReference_2 = ArcMap.Document.FocusMap.SpatialReference;

            pFldEdt = new FieldClass();
            pFldEdt.Name_2 = "SHAPE";
            pFldEdt.AliasName_2 = "SHAPE";
            pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
            pFldEdt.GeometryDef_2 = pGeoDef;
            pFldsEdt.AddField(pFldEdt);

            IFeatureClass pFClass = featWorkspace.CreateFeatureClass(name, pFldsEdt, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

            return pFClass;
        }
 /// <summary>
 /// 在内存中创建要素类
 /// </summary>
 /// <returns></returns>
 public IFeatureClass MemoryFeatureClass()
 {
     AccessGeoData accData = new AccessGeoData();
     IFeatureWorkspace pFeaWorkspace = accData.FeatureWorkspace();
     IFields fields = new FieldsClass();
     IFieldsEdit fedits = (IFieldsEdit)fields;
     IField objfield = new FieldClass();
     IFieldEdit objEdit = (IFieldEdit)objfield;
     objEdit.Name_2 = "OBJECTID";
     objEdit.Type_2 = esriFieldType.esriFieldTypeOID;
     fedits.AddField(objEdit);
     IField Spfield = new FieldClass();
     IFieldEdit fEdit = (IFieldEdit)Spfield;
     IGeometryDef pGeoDef = new GeometryDefClass();
     IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
     pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
     pGeoDefEdit.SpatialReference_2 = spatialRef;
     fEdit.Name_2 = "Shape";
     fEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
     fEdit.GeometryDef_2 = pGeoDef;
     fedits.AddField(Spfield);
     IField fieldZ = new FieldClass();
     IFieldEdit EditZ = (IFieldEdit)fieldZ;
     EditZ.Name_2 = "Z";
     EditZ.Type_2 = esriFieldType.esriFieldTypeDouble;
     fedits.AddField(EditZ);
     IFeatureClass pFeaClass = pFeaWorkspace.CreateFeatureClass("FeaturePoints", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
     return pFeaClass;
 }
예제 #4
0
        public static IFeatureClass CreateFeatureClass(IWorkspace workspace, string featureClassName, esriGeometryType type, ISpatialReference spatialReference)
        {
            IFeatureWorkspace        pFeatureWorkspace        = workspace as IFeatureWorkspace;
            IFeatureClassDescription pFeatureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  pObjectClassDescription  = pFeatureClassDescription as IObjectClassDescription;
            IFields     pFields     = pObjectClassDescription.RequiredFields;
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            for (int i = 0; i < pFields.FieldCount; i++)
            {
                if (pFieldsEdit.Field[i].Type == esriFieldType.esriFieldTypeGeometry)
                {
                    IFieldEdit       pFieldEdit       = pFieldsEdit.Field[i] as IFieldEdit;
                    IGeometryDef     pGeometryDef     = new GeometryDefClass();
                    IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                    pGeometryDefEdit.GeometryType_2     = type;
                    pGeometryDefEdit.SpatialReference_2 = spatialReference;
                    pFieldEdit.GeometryDef_2            = pGeometryDef;
                }
            }

            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            pFieldChecker.ValidateWorkspace = workspace;
            pFieldChecker.Validate(pFields, out enumFieldError, out validatedFields);

            return(pFeatureWorkspace.CreateFeatureClass(featureClassName, validatedFields,
                                                        pObjectClassDescription.InstanceCLSID, pObjectClassDescription.ClassExtensionCLSID,
                                                        esriFeatureType.esriFTSimple, "SHAPE", ""));
        }
예제 #5
0
        public bool CreateRaster(IRasterDataset pRDs, IRasterWorkspaceEx pWorkSpace)
        {
            IRasterProps      pRasterProps      = (IRasterProps)pRDs.CreateDefaultRaster();
            IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

            pRasterStorageDef.CompressionType     = esriRasterCompressionType.esriRasterCompressionJPEG2000;
            pRasterStorageDef.CompressionQuality  = 50;
            pRasterStorageDef.PyramidLevel        = 2;
            pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
            pRasterStorageDef.TileHeight          = 128;
            pRasterStorageDef.TileWidth           = 128;
            IRasterDef pRasterDef = new RasterDefClass();

            pRasterDef.Description      = "RasterDataset";
            pRasterDef.SpatialReference = pRasterProps.SpatialReference;
            IGeometryDef     pGeoDef     = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;

            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            pGeoDefEdit.AvgNumPoints_2 = 4;
            pGeoDefEdit.GridCount_2    = 1;
            pGeoDefEdit.set_GridSize(0, 1000);
            pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
            IRasterDataset pRasterDataset = pWorkSpace.CreateRasterDataset("zzy", 3, rstPixelType.PT_UCHAR, pRasterStorageDef, "", pRasterDef, pGeoDef);

            pRasterDataset = pRDs;
            return(true);
        }
예제 #6
0
        public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName)
        {
            try
            {
                IRasterDataset pRds = pRW.OpenRasterDataset(pFileName);


                IRasterProps      pRasterProps      = (IRasterProps)pRds.CreateDefaultRaster();
                IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

                IRasterDef pRasterDef = new RasterDefClass();
                pRasterDef.SpatialReference = pRasterProps.SpatialReference;
                IGeometryDef     pGeoDef     = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeoDefEdit.AvgNumPoints_2 = 4;
                pGeoDefEdit.GridCount_2    = 1;
                pGeoDefEdit.set_GridSize(0, 1000);
                pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
                IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef);

                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
 /// <summary>
 /// 在地理数据库中创建要素类
 /// </summary>
 /// <param name="workspacePath">工作空间路径</param>
 /// <param name="feaclassName">所创建要素类名称</param>
 /// <param name="GeometeyType">枚举要素类类型: esriGeimetryType(</param>
 /// <param name="gcsType">地理空间坐标系类型,格式如: (int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980</param>
 /// <returns></returns>
 public IFeatureClass CreateFeatureClass(string workspacePath, string feaclassName, esriGeometryType GeometeyType, int gcsType)
 {
     AccessGeoData accData = new AccessGeoData();
     IFeatureWorkspace pFeaWorkspace = accData.OpenFeatureWorkspace(workspacePath);
     spatialRef = spatialRefFactory.CreateGeographicCoordinateSystem(gcsType);
     //字段编辑:包括ObjectID 与 Shape
     IFields fields = new FieldsClass();
     IFieldsEdit fedits = (IFieldsEdit)fields;
     //构建唯一标识符字段
     IField objfield = new FieldClass();
     IFieldEdit objEdit = (IFieldEdit)objfield;
     objEdit.Name_2 = "OBJECTID";
     objEdit.Type_2 = esriFieldType.esriFieldTypeOID;
     fedits.AddField(objEdit);
     //构建shape
     IField Spfield = new FieldClass();
     IFieldEdit fEdit = (IFieldEdit)Spfield;
     IGeometryDef pGeoDef = new GeometryDefClass();
     IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
     pGeoDefEdit.GeometryType_2 = GeometeyType;
     pGeoDefEdit.SpatialReference_2 = spatialRef;
     fEdit.Name_2 = "Shape";
     fEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
     fEdit.GeometryDef_2 = pGeoDef;
     fedits.AddField(Spfield);
     //附加一个可编辑字段,存放属性值
     IField fieldZ = new FieldClass();
     IFieldEdit EditZ = (IFieldEdit)fieldZ;
     EditZ.Name_2 = "Value";
     EditZ.Type_2 = esriFieldType.esriFieldTypeDouble;
     fedits.AddField(EditZ);
     //若有其他需求,在此处添加字段,参加Value字段添加方式
     IFeatureClass pFeaClass = pFeaWorkspace.CreateFeatureClass(feaclassName, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
     return pFeaClass;
 }
예제 #8
0
        /// <summary>
        /// 创建内存IFeatureLayer,该方法为创建内存临时图层的便捷方法,创建的图层带有id,和name两个属性字段。
        /// </summary>
        /// <param name="myAxMapControl">AxMapControl扩展对象</param>
        /// <param name="strIFeatureClassName">IFeatureClass名称</param>
        /// <param name="myEsriGeometryType">数据类型</param>
        /// <returns>IFeatureLayer对象</returns>
        public static IFeatureLayer CreateMemoryFeatureLayer(this AxMapControl myAxMapControl, String strIFeatureClassName, esriGeometryType myEsriGeometryType)
        {
            IWorkspaceFactory myIWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName    myIWorkspaceName    = myIWorkspaceFactory.Create("", strIFeatureClassName, null, 0);
            IName             myIName             = (IName)myIWorkspaceName;
            IWorkspace        myIWorkspace        = (IWorkspace)myIName.Open();
            IField            myIField            = null;
            IFields           myIFields           = new FieldsClass();
            IFieldsEdit       myIFieldsEdit       = myIFields as IFieldsEdit;
            IFieldEdit        myIFieldEdit        = null;
            IFeatureClass     myIFeatureClass     = null;
            IFeatureLayer     myIFeatureLayer     = null;

            try
            {
                //主键id
                myIField                  = new FieldClass();
                myIFieldEdit              = myIField as IFieldEdit;
                myIFieldEdit.Name_2       = "id";
                myIFieldEdit.IsNullable_2 = true;
                myIFieldEdit.Length_2     = 50;
                myIFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                myIFieldsEdit.AddField(myIField);
                //名称name
                myIField                  = new FieldClass();
                myIFieldEdit              = myIField as IFieldEdit;
                myIFieldEdit.Name_2       = "name";
                myIFieldEdit.IsNullable_2 = true;
                myIFieldEdit.Length_2     = 50;
                myIFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                myIFieldsEdit.AddField(myIField);
                //IGeometryI字段
                IGeometryDef     myIGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit myIGeometryDefEdit = (IGeometryDefEdit)myIGeometryDef;
                myIGeometryDefEdit.AvgNumPoints_2     = 5;
                myIGeometryDefEdit.GeometryType_2     = myEsriGeometryType;
                myIGeometryDefEdit.GridCount_2        = 1;
                myIGeometryDefEdit.HasM_2             = false;
                myIGeometryDefEdit.HasZ_2             = false;
                myIGeometryDefEdit.SpatialReference_2 = myAxMapControl.SpatialReference;
                myIField                   = new FieldClass();
                myIFieldEdit               = myIField as IFieldEdit;
                myIFieldEdit.Name_2        = "SHAPE";
                myIFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                myIFieldEdit.GeometryDef_2 = myIGeometryDef;
                myIFieldEdit.IsNullable_2  = true;
                myIFieldEdit.Required_2    = true;
                myIFieldsEdit.AddField(myIField);
                //
                myIFeatureClass = (myIWorkspace as IFeatureWorkspace).CreateFeatureClass(strIFeatureClassName, myIFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                (myIFeatureClass as IDataset).BrowseName = strIFeatureClassName;
                myIFeatureLayer              = new FeatureLayerClass();
                myIFeatureLayer.Name         = strIFeatureClassName;
                myIFeatureLayer.FeatureClass = myIFeatureClass;
            }
            catch
            {
            }
            return(myIFeatureLayer);
        }
예제 #9
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace FeatureWorkspace, string LayerName, esriFeatureType featureType, esriGeometryType GeometryType)
        {
            IFields     fields = new FieldsClass();
            IFieldsEdit edit   = fields as IFieldsEdit;

            //创建OBJECTID字段
            IField     field3 = new FieldClass();
            IFieldEdit edit2  = field3 as IFieldEdit;

            edit2.Name_2      = "OBJECTID";
            edit2.AliasName_2 = "OBJECTID";
            edit2.Type_2      = esriFieldType.esriFieldTypeOID;
            edit.AddField(field3);

            //创建Shape字段
            IGeometryDef     def   = new GeometryDefClass();
            IGeometryDefEdit edit4 = def as IGeometryDefEdit;

            edit4.GeometryType_2 = GeometryType;
            edit4.GridCount_2    = 1;
            edit4.set_GridSize(0, 1000);
            edit4.AvgNumPoints_2     = 2;
            edit4.HasM_2             = false;
            edit4.HasZ_2             = false;
            edit4.SpatialReference_2 = this.ExportSpatialReference;

            IField     field4 = new FieldClass();
            IFieldEdit edit3  = field4 as IFieldEdit;

            edit3.Name_2        = "SHAPE";
            edit3.AliasName_2   = "SHAPE";
            edit3.Type_2        = esriFieldType.esriFieldTypeGeometry;
            edit3.GeometryDef_2 = def;
            edit.AddField(field4);

            string ShapeFiledName = field4.Name;

            UID uid  = null;
            UID uid2 = null;

            switch (featureType)
            {
            case esriFeatureType.esriFTSimple:       //FeatureClass
                IObjectClassDescription description4 = new FeatureClassDescriptionClass();
                uid  = description4.InstanceCLSID;
                uid2 = description4.ClassExtensionCLSID;
                break;

            case esriFeatureType.esriFTAnnotation:     //AnnotationFeatureClass
                IObjectClassDescription description = new AnnotationFeatureClassDescriptionClass();
                uid          = description.InstanceCLSID;
                uid2         = description.ClassExtensionCLSID;
                GeometryType = esriGeometryType.esriGeometryPolygon;
                break;
            }
            //创建要素对象
            IFeatureClass fc = FeatureWorkspace.CreateFeatureClass(LayerName, fields, uid, uid2, featureType, ShapeFiledName, null);

            return(fc);
        }
예제 #10
0
 static IGeometryDefEdit CreateGeometryDef(esriGeometryType type, int epsg)
 {
     IGeometryDefEdit geomDef = new GeometryDefClass();
     geomDef.GeometryType_2 = type;
     geomDef.SpatialReference_2 = CreateSpatialRef(epsg);
     return geomDef;
 }
예제 #11
0
        /// <summary>
        /// 新建线图层
        /// </summary>
        public void CreatePolylineLayer()
        {
            SaveFileDialog sfdPoint = new SaveFileDialog();

            sfdPoint.Title            = "请选择线图层的存储位置";
            sfdPoint.Filter           = "Shapefile(*.shp)|*.shp|All files(*.*)|*.*";
            sfdPoint.RestoreDirectory = true;
            if (sfdPoint.ShowDialog() == DialogResult.OK)
            {
                LocalFilePath = sfdPoint.FileName;
                FilePath      = System.IO.Path.GetDirectoryName(LocalFilePath);
                FileName      = System.IO.Path.GetFileName(LocalFilePath);

                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                pFieldEdit.GeometryDef_2        = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(FilePath, 0) as IFeatureWorkspace;
                pFeatureWorkspace.CreateFeatureClass(FileName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                m_mapControl.AddShapeFile(FilePath, FileName);
                m_mapControl.ActiveView.Refresh();
            }
        }
예제 #12
0
        public static IFeatureClass CreateFClassInPDB(IWorkspace accessworkspace, string feaDSname, string FCname, esriGeometryType esriGeometryType, ISpatialReference sprf)
        {
            try
            {
                IFeatureDataset featureDataset = ((IFeatureWorkspace)accessworkspace).OpenFeatureDataset(feaDSname);
                //IGeoDataset geoDataset = featureDataset as IGeoDataset;

                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pFieldEdit.GeometryDef_2        = pGeometryDef;
                pFieldsEdit.AddField(pField);


                IFeatureClass fc = featureDataset.CreateFeatureClass(FCname, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                return(fc);
            }

            catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString());
                return(null);
            }
        }
예제 #13
0
        static IFeatureClass CreateFeatureClass(IFeatureWorkspace workspace, string name, ISpatialReference outSR)
        {
            IFieldsEdit fields = new FieldsClass();

            IFieldEdit field = new FieldClass();
            field.Type_2 = esriFieldType.esriFieldTypeOID;
            field.Name_2 = "OBJECTID";
            field.AliasName_2 = "OBJECTID";
            fields.AddField(field);

            IGeometryDefEdit geom = new GeometryDefClass();
            geom.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geom.SpatialReference_2 = outSR;
            geom.HasM_2 = true;
            geom.HasZ_2 = false;

            field = new FieldClass();
            field.Name_2 = "SHAPE";
            field.AliasName_2 = "SHAPE";
            field.Type_2 = esriFieldType.esriFieldTypeGeometry;
            field.GeometryDef_2 = geom;
            fields.AddField(field);

            return workspace.CreateFeatureClass(name, fields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
        }
예제 #14
0
        private IFeatureClass CreateShapeFile(string shapeFullname, string proj)
        {
            FileInfo finfo     = new FileInfo(shapeFullname);
            string   parFolder = System.IO.Path.GetDirectoryName(shapeFullname);

            if (!Directory.Exists(parFolder))
            {
                Directory.CreateDirectory(parFolder);
            }
            IWorkspaceFactory shpwf       = new ShapefileWorkspaceFactory();
            IFeatureWorkspace featureWs   = shpwf.OpenFromFile(parFolder, 0) as IFeatureWorkspace;
            IFields           pFields     = new FieldsClass();
            IFieldsEdit       pFieldsEdit = pFields as IFieldsEdit;

            //添加几何字段
            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef     pGeomDef     = new GeometryDefClass();
            IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;

            pGeomDefEdit.GeometryType_2     = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint; //几何类型
            pGeomDefEdit.HasZ_2             = true;                                                    //是否有Z值
            pGeomDefEdit.SpatialReference_2 = CreateSpatialReference(proj);                            //设置空间参考
            pFieldEdit.GeometryDef_2        = pGeomDef;
            pFieldsEdit.AddField(pField);
            return(featureWs.CreateFeatureClass(finfo.Name, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", null));
        }
        /// <summary>
        /// Create a polygon feature class used to store buffer geometries for observer points
        /// </summary>
        /// <param name="featWorkspace">IFeatureWorkspace</param>
        /// <param name="spatialRef">ISpatialReference of selected surface</param>
        /// <param name="name">Name of the feature class</param>
        /// <returns>IFeatureClass</returns>
        private static IFeatureClass CreateMaskFeatureClass(IFeatureWorkspace featWorkspace, ISpatialReference spatialRef, string name)
        {
            IFieldsEdit pFldsEdt = new FieldsClass();
            IFieldEdit  pFldEdt  = new FieldClass();

            pFldEdt             = new FieldClass();
            pFldEdt.Type_2      = esriFieldType.esriFieldTypeOID;
            pFldEdt.Name_2      = "OBJECTID";
            pFldEdt.AliasName_2 = "OBJECTID";
            pFldsEdt.AddField(pFldEdt);

            IGeometryDefEdit pGeoDef;

            pGeoDef = new GeometryDefClass();
            pGeoDef.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            pGeoDef.SpatialReference_2 = spatialRef;

            pFldEdt               = new FieldClass();
            pFldEdt.Name_2        = "SHAPE";
            pFldEdt.AliasName_2   = "SHAPE";
            pFldEdt.Type_2        = esriFieldType.esriFieldTypeGeometry;
            pFldEdt.GeometryDef_2 = pGeoDef;
            pFldsEdt.AddField(pFldEdt);

            IFeatureClass pFClass = featWorkspace.CreateFeatureClass(name, pFldsEdt, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

            return(pFClass);
        }
예제 #16
0
        public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName)
        {
            try
            {

                IRasterDataset pRds = pRW.OpenRasterDataset(pFileName);

                IRasterProps pRasterProps = (IRasterProps)pRds.CreateDefaultRaster();
                IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

                IRasterDef pRasterDef = new RasterDefClass();
                pRasterDef.SpatialReference = pRasterProps.SpatialReference;
                IGeometryDef pGeoDef = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeoDefEdit.AvgNumPoints_2 = 4;
                pGeoDefEdit.GridCount_2 = 1;
                pGeoDefEdit.set_GridSize(0, 1000);
                pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
                IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef);

                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
예제 #17
0
        public IFeatureClass CreateShapeFile(DataSet ds, string strOutShpName, ISpatialReference pSRF)
        {
            try
            {
                DirectoryInfo    di         = new DirectoryInfo(strOutShpName);
                string           filefolder = di.Parent.FullName;
                ClsGDBDataCommon cdc        = new ClsGDBDataCommon();
                //cdc.OpenFromShapefile(filefolder);
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

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

                //创建类型为几何类型的字段
                IGeometryDef     pGeoDef     = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

                pGeoDefEdit.HasM_2             = false;
                pGeoDefEdit.HasZ_2             = false;
                pGeoDefEdit.SpatialReference_2 = pSRF;

                pFieldEdit.Name_2        = "SHAPE";
                pFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                pFieldEdit.GeometryDef_2 = pGeoDef;
                //pFieldEdit.IsNullable_2 = true;
                //pFieldEdit.Required_2 = true;
                pFieldsEdit.AddField(pField);

                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = ds.Tables[0].Columns[i].ColumnName;
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);
                }

                ClsGDBDataCommon comm     = new ClsGDBDataCommon();
                IWorkspace       inmemWor = comm.OpenFromShapefile(filefolder);
                // ifeatureworkspacee
                IFeatureWorkspace pFeatureWorkspace = inmemWor as IFeatureWorkspace;
                IFeatureClass     pFeatureClass     = pFeatureWorkspace.CreateFeatureClass(di.Name, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

                return(pFeatureClass);
                //IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                //pFeatureLayer.FeatureClass = pFeatureClass;
                //pFeatureLayer.Name = System.IO.Path.GetFileNameWithoutExtension(di.Name);
                //m_mapControl.AddLayer(pFeatureLayer as ILayer, 0);
                //m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            catch (SystemException ee)
            {
                MessageBox.Show(ee.Message);
                return(null);
            }
        }
예제 #18
0
        /// <summary>
        /// �½���ͼ��
        /// </summary>
        public void CreatePointLayer()
        {
            SaveFileDialog sfdPoint = new SaveFileDialog();
            sfdPoint.Title = "��ѡ���ͼ��Ĵ洢λ��";
            sfdPoint.Filter = "Shapefile(*.shp)|*.shp|All files(*.*)|*.*";
            sfdPoint.RestoreDirectory = true;
            if (sfdPoint.ShowDialog() == DialogResult.OK)
            {
                LocalFilePath = sfdPoint.FileName;
                FilePath = System.IO.Path.GetDirectoryName(LocalFilePath);
                FileName = System.IO.Path.GetFileName(LocalFilePath);

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef pGeometryDef = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(FilePath, 0) as IFeatureWorkspace;
                pFeatureWorkspace.CreateFeatureClass(FileName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                m_mapControl.AddShapeFile(FilePath, FileName);
                m_mapControl.ActiveView.Refresh();
            }
        }
예제 #19
0
        public IFields CreateShapeFields(esriGeometryType p_esriGeotype)
        {
            //创建字段编辑所需要的接口
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
            //创建基本必要的属性字段



            IField     pFld     = new FieldClass();
            IFieldEdit pFldEdit = pFld as IFieldEdit;

            pFldEdit.Name_2       = "shape";
            pFldEdit.IsNullable_2 = false;
            pFldEdit.Type_2       = esriFieldType.esriFieldTypeGeometry;

            //增加特定的属性字段
            pFieldsEdit.AddField(pFld);
            IGeometryDef     pGeoDef     = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;

            pGeoDefEdit.GeometryType_2     = p_esriGeotype;
            pGeoDefEdit.SpatialReference_2 = (ISpatialReference) new UnknownCoordinateSystem();
            pFldEdit.GeometryDef_2         = pGeoDef;
            return(pFieldsEdit as IFields);
        }
예제 #20
0
        private void method_1(int int_0, IFieldsEdit ifieldsEdit_1)
        {
            IFieldEdit field = new FieldClass();

            field.Name_2       = "OBJECTID";
            field.AliasName_2  = "OBJECTID";
            field.IsNullable_2 = false;
            field.Type_2       = esriFieldType.esriFieldTypeOID;
            ifieldsEdit_1.AddField(field);
            if (int_0 == 1)
            {
                field              = new FieldClass();
                field.Name_2       = "SHAPE";
                field.AliasName_2  = "SHAPE";
                field.IsNullable_2 = true;
                field.Type_2       = esriFieldType.esriFieldTypeGeometry;
                IGeometryDefEdit edit2 = new GeometryDefClass();
                edit2.SpatialReference_2 = new UnknownCoordinateSystemClass();
                edit2.GridCount_2        = 1;
                edit2.set_GridSize(0, 1000.0);
                edit2.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                edit2.HasZ_2         = false;
                edit2.HasM_2         = false;
                field.GeometryDef_2  = edit2;
                ifieldsEdit_1.AddField(field);
            }
        }
예제 #21
0
        private static IGeometryDef CreateGeometryDef(
            esriGeometryType geometryType,
            [NotNull] ISpatialReference spatialReference,
            double gridSize1,
            double gridSize2,
            double gridSize3,
            bool hasZ,
            bool hasM)
        {
            IGeometryDefEdit result = new GeometryDefClass();

            ISpatialReference highPrecisionSpatialReference;

            SpatialReferenceUtils.EnsureHighPrecision(spatialReference,
                                                      out highPrecisionSpatialReference);

            result.GeometryType_2     = geometryType;
            result.HasZ_2             = hasZ;
            result.HasM_2             = hasM;
            result.SpatialReference_2 = highPrecisionSpatialReference;

            ConfigureSpatialIndexGrid(result, gridSize1, gridSize2, gridSize3);

            return(result);
        }
예제 #22
0
        private void method_1(int int_0, IFieldsEdit ifieldsEdit_2)
        {
            IFieldEdit field = new FieldClass();

            field.Name_2       = "OBJECTID";
            field.AliasName_2  = "OBJECTID";
            field.IsNullable_2 = false;
            field.Type_2       = esriFieldType.esriFieldTypeOID;
            ifieldsEdit_2.AddField(field);
            if (int_0 == 1)
            {
                field              = new FieldClass();
                field.Name_2       = "SHAPE";
                field.AliasName_2  = "SHAPE";
                field.IsNullable_2 = true;
                field.Type_2       = esriFieldType.esriFieldTypeGeometry;
                IGeometryDefEdit edit2 = new GeometryDefClass();
                edit2.SpatialReference_2 =
                    SpatialReferenctOperator.ConstructCoordinateSystem(this.iworkspace_0 as IGeodatabaseRelease);
                edit2.GridCount_2 = 1;
                edit2.set_GridSize(0, 1000.0);
                edit2.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                edit2.HasZ_2         = false;
                edit2.HasM_2         = false;
                field.GeometryDef_2  = edit2;
                ifieldsEdit_2.AddField(field);
            }
        }
예제 #23
0
        public IField2 GetGeometryField(string geometryType, string geometryFieldName)
        {
            esriGeometryType type = _geometryTypeProvider.GetGeometryType(geometryType);
            // Create the geometry field
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            // Assign Geometry Definition
            geometryDefEdit.GeometryType_2 = type;
            geometryDefEdit.GridCount_2    = 1;
            geometryDefEdit.set_GridSize(0, 0.5);
            geometryDefEdit.AvgNumPoints_2 = 2;
            geometryDefEdit.HasM_2         = false;
            geometryDefEdit.HasZ_2         = false;

            // Create Geometry Field
            IField     fieldShape     = new FieldClass();
            IFieldEdit fieldEditShape = (IFieldEdit)fieldShape;

            fieldEditShape.Name_2        = geometryFieldName;
            fieldEditShape.AliasName_2   = geometryFieldName;
            fieldEditShape.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fieldEditShape.GeometryDef_2 = geometryDef;

            return(null);
        }
예제 #24
0
파일: GDBData.cs 프로젝트: chinasio/minegis
        public static IFeatureClass CreateFClassInPDB(IWorkspace accessworkspace, string feaDSname, string FCname, esriGeometryType esriGeometryType,ISpatialReference sprf)
        {
            try
            {
                IFeatureDataset featureDataset = ((IFeatureWorkspace)accessworkspace).OpenFeatureDataset(feaDSname);
                //IGeoDataset geoDataset = featureDataset as IGeoDataset;

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef pGeometryDef = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IFeatureClass fc = featureDataset.CreateFeatureClass(FCname, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                return fc;
            }

            catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString());
                return null;
            }
        }
예제 #25
0
        static IGeometryDefEdit CreateGeometryDef(esriGeometryType type, int epsg)
        {
            IGeometryDefEdit geomDef = new GeometryDefClass();

            geomDef.GeometryType_2     = type;
            geomDef.SpatialReference_2 = CreateSpatialRef(epsg);
            return(geomDef);
        }
        /// <summary>
        /// Coder:  梁  爽
        /// Date:   2008-10-16
        /// Content:该函数实现要素类的创建,首先用接口IGeometryDefEdit设置要素类的类型,即是Point,Polylin还是Polygon
        ///         然后用接口IFieldEdit设置要素类的字段,这里设置了三个字段,分别是ID,OID和Shape。最后通过接口IFeatureWorkspace
        ///         的CreateFeatureClass方法创建要素类,函数返回IFeatureClass接口类型
        /// </summary>
        /// <param name="pWorkspace">设置工作空间</param>
        /// <param name="pGeometryType">设置要素的类型,即是点,线,还是面</param>
        /// <param name="strFeatName">设置要素类的名称</param>
        /// <param name="ValCoordinatType">传递一个数值型参数,该参数为1-UnkownCoordinateSystem,2-GeographicCoordinateSystem
        ///            或3ProjectedCoordinateSystem</param>
        /// <returns></returns>
        private IFeatureClass CreateFeatureClass(esriGeometryType pesriGeometryType, string pstrLayerName,
                                                 IWorkspace pWorkspace, IMapControl4 pm_mapControl, List <string> pstrFieldNameLt = null, List <esriFieldType> pesriFieldTypeLt = null)
        {
            //创建要素空间
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
            IGeometryDef      geometryDef       = new GeometryDefClass();
            IGeometryDefEdit  pGeometryDefEdit  = (IGeometryDefEdit)geometryDef;

            //_esriGeometryType could be: esriGeometryPoint, esriGeometryMultipoint,
            //esriGeometryPolyline, esriGeometryPolygon, and esriGeometryMultiPatch.
            pGeometryDefEdit.GeometryType_2     = pesriGeometryType;
            pGeometryDefEdit.SpatialReference_2 = pm_mapControl.SpatialReference;
            // Set the grid count to 1 and the grid size to 0 to allow ArcGIS to
            // determine a valid grid size.
            pGeometryDefEdit.GridCount_2 = 1;
            pGeometryDefEdit.set_GridSize(0, 0);

            //新建字段
            IFieldsEdit pFieldsEdit = new FieldsClass();
            //添加“Shape”字段
            IFieldEdit pField;

            pField               = new FieldClass();
            pField.Type_2        = esriFieldType.esriFieldTypeGeometry;
            pField.GeometryDef_2 = geometryDef;
            pField.Name_2        = "Shape";
            pFieldsEdit.AddField((IField)pField);
            //添加其它字段
            if (pstrFieldNameLt != null)
            {
                //we don't need the first three FieldNames, i.e., "FID", "Shape", and "Id"
                for (int i = 0; i < pstrFieldNameLt.Count; i++)
                {
                    pFieldsEdit.AddField((IField)GenerateFieldEdit(pesriFieldTypeLt[i], pstrFieldNameLt[i]));
                }
            }


            string strFullName = pWorkspace.PathName + "\\" + pstrLayerName;

            File.Delete(strFullName + ".dbf");
            File.Delete(strFullName + ".lyr");
            File.Delete(strFullName + ".prj");
            File.Delete(strFullName + ".shp");
            //File.Delete(strFullName + ".shp.PALANQUE.2296.5388.sr.lock");
            File.Delete(strFullName + ".shx");

            try
            {
                return(pFeatureWorkspace.CreateFeatureClass(pstrLayerName,
                                                            (IFields)pFieldsEdit, null, null, esriFeatureType.esriFTSimple, "Shape&quot;", ""));
            }
            catch
            {
                return(pFeatureWorkspace.CreateFeatureClass(pstrLayerName,
                                                            (IFields)pFieldsEdit, null, null, esriFeatureType.esriFTSimple, "Shape", ""));
            }
        }
        public IFeatureClass CreateShapefile(String sParentDirectory, String sWorkspaceName, String sFileName)
        {
            IWorkspaceFactory workspaceFactory;
            IWorkspace        workspace;
            IFeatureWorkspace featureWorkspace;
            IFeatureClass     featureClass;

            if (System.IO.Directory.Exists(sParentDirectory + sWorkspaceName))
            {
                workspaceFactory = new ShapefileWorkspaceFactoryClass();
                workspace        = workspaceFactory.OpenFromFile(sParentDirectory + sWorkspaceName, 0);
                featureWorkspace = workspace as IFeatureWorkspace;
                featureClass     = featureWorkspace.OpenFeatureClass(sFileName);
            }
            else
            {
                workspaceFactory = new ShapefileWorkspaceFactoryClass();
                IWorkspaceName workspaceName      = workspaceFactory.Create(sParentDirectory, sWorkspaceName, null, 0);
                ESRI.ArcGIS.esriSystem.IName name = workspaceName as ESRI.ArcGIS.esriSystem.IName;
                workspace        = (IWorkspace)name.Open();
                featureWorkspace = workspace as IFeatureWorkspace;

                IFields     fields     = new FieldsClass();
                IFieldsEdit fieldsEdit = fields as IFieldsEdit;

                IFieldEdit fieldEdit = new FieldClass();
                fieldEdit.Name_2      = "OID";
                fieldEdit.AliasName_2 = "序号";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField((IField)fieldEdit);

                fieldEdit             = new FieldClass();
                fieldEdit.Name_2      = "Name";
                fieldEdit.AliasName_2 = "名称";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeString;
                fieldsEdit.AddField((IField)fieldEdit);

                IGeometryDefEdit  geoDefEdit       = new GeometryDefClass();
                ISpatialReference spatialReference = m_map.SpatialReference;
                geoDefEdit.SpatialReference_2 = spatialReference;
                geoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;

                fieldEdit               = new FieldClass();
                fieldEdit.Name_2        = "Shape";
                fieldEdit.AliasName_2   = "形状";
                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit.GeometryDef_2 = geoDefEdit;
                fieldsEdit.AddField((IField)fieldEdit);

                featureClass = featureWorkspace.CreateFeatureClass(sFileName, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                if (featureClass == null)
                {
                    return(null);
                }
            }
            return(featureClass);
        }
예제 #28
0
        public IFeatureClass CreateShapefile(
            string sParentDirectory,
            string sWorkspaceName,
            string sFileName)
        {
            if (System.IO.Directory.Exists(sParentDirectory + sWorkspaceName))
            {
                System.IO.Directory.Delete(sParentDirectory + sWorkspaceName, true);
            }

            IWorkspaceFactory pWf = new ShapefileWorkspaceFactoryClass();
            IWorkspaceName    pWn = pWf.Create(sParentDirectory, sWorkspaceName, null, 0);

            ESRI.ArcGIS.esriSystem.IName name = pWn as ESRI.ArcGIS.esriSystem.IName;

            IWorkspace        pW  = (IWorkspace)name.Open();
            IFeatureWorkspace pFw = pW as IFeatureWorkspace;

            IFields     pFs  = new FieldsClass();
            IFieldsEdit pFse = pFs as IFieldsEdit;

            IFieldEdit pFe = new FieldClass();

            pFe.Name_2      = "OID";
            pFe.AliasName_2 = "序号";
            pFe.Type_2      = esriFieldType.esriFieldTypeOID;
            pFse.AddField((IField)pFe);//IFieldEdit.AddField是AO隐藏属性

            pFe             = new FieldClass();
            pFe.Name_2      = "Name";
            pFe.AliasName_2 = "名称";
            pFe.Type_2      = esriFieldType.esriFieldTypeString;
            pFse.AddField((IField)pFe);

            IGeometryDefEdit  pGde = new GeometryDefClass();
            ISpatialReference pSr  = m_map.SpatialReference;

            pGde.SpatialReference_2 = pSr;
            pGde.GeometryType_2     = esriGeometryType.esriGeometryPoint;

            pFe = new FieldClass();
            string sShapeFieldName = "Shape";

            pFe.Name_2        = sShapeFieldName;
            pFe.AliasName_2   = "形状";
            pFe.Type_2        = esriFieldType.esriFieldTypeGeometry;
            pFe.GeometryDef_2 = pGde;
            pFse.AddField((IField)pFe);

            IFeatureClass pFc = pFw.CreateFeatureClass(sFileName, pFs, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            if (pFc == null)
            {
                return(null);
            }
            return(pFc);
        }
예제 #29
0
        public static IFields GetFields(IFeatureClass featureClass)
        {
            IFields     pNewFields     = new FieldsClass();
            IFields     pFields        = featureClass.Fields;
            IFieldsEdit pNewFieldsEdit = pNewFields as IFieldsEdit;
            int         fieldCount     = pFields.FieldCount;

            for (int i = 0; i < fieldCount; i++)
            {
                IField pField = pFields.Field[i];
                if (pField.Name == "OBJECTID_1" || pField.Name == "OBJECTID")
                {
                    continue;
                }
                if (pField.Editable == false)
                {
                    continue;
                }
                IField     pNewField     = new FieldClass();
                IFieldEdit pNewFieldEdit = pNewField as IFieldEdit;
                pNewFieldEdit.Name_2      = pField.Name;
                pNewFieldEdit.AliasName_2 = pField.AliasName;

                if (pField.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    pNewFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                    IGeometryDef     pGeometryDef     = new GeometryDefClass();
                    IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                    pGeometryDefEdit.GeometryType_2 = pField.GeometryDef.GeometryType;
                    if (pField.GeometryDef.SpatialReference.Name == "Unknown")
                    {
                        ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
                        pSpatialReference.SetDomain(-1000000, 1000000, -1000000, 1000000);
                        pSpatialReference.SetZDomain(0, 0);
                        pSpatialReference.SetMDomain(0, 0);
                        pGeometryDefEdit.SpatialReference_2 = pSpatialReference;
                    }
                    else
                    {
                        pGeometryDefEdit.SpatialReference_2 = pField.GeometryDef.SpatialReference;
                    }
                    pNewFieldEdit.GeometryDef_2 = pGeometryDefEdit;
                }
                else
                {
                    pNewFieldEdit.DefaultValue_2 = pField.DefaultValue;
                    pNewFieldEdit.DomainFixed_2  = pField.DomainFixed;
                    pNewFieldEdit.Domain_2       = pField.Domain;
                    pNewFieldEdit.Precision_2    = pField.Precision;
                    pNewFieldEdit.Required_2     = pField.Required;
                    pNewFieldEdit.Scale_2        = pField.Scale;
                    pNewFieldEdit.Type_2         = pField.Type;
                }
                pNewFieldsEdit.AddField(pNewField);
            }
            return(pNewFieldsEdit);
        }
예제 #30
0
파일: Program.cs 프로젝트: nicogis/Voronoi
        /// <summary>
        /// create feature class of output
        /// </summary>
        /// <param name="workspace">object workspace</param>
        /// <param name="spatialReference">spatial reference of feature class of output</param>
        /// <param name="nameFeatureClass">name of feature class</param>
        /// <returns>object feature class</returns>
        private static IFeatureClass CreateFeatureClassOutput(IWorkspace workspace, ISpatialReference spatialReference, string nameFeatureClass)
        {
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription objectClassDescription = (IObjectClassDescription)featureClassDescription;

            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

            // Create the fields collection.
            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            IField oidField = new FieldClass();
            IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
            oidFieldEdit.Name_2 = "OBJECTID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            // Create the Shape field.
            IField shapeField = new Field();
            IFieldEdit shapeFieldEdit = (IFieldEdit)shapeField;

            // Set up the geometry definition for the Shape field.
            IGeometryDef geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

            // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size
            // will be based on the initial loading or inserting of features.
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;

            geometryDefEdit.SpatialReference_2 = spatialReference;

            // Set standard field properties.
            shapeFieldEdit.Name_2 = featureClassDescription.ShapeFieldName;
            shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            shapeFieldEdit.GeometryDef_2 = geometryDef;
            shapeFieldEdit.IsNullable_2 = true;
            shapeFieldEdit.Required_2 = true;
            fieldsEdit.AddField(shapeField);

            IField idField = new FieldClass();
            IFieldEdit idIsolaFieldEdit = (IFieldEdit)idField;
            idIsolaFieldEdit.Name_2 = Program.nameFieldIdOutput;
            idIsolaFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(idField);

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError = null;
            IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            return featureWorkspace.CreateFeatureClass(nameFeatureClass, fields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, featureClassDescription.ShapeFieldName, string.Empty);
        }
        /// <summary>
        /// create a feature class in workspace with type geometry
        /// </summary>
        /// <param name="geometry">geometry of feature class</param>
        /// <param name="featureWorkspace">workspace for store feature class</param>
        /// <returns>feature class created</returns>
        private IFeatureClass CreateFeatureClass(IGeometry geometry, IFeatureWorkspace featureWorkspace)
        {
            // Create a fields collection for the feature class.
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            // Add an object ID field to the fields collection. This is mandatory for feature classes.
            IField     oidField     = new FieldClass();
            IFieldEdit oidFieldEdit = (IFieldEdit)oidField;

            oidFieldEdit.Name_2 = "OID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            IField     idField     = new FieldClass();
            IFieldEdit idFieldEdit = (IFieldEdit)idField;

            idFieldEdit.Name_2 = SAUtility.FieldNameIdWatershed;
            idFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(idField);

            // Create a geometry definition (and spatial reference) for the feature class.
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = geometry.GeometryType;
            geometryDefEdit.SpatialReference_2 = geometry.SpatialReference;

            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = (IObjectClassDescription)featureClassDescription;

            // Add a geometry field to the fields collection. This is where the geometry definition is applied.
            IField     geometryField     = new FieldClass();
            IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;

            geometryFieldEdit.Name_2        = featureClassDescription.ShapeFieldName;
            geometryFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            geometryFieldEdit.GeometryDef_2 = geometryDef;
            fieldsEdit.AddField(geometryField);

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            // Create the feature class. Note that the CLSID parameter is null - this indicates to use the
            // default CLSID, esriGeodatabase.Feature (acceptable in most cases for feature classes).
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass("pourPoint", validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, featureClassDescription.ShapeFieldName, string.Empty);

            return(featureClass);
        }
예제 #32
0
        public void Test()
        {
            //定义一个几何字段,类型为点类型
            ISpatialReferenceFactory2 originalSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference         originalSpatialReference        = originalSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            IGeometryDefEdit          pGeoDef     = new GeometryDefClass();
            IGeometryDefEdit          pGeoDefEdit = pGeoDef as IGeometryDefEdit;

            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

            pGeoDefEdit.SpatialReference_2 = originalSpatialReference;
            //定义一个字段集合对象
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            //定义shape字段
            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            pFieldEdit.Name_2 = "SHAPE";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            pFieldsEdit.AddField(pField);
            pFieldEdit.GeometryDef_2 = pGeoDef;

            //定义单个的字段,并添加到字段集合中
            pField            = new FieldClass();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "STCD";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            //定义单个的字段,并添加到字段集合中
            pField            = new FieldClass();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "SLM10";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            //定义单个的字段,并添加到字段集合中
            pField            = new FieldClass();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "SLM20";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            //定义单个的字段,并添加到字段集合中
            pField            = new FieldClass();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "SLM40";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
            IFeatureWorkspace pFWS     = pWorkspaceFactory.OpenFromFile(workspaceDirectory, 0) as IFeatureWorkspace;
            IFeatureClass     pFtClass = pFWS.CreateFeatureClass("Test", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", null);
        }
        private IFields CreateChainFields()
        {
            IFields     flds  = new FieldsClass();
            IFieldsEdit eflds = flds as IFieldsEdit;

            eflds.FieldCount_2 = 7;

            IField     oid_field = new FieldClass();
            IFieldEdit eOid      = (IFieldEdit)oid_field;

            eOid.Name_2      = "ObjectID";
            eOid.AliasName_2 = "ObjectID";
            eOid.Type_2      = esriFieldType.esriFieldTypeOID;

            eflds.set_Field(0, oid_field);

            //Create A geometry Definition for the layer
            IGeometryDef     geomDef  = new GeometryDefClass();
            IGeometryDefEdit egeomDef = (IGeometryDefEdit)geomDef;

            egeomDef.GeometryType_2     = esriGeometryType.esriGeometryPolyline;
            egeomDef.SpatialReference_2 = ArcMap.Document.FocusMap.SpatialReference;

            IField     shap   = new FieldClass();
            IFieldEdit eshape = (IFieldEdit)shap;

            eshape.Type_2        = esriFieldType.esriFieldTypeGeometry;
            eshape.Name_2        = "Shape";
            eshape.AliasName_2   = "Shape";
            eshape.GeometryDef_2 = geomDef;

            eflds.set_Field(1, shap);

            IField FromLeft = CreateIntegerField("FromLeft");

            eflds.set_Field(2, FromLeft);

            IField ToLeft = CreateIntegerField("ToLeft");

            eflds.set_Field(3, ToLeft);

            IField FromRight = CreateIntegerField("FromRight");

            eflds.set_Field(4, FromRight);

            IField ToRight = CreateIntegerField("ToRight");

            eflds.set_Field(5, ToRight);

            IField CLID = CreateIntegerField("CLID");

            eflds.set_Field(6, CLID);

            return(flds);
        }
예제 #34
0
 public static IGeometryDefEdit CreateGeometryDef(esriGeometryType type, int epsg)
 {
     if (epsg > 0)
     {
         IGeometryDefEdit geomDef = new GeometryDefClass();
         geomDef.GeometryType_2     = type;
         geomDef.SpatialReference_2 = GetSpatialReference((uint)epsg);
         return(geomDef);
     }
     return(null);
 }
예제 #35
0
        public void CreateLineShpFile(string fileName, ISpatialReference pSRF)
        {
            //判断需要生成的线文件是否存在,若不存在则创建文件,若存在则将新添加的线写入文件
            if (File.Exists(fileName))
            {
                MessageBox.Show("file already exist, please change file name!");
                return;
            }
            else
            {
                string pLineFile = fileName;
                string pFilePath = System.IO.Path.GetDirectoryName(pLineFile);
                string pFileName = System.IO.Path.GetFileName(pLineFile);
                //打开工作空间
                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pWS  = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0);

                //判断文件是否存在,若不存在则创建文件
                if (!(File.Exists(fileName)))
                {
                    const string strShapeFieldName = "shape";
                    //设置字段集
                    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.esriGeometryPolyline;
                    pGeoDefEdit.SpatialReference_2 = pSRF;
                    pFieldEdit.GeometryDef_2       = pGeoDef;
                    pFieldsEdit.AddField(pField);

                    //add length field
                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "length";
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    //创建shapefile线图层
                    pWS.CreateFeatureClass(pFileName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");
                }
            }
        }
예제 #36
0
        //创建线图层
        public IFeatureClass CreatLineFC(IFeatureDataset pFeatureDataset, IFeatureClass pPointFClass)
        {
            try
            {
                //建立shape字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //设置Geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolyline; //点、线、面
                pGeometryDefEdit.SpatialReference_2 = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "Length";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                IFeatureClass pFeatureClass = pFeatureDataset.CreateFeatureClass(textBoxX3.Text + "_GmpLine", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

                FrmPointToLine frmP2L  = new FrmPointToLine(m_pMapCtl.Object as IMapControl3);
                IFeatureLayer  PFLayer = new FeatureLayerClass();
                PFLayer.FeatureClass = pPointFClass;
                IPointCollection pPointColl = frmP2L.ReadPoint(PFLayer);
                List <IPolyline> LineList   = CreatePolyline(pPointColl);

                for (int i = 0; i < LineList.Count; i++)
                {
                    if (LineList[i].Length > 0)
                    {
                        IFeature pFeature = pFeatureClass.CreateFeature();
                        pFeature.Shape = LineList[i];
                        string sLength = ((int)(LineList[i].Length * 100.0) / 100.0).ToString() + "m";
                        pFeature.set_Value(pFeature.Fields.FindField("Length"), sLength);
                        pFeature.Store();
                    }
                }
                return(pFeatureClass);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
예제 #37
0
        private IFeatureLayer CreateShpFromPoints(List <CPoint> cPointList, string filePath)
        {
            int               index     = filePath.LastIndexOf('\\');
            string            folder    = filePath.Substring(0, index);
            string            shapeName = filePath.Substring(index + 1);
            IWorkspaceFactory pWSF      = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS      = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0);

            IFields     pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit;

            pFieldsEdit = (IFieldsEdit)pFields;

            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef     pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGDefEdit    = (IGeometryDefEdit)pGeometryDef;

            pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            //定义坐标系
            ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
            ISpatialReference        pSpatialReference = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);

            pGDefEdit.SpatialReference_2 = pSpatialReference;

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

            IFeatureClass pFeatureClass;

            pFeatureClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            IPoint pPoint = new PointClass();

            for (int j = 0; j < cPointList.Count; j++)
            {
                pPoint.X = cPointList[j].X;
                pPoint.Y = cPointList[j].Y;

                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.Store();
            }

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.Name         = shapeName;
            pFeatureLayer.FeatureClass = pFeatureClass;
            return(pFeatureLayer);
        }
예제 #38
0
        /// <summary>
        /// 生成signature文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SC_CreateSampleFiles_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (SC_dataGridView.Rows.Count == 0)
            {
                return;
            }
            SaveFileDialog SaveSignatureFile = new SaveFileDialog();

            SaveSignatureFile.Title  = "生成Signature文件";
            SaveSignatureFile.Filter = "样本文件|*.gsg";
            if (SaveSignatureFile.ShowDialog() == DialogResult.OK)
            {
                IGeoDataset inputraster = SampleLayerCombox.Tag as IGeoDataset;

                //在临时文件夹生成featureclass,根据featureclass生成signature文件
                //判断临时文件夹下是否有重名
                int changefilename = 0;
                while (System.IO.File.Exists(Application.StartupPath + "\\temp\\TempSample" + changefilename + ".shp"))
                {
                    changefilename++;
                }
                //新建featureclass字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                //设置geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2     = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
                pGeometryDefEdit.SpatialReference_2 = inputraster.SpatialReference;
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\temp", 0) as IFeatureWorkspace;
                IFeatureClass     featureclass      = pFeatureWorkspace.CreateFeatureClass("TempSample" + changefilename + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                //根据单元格tag中存储的多边形生成对应要素
                for (int i = 0; i < SC_dataGridView.Rows.Count; i++)
                {
                    IFeature feature = featureclass.CreateFeature();
                    feature.Shape = SC_dataGridView.Rows[i].Cells["color"].Tag as IPolygon;
                    feature.Store();
                }
                //生成signature文件
                IGeoDataset     Sampledataset  = featureclass as IGeoDataset;
                IMultivariateOp Multivariateop = new RasterMultivariateOpClass();
                Multivariateop.CreateSignatures(inputraster, Sampledataset, SaveSignatureFile.FileName + ".gsg", true);
            }
        }
예제 #39
0
        public static IField CreateGeometryField(esriGeometryType pGT, ISpatialReference pSR, bool pHasZ)
        {
            FieldClass class2 = new FieldClass();
            IFieldEdit edit = class2;
            edit.Name_2 = "SHAPE";
            edit.AliasName_2 = "图形对象";
            edit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeoDef = new GeometryDefClass();
            IGeometryDefEdit class3 = (IGeometryDefEdit)pGeoDef;

            class3.GeometryType_2 = pGT;
            class3.HasM_2 = false;
            class3.HasZ_2 = pHasZ;
            class3.GridCount_2 = 1;
            class3.set_GridSize(0, 1000.0);
            class3.SpatialReference_2 = pSR;
            edit.GeometryDef_2 = class3;
            return class2;
        }
예제 #40
0
        //������ţ�RasterCreate-04
        //��������createGeometryDef
        //���ܣ��������ζ���
        //������spatialReference���ռ�ο�
        //
        public IGeometryDef createGeometryDef(ISpatialReference spatialReference)
        {
            // Create GeometryDef
            IGeometryDefEdit geometryDefEdit = new GeometryDefClass();

            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.AvgNumPoints_2 = 4;
            //���ÿռ������IJ���
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 1000);

            // Set unknown spatial reference is not set
            if (spatialReference == null)
                spatialReference = new UnknownCoordinateSystemClass();

            //���ÿռ�ο�
            geometryDefEdit.SpatialReference_2 = spatialReference;

            return (IGeometryDef)geometryDefEdit;
        }
예제 #41
0
        public static IField CreateShapeField(FeatureClassInfo fcInfo)
        {
            IFieldEdit shpField = new FieldClass();
            shpField.Name_2=string.IsNullOrWhiteSpace(fcInfo.ShapeFieldName)?"Shape":fcInfo.ShapeFieldName;
            shpField.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDefEdit geoDef=new GeometryDefClass();
            geoDef.AvgNumPoints_2 = fcInfo.AvgNumPoints;
            geoDef.GeometryType_2=fcInfo.ShapeType;
            geoDef.GridCount_2=fcInfo.GridCount;
            geoDef.HasM_2 = fcInfo.HasM;
            geoDef.HasZ_2 = fcInfo.HasZ;
            geoDef.SpatialReference_2 = fcInfo.SpatialReference;

            shpField.GeometryDef_2=geoDef;

            return shpField;
        }
        /// <summary>
        /// Export graphics to a shapefile
        /// </summary>
        /// <param name="fileNamePath">Path to shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Created featureclass</returns>
        private IFeatureClass ExportToShapefile(string fileNamePath, List<Graphic> graphicsList, ISpatialReference ipSpatialRef)
        {
            int index = fileNamePath.LastIndexOf('\\');
            string folder = fileNamePath.Substring(0, index);
            string nameOfShapeFile = fileNamePath.Substring(index + 1);
            string shapeFieldName = "Shape";
            IFeatureClass featClass = null;

            using (ComReleaser oComReleaser = new ComReleaser())
            {
                try
                {
                    IWorkspaceFactory workspaceFactory = null;
                    workspaceFactory = new ShapefileWorkspaceFactoryClass();
                    IWorkspace workspace = workspaceFactory.OpenFromFile(folder, 0);
                    IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
                    IFields fields = null;
                    IFieldsEdit fieldsEdit = null;
                    fields = new Fields();
                    fieldsEdit = (IFieldsEdit)fields;
                    IField field = null;
                    IFieldEdit fieldEdit = null;
                    field = new FieldClass();///###########
                    fieldEdit = (IFieldEdit)field;
                    fieldEdit.Name_2 = "Shape";
                    fieldEdit.Type_2 = (esriFieldType.esriFieldTypeGeometry);
                    IGeometryDef geomDef = null;
                    IGeometryDefEdit geomDefEdit = null;
                    geomDef = new GeometryDefClass();///#########
                    geomDefEdit = (IGeometryDefEdit)geomDef;

                    //This is for line shapefiles
                    geomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                    geomDefEdit.SpatialReference_2 = ipSpatialRef;

                    fieldEdit.GeometryDef_2 = geomDef;
                    fieldsEdit.AddField(field);

                    ////Add another miscellaneous text field
                    //field = new FieldClass();
                    //fieldEdit = (IFieldEdit)field;
                    //fieldEdit.Length_2 = 30;
                    //fieldEdit.Name_2 = "TextField";
                    //fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    //fieldsEdit.AddField(field);

                    featClass = featureWorkspace.CreateFeatureClass(nameOfShapeFile, fields, null, null, esriFeatureType.esriFTSimple, shapeFieldName, "");

                    foreach (Graphic graphic in graphicsList)
                    {
                        IFeature feature = featClass.CreateFeature();

                        feature.Shape = graphic.Geometry;
                        feature.Store();
                    }

                    IFeatureLayer featurelayer = null;
                    featurelayer = new FeatureLayerClass();
                    featurelayer.FeatureClass = featClass;
                    featurelayer.Name = featClass.AliasName;

                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(workspace);
                    workspace = null;
                    GC.Collect();

                    return featClass;
                }
                catch (Exception ex)
                {
                    return featClass;
                }
            }
        }
예제 #43
0
        /// <summary>
        /// This initialises all of the different fields that are required for the locator to function
        /// It contains declarations for the Match and Candidate fields for the locator
        /// </summary>
        protected override void CreateFields()
        {
            IFieldsEdit fieldsEdit = new FieldsClass();
            IFieldEdit shapeField = new FieldClass();
            IFieldEdit statusField = new FieldClass();
            IFieldEdit scoreField = new FieldClass();
            IFieldEdit xField = new FieldClass();
            IFieldEdit yField = new FieldClass();
            IFieldEdit matchField = new FieldClass();

            m_spatialReference = new SpatialReferenceEnvironmentClass().CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid);
            SearchDistanceUnits = esriUnits.esriMeters;
            // Set up the spatial Reference and Geometry Definition
            IGeometryDefEdit geometryDefEdit = new GeometryDefClass();
            geometryDefEdit.SpatialReference_2 = m_spatialReference;
            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

            // Create the matchFields
            shapeField.Name_2 = "Shape";
            shapeField.Type_2 = esriFieldType.esriFieldTypeGeometry;
            shapeField.GeometryDef_2 = geometryDefEdit as IGeometryDef;
            fieldsEdit.AddField(shapeField);

            statusField.Name_2 = "Status";
            statusField.Type_2 = esriFieldType.esriFieldTypeString;
            statusField.Length_2 = 1;
            fieldsEdit.AddField(statusField);

            scoreField.Name_2 = "Score";
            scoreField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fieldsEdit.AddField(scoreField);

            matchField.Name_2 = "Match_addr";
            matchField.Type_2 = esriFieldType.esriFieldTypeString;
            matchField.Length_2 = 50;
            fieldsEdit.AddField(matchField);

            xField.Name_2 = "X";
            xField.Type_2 = esriFieldType.esriFieldTypeDouble;
            xField.Length_2 = 16;
            xField.Precision_2 = 10;
            fieldsEdit.AddField(xField);

            yField.Name_2 = "Y";
            yField.Type_2 = esriFieldType.esriFieldTypeDouble;
            yField.Length_2 = 16;
            yField.Precision_2 = 10;
            fieldsEdit.AddField(yField);

            IFieldEdit XMinField = new FieldClass();
            IFieldEdit YMinField = new FieldClass();
            IFieldEdit XMaxField = new FieldClass();
            IFieldEdit YMaxField = new FieldClass();
            IFieldEdit addrType = new FieldClass();

            XMinField.Name_2 = "XMin";
            YMinField.Name_2 = "YMin";
            XMaxField.Name_2 = "XMax";
            YMaxField.Name_2 = "YMax";
            addrType.Name_2 = "Addr_type";

            XMinField.Type_2 = esriFieldType.esriFieldTypeDouble;
            YMinField.Type_2 = esriFieldType.esriFieldTypeDouble;
            XMaxField.Type_2 = esriFieldType.esriFieldTypeDouble;
            YMaxField.Type_2 = esriFieldType.esriFieldTypeDouble;
            addrType.Type_2 = esriFieldType.esriFieldTypeString;

            XMinField.Precision_2 = 8;
            YMinField.Precision_2 = 8;
            XMaxField.Precision_2 = 8;
            YMaxField.Precision_2 = 8;
            addrType.Length_2 = 20;

            fieldsEdit.AddField(XMinField);
            fieldsEdit.AddField(YMinField);
            fieldsEdit.AddField(XMaxField);
            fieldsEdit.AddField(YMaxField);
            fieldsEdit.AddField(addrType);

            m_matchFields = fieldsEdit as IFields;

            fieldsEdit = new FieldsClass();
            shapeField = new FieldClass();
            scoreField = new FieldClass();
            xField = new FieldClass();
            yField = new FieldClass();
            matchField = new FieldClass();

            // Create the CandidateFields
            shapeField.Name_2 = "Shape";
            shapeField.Type_2 = esriFieldType.esriFieldTypeGeometry;
            shapeField.GeometryDef_2 = geometryDefEdit as GeometryDef;
            fieldsEdit.AddField(shapeField);

            scoreField.Name_2 = "Score";
            scoreField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fieldsEdit.AddField(scoreField);

            matchField.Name_2 = "Match_addr";
            matchField.Type_2 = esriFieldType.esriFieldTypeString;
            matchField.Length_2 = 50;
            fieldsEdit.AddField(matchField);

            xField.Name_2 = "X";
            xField.Type_2 = esriFieldType.esriFieldTypeDouble;
            xField.Length_2 = 16;
            xField.Precision_2 = 10;
            fieldsEdit.AddField(xField);

            yField.Name_2 = "Y";
            yField.Type_2 = esriFieldType.esriFieldTypeDouble;
            yField.Length_2 = 16;
            yField.Precision_2 = 10;
            fieldsEdit.AddField(yField);

            fieldsEdit.AddField(XMinField);
            fieldsEdit.AddField(YMinField);
            fieldsEdit.AddField(XMaxField);
            fieldsEdit.AddField(YMaxField);
            fieldsEdit.AddField(addrType);

            m_candidateFields = fieldsEdit as IFields;
        }
예제 #44
0
        private void 添加面形地物ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //创建要素类
            #region 创建新的内存工作空间
            IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0);

            IName pName = (IName)pWSName;
            IWorkspace pMemoryWS = (IWorkspace)pName.Open();
            #endregion

            IField oField = new FieldClass();
            IFields oFields = new FieldsClass();
            IFieldsEdit oFieldsEdit = null;
            IFieldEdit oFieldEdit = null;
            IFeatureClass oFeatureClass = null;
            IFeatureLayer oFeatureLayer = null;

            oFieldsEdit = oFields as IFieldsEdit;
            oFieldEdit = oField as IFieldEdit;
            oFieldEdit.Name_2 = "OBJECTID";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            oFieldEdit.IsNullable_2 = false;
            oFieldEdit.Required_2 = false;
            oFieldsEdit.AddField(oField);

            oField = new FieldClass();
            oFieldEdit = oField as IFieldEdit;
            IGeometryDef pGeoDef = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
            pGeoDefEdit.AvgNumPoints_2 = 5;
            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            pGeoDefEdit.GridCount_2 = 1;
            pGeoDefEdit.HasM_2 = false;
            pGeoDefEdit.HasZ_2 = false;
            pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;
            oFieldEdit.Name_2 = "SHAPE";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            oFieldEdit.GeometryDef_2 = pGeoDef;
            oFieldEdit.IsNullable_2 = true;
            oFieldEdit.Required_2 = true;
            oFieldsEdit.AddField(oField);

            oField = new FieldClass();
            oFieldEdit = oField as IFieldEdit;
            oFieldEdit.Name_2 = "Code";
            oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            oFieldEdit.IsNullable_2 = true;
            oFieldsEdit.AddField(oField);
            //创建要素类
            oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            oFeatureLayer = new FeatureLayerClass();
            oFeatureLayer.Name = "PolygonLayer";
            oFeatureLayer.FeatureClass = oFeatureClass;
            //创建唯一值符号化对象
            IUniqueValueRenderer pURender = new UniqueValueRendererClass();
            pURender.FieldCount = 1;
            pURender.set_Field(0, "Code");
            pURender.UseDefaultSymbol = false;
            ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass();
            pFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
            //半透明颜色
            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 255;
            pColor.Green = 255;
            pFillSym.Color = pColor;
            pURender.AddValue("1", "", pFillSym as ISymbol);
            pFillSym = new SimpleFillSymbolClass();
            pFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
            //唯一值符号化内存图层
            (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer;
            ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects;
            //透明度
            pLyrEffect.Transparency = 0;



            this.axMapControl1.AddLayer(oFeatureLayer, axMapControl1.LayerCount);
            insertPolygon = true;
        }
        /// <summary>
        /// 储存点shp,聚类号在"index"字段中标注
        /// </summary>
        public void CreatePointsShapefile()
        {
            string filePath = m_dataInfo.GetOutputFilePath();
            string fileName = m_dataInfo.GetOutputFileName();
            ISpatialReference spatialReference = m_dataInfo.GetSpatialReference();
            int index = fileName.LastIndexOf(".");
            fileName = fileName.Substring(0, index);
            fileName = fileName + "_pts.shp";
            //打开工作空间
            const string strShapeFieldName = "shape";
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(filePath, 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 = spatialReference;

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

            pField = new FieldClass();
            pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "index";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            pFieldEdit.Precision_2 = 7;//数值精度
            //            pFieldEdit.Scale_2 = 3;//小数点位数
            pFieldsEdit.AddField(pField);

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

            //在featureclass中创建feature
            IWorkspaceEdit workspaceEdit = pWS as IWorkspaceEdit;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            IFeatureClass featureClass = pWS.OpenFeatureClass(fileName);
            IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
            IFeatureCursor featureCursor = featureClass.Search(null, true);
            IFeature feature = featureCursor.NextFeature();
            while (feature != null)
            {
                feature.Delete();
                feature = featureCursor.NextFeature();
            }
            featureCursor = featureClass.Insert(true);
            int typeFieldIndex = featureClass.FindField("index");
            //插入点,并写入聚类号
            for (int i = 0; i < m_clusters.GetClusterCount(); i++)
            {
                Cluster currentCluster = m_clusters.GetCluster(i);
                List<IPoint> currentPoints = currentCluster.GetPointsList();
                for (int j = 0; j < currentPoints.Count; j++)
                {
                    featureBuffer.set_Value(typeFieldIndex, currentCluster.GetClusterIndex());
                    featureBuffer.Shape = currentPoints[j] as IGeometry;
                    object featureOID = featureCursor.InsertFeature(featureBuffer);
                }
            }
            featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

            //将新创建的shapfile作为图层添加到map里
            IFeatureLayer featureLayer = new FeatureLayerClass();
            featureLayer.FeatureClass = featureClass;
            featureLayer.Name = featureClass.AliasName;

            m_pointLayer = featureLayer;
            ////设置渲染
            //DefinePointUniqueValueRenderer(featureLayer as IGeoFeatureLayer, "Class");
            //m_mapControl.AddLayer(featureLayer as ILayer);
            //this.m_mapControl.Refresh();
        }
        private ESRI.ArcGIS.Geodatabase.IFeatureClass CreatePointFeatureClass(System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID)
        {
            if (featureClassName == "") return null; // name was not passed in

            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
            // Create a new in-memory workspace. This returns a name object.
            IWorkspaceName workspaceName = workspaceFactory.Create(null, "OSMPointsWorkspace", null, 0);
            IName name = (IName)workspaceName;

            // Open the workspace through the name object.
            IWorkspace workspace = (IWorkspace)name.Open();

            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

            // assign the class id value if not assigned
            if (CLSID == null)
            {
                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                // add the OSM ID field
                IFieldEdit osmIDField = new FieldClass() as IFieldEdit;
                osmIDField.Name_2 = "OSMID";
                osmIDField.Type_2 = esriFieldType.esriFieldTypeString;
                osmIDField.Length_2 = 20;
                fieldsEdit.AddField((IField)osmIDField);

                // add the field for the tag cloud for all other tag/value pairs
                IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit;
                osmXmlTagsField.Name_2 = "osmTags";
                    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                fieldsEdit.AddField((IField)osmXmlTagsField);

                // user, uid, visible, version, changeset, timestamp
                IFieldEdit osmuserField = new FieldClass() as IFieldEdit;
                osmuserField.Name_2 = "osmuser";
                osmuserField.Type_2 = esriFieldType.esriFieldTypeString;
                osmuserField.Length_2 = 100;
                fieldsEdit.AddField((IField) osmuserField);

                IFieldEdit osmuidField = new FieldClass() as IFieldEdit;
                osmuidField.Name_2 = "osmuid";
                osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField((IField)osmuidField);

                IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit;
                osmvisibleField.Name_2 = "osmvisible";
                osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString;
                osmvisibleField.Length_2 = 20;
                fieldsEdit.AddField((IField)osmvisibleField);

                IFieldEdit osmversionField = new FieldClass() as IFieldEdit;
                osmversionField.Name_2 = "osmversion";
                osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                fieldsEdit.AddField((IField)osmversionField);

                IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit;
                osmchangesetField.Name_2 = "osmchangeset";
                osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField((IField)osmchangesetField);

                IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit;
                osmtimestampField.Name_2 = "osmtimestamp";
                osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate;
                fieldsEdit.AddField((IField)osmtimestampField);

                IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit;
                osmrelationIDField.Name_2 = "osmMemberOf";
                    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob;
                fieldsEdit.AddField((IField)osmrelationIDField);

                IFieldEdit hasOSMTagsField = new FieldClass() as IFieldEdit;
                hasOSMTagsField.Name_2 = "hasOSMTags";

                IFieldEdit osmSupportingElementField = new FieldClass() as IFieldEdit;
                osmSupportingElementField.Name_2 = "osmSupportingElement";
                osmSupportingElementField.Type_2 = esriFieldType.esriFieldTypeString;
                osmSupportingElementField.Length_2 = 5;
                fieldsEdit.AddField((IField) osmSupportingElementField);

                IFieldEdit wayRefCountField = new FieldClass() as IFieldEdit;
                wayRefCountField.Name_2 = "wayRefCount";
                wayRefCountField.Type_2 = esriFieldType.esriFieldTypeInteger;
                wayRefCountField.DefaultValue_2 = 0;
                fieldsEdit.AddField((IField)wayRefCountField);

                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;

                    // redefine geometry type

                    IFieldEdit shapeField = fields.get_Field(j) as IFieldEdit;
                    IGeometryDefEdit geometryDef = new GeometryDefClass() as IGeometryDefEdit;
                    geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                    geometryDef.HasZ_2 = false;
                    geometryDef.HasM_2 = false;
                    geometryDef.GridCount_2 = 1;
                    geometryDef.set_GridSize(0, 1);

                    ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();
                    ISpatialReference wgs84 = spatialRefFactory.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984) as ISpatialReference;
                    geometryDef.SpatialReference_2 = wgs84;

                    shapeField.GeometryDef_2 = (IGeometryDef)geometryDef;

                    break;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class
                try
                {
                    featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, null, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, "");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

            return featureClass;
        }
예제 #47
0
 public bool CreateRaster(IRasterDataset pRDs, IRasterWorkspaceEx pWorkSpace)
 {
     IRasterProps pRasterProps = (IRasterProps)pRDs.CreateDefaultRaster();
     IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();
     pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;
     pRasterStorageDef.CompressionQuality = 50;
     pRasterStorageDef.PyramidLevel = 2;
     pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
     pRasterStorageDef.TileHeight = 128;
     pRasterStorageDef.TileWidth = 128;
     IRasterDef pRasterDef = new RasterDefClass();
     pRasterDef.Description = "RasterDataset";
     pRasterDef.SpatialReference = pRasterProps.SpatialReference;
     IGeometryDef pGeoDef = new GeometryDefClass();
     IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
     pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
     pGeoDefEdit.AvgNumPoints_2 = 4;
     pGeoDefEdit.GridCount_2 = 1;
     pGeoDefEdit.set_GridSize(0, 1000);
     pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
     IRasterDataset pRasterDataset = pWorkSpace.CreateRasterDataset("zzy", 3, rstPixelType.PT_UCHAR, pRasterStorageDef, "", pRasterDef, pGeoDef);
     pRasterDataset = pRDs;
     return true;
 }
예제 #48
0
        /// <summary>
        /// 创建一个新的FeatureClass
        /// </summary>
        /// <param name="FeatureWorkspace">要素命名空间</param>
        /// <param name="Name">名称</param>
        /// <param name="esriGeometryType">类型</param>
        /// <param name="FieldDict">字段已经类型</param>
        /// <returns></returns>
        private static IFeatureClass Create(IFeatureWorkspace FeatureWorkspace, string Name, ESRI.ArcGIS.Geometry.esriGeometryType esriGeometryType,Dictionary<string,esriFieldType> FieldDict)
        {
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = "shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
            pGeometryDefEdit.GeometryType_2 = esriGeometryType;

            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            pSpatialReference.SetDomain(-6000000, 6000000, -6000000, 6000000);
            pGeometryDefEdit.SpatialReference_2 = pSpatialReference;
            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            pField = new FieldClass();
            pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = "FID";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            pFieldsEdit.AddField(pField);

            foreach (var key in FieldDict.Keys)
            {
                if (key.ToUpper() == "SHAPE"||key.ToUpper()=="OBJECTID")
                {
                    continue;
                }
                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Name_2 = key;
                pFieldEdit.Type_2 = FieldDict[key];
                pFieldsEdit.AddField(pField);
            }

            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription objectClassDescription = featureClassDescription as IObjectClassDescription;
            IFeatureClass featureClass = FeatureWorkspace.CreateFeatureClass(Name, pFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "shape", "");
            return featureClass;
        }
예제 #49
0
파일: SEEDAO.cs 프로젝트: EAWCS1/SUITT
        public void insert(Transaction current, SEE see, ISpatialReference utmSR)
        {
            // Create table on datastore PGDB first?
            current.TxId = see.RestID;
            IPolygon sourcePolygon = see.Shape;
            //sourcePolygon.Project(utmSR);

            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
            fieldsEdit.FieldCount_2 = 3;
            //Create the Object ID field.
            IField fieldUserDefined = new Field();
            IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2 = "OBJECTID";
            fieldEdit.AliasName_2 = "OBJECT ID";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, fieldUserDefined);
            // Create the Shape field.
            fieldUserDefined = new Field();
            fieldEdit = (IFieldEdit)fieldUserDefined;
            // Set up the geometry definition for the Shape field.
            IGeometryDef geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
            // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size
            // will be based on the initial loading or inserting of features.
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;
            //Assign the spatial reference that was passed in, possibly from
            //IGeodatabase.SpatialReference for the containing feature dataset.
            if (see.Shape.SpatialReference != null)
            {
                geometryDefEdit.SpatialReference_2 = see.Shape.SpatialReference;
            }
            //if (utmSR == null)
            //{
            //    ISpatialReferenceFactory2 sre = (ISpatialReferenceFactory2)new SpatialReferenceEnvironment();
            //    utmSR = sre.CreateSpatialReference((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_10N);
            //}

            //geometryDefEdit.SpatialReference_2 = utmSR;// see.Shape.SpatialReference;
            // Set standard field properties.
            fieldEdit.Name_2 = "SHAPE";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Required_2 = true;
            fieldsEdit.set_Field(1, fieldUserDefined);
            // Create a field of type double to hold some information for the features.
            fieldUserDefined = new Field();
            fieldEdit = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2 = "SPATIAL_EDIT_EXTENT_SP_ID";
            fieldEdit.AliasName_2 = "SPATIAL_EDIT_EXTENT_SP_ID";
            fieldEdit.Editable_2 = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Length_2 = 125;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(2, fieldUserDefined);
            // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
            ESRI.ArcGIS.esriSystem.UID CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            IFeatureClass fc = osdb.CreateFeatureClass(OSDB_SEE_NAME, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");

            //IGeoDatasetSchemaEdit fd_ed = (IGeoDatasetSchemaEdit)fc;
            //ISpatialReference oldSR = ((IGeoDataset)fc).SpatialReference;
            //if (fd_ed.CanAlterSpatialReference && !oldSR.Equals(utmSR))
            //{
            //    // does not reproject the data
            //    // doees alter all child feature classes
            //    fd_ed.AlterSpatialReference(utmSR);
            //}

            IWorkspaceEdit wse = (IWorkspaceEdit)osdb;
            wse.StartEditing(false);
            wse.StartEditOperation();

            try
            {
                fc = osdb.OpenFeatureClass(OSDB_SEE_NAME);
            }
            catch(Exception e)
            {
                MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }

            IFeatureCursor fcrs = null;

            try
            {
                fcrs = fc.Insert(false);
                IFeatureBuffer buffer = fc.CreateFeatureBuffer();

                buffer.set_Value(fcrs.FindField(SEE_ID_COL), RestTransactionManager.Instance.NewTransactionSeeID);
                //buffer.set_Value(fcrs.FindField(OSDB_NAME_COL),current.OperationalDatasetName);

                //string t = current.Description;
                //if (t != null && t.Length > EDIT_INTENT_COL_LNG)
                //{
                //    t = t.Substring(0, EDIT_INTENT_COL_LNG);
                //}
                //buffer.set_Value(fcrs.FindField(EDIT_INTENT_COL), t);

                //buffer.set_Value(fcrs.FindField(OPEN_DATE_COL),current.CreationDate);
                //t = current.PGDB.FullName;
                //buffer.set_Value(fcrs.FindField(PGDB_PATH_COL), t);

                IPolygon p = sourcePolygon;
                if(p!=null)
                {
                    //p.Project(utmSR);
                    p.Project(((IGeoDataset)fc).SpatialReference);
                }
                buffer.Shape = p;

                fcrs.InsertFeature(buffer);

                fcrs.Flush();

                // Explicitly release the cursor.
                Marshal.ReleaseComObject(fcrs);

                // Stop editing.
                wse.StopEditOperation();
                wse.StopEditing(true);
            }
            catch(Exception e)
            {
                // Failed while writing the SEE area poygon to the PGDB?
                // We should carry on with the transaction, but the SEE area will be lost

                MessageBox.Show("Error occured storing SEE geometry. " + e.Message);
            }
            finally
            {
                if(fcrs != null)
                {
                    Utils.Release(fcrs);
                }
            }
        }
예제 #50
0
파일: GDBData.cs 프로젝트: chinasio/minegis
        public void CreateFeaInSDE(string name)
        {
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit ;

            pField = new FieldClass();
            pFieldEdit=pField as IFieldEdit;
            pFieldEdit.Name_2 = "OBJECTID";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            pFieldsEdit.AddField(pField);

            pField = new FieldClass();
            pFieldEdit=pField as IFieldEdit;
            pFieldEdit.Name_2 = "SHAPE";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
            pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            ISpatialReference spatialRef = new UnknownCoordinateSystemClass();
            spatialRef.SetDomain(21151314, 21416785, 3497200, 3895222);
            //spatialRef.SetFalseOriginAndUnits(0, 0, 100000);
            pGeometryDefEdit.SpatialReference_2 = spatialRef;
            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "PlanID", "围填方案号");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "V_Change_Rate", "水道全潮平均流速最大变化率");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "V_Area", "流速变化范围");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Change_Rate", "相邻水道流量变化率");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Silting_Strength", "水道淤积强度");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Ecological_Service_Lost", "生态服务价值损失");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Sewage_Discharge", "污水排放量");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Cultivation_Area", "影像养殖区面积");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Distance", "缩短岸线与深水区的距离");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "V_Variation", "缩短岸线与深水区的距离");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Land_Area", "围填海后形成的陆域面积");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Benifit", "围填海的效益");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Economic_Output", "围填区的经济产出");
            AddSimpleField(pFieldsEdit, esriFieldType.esriFieldTypeString, "Increased_Imployment", "围填区可增加的就业人口");

            ((IFeatureWorkspace)m_workSpace).CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
        }
예제 #51
0
        static void CopyAndLabel(IFeatureClass inFC, IFeatureWorkspace destination, String name)
        {
            IFieldsEdit outFields = new FieldsClass();
            ISpatialReference outSR = null;
            for (int i = 0; i < inFC.Fields.FieldCount; i += 1) {
                IField field = inFC.Fields.get_Field(i);
                if (field.Type == esriFieldType.esriFieldTypeGeometry) {
                    outSR = field.GeometryDef.SpatialReference;
                } else {
                    outFields.AddField(field);
                }
            }
            outSR.SetMDomain(-137434824702, 137434824702);

            IGeometryDefEdit geom = new GeometryDefClass();
            geom.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geom.SpatialReference_2 = outSR;
            geom.HasM_2 = true;
            geom.HasZ_2 = false;

            IFieldEdit geomField = new FieldClass();
            geomField.Name_2 = "SHAPE";
            geomField.AliasName_2 = "SHAPE";
            geomField.Type_2 = esriFieldType.esriFieldTypeGeometry;
            geomField.GeometryDef_2 = geom;
            outFields.AddField(geomField);

            IFeatureClass outFC = destination.CreateFeatureClass(name, outFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            // Start numbering from 1, because index 0 is used by clipping cell
            int vIndex = 1;
            IFeatureCursor featureCursor = inFC.Search(null, true);
            IFeature inFeature;
            while ((inFeature = featureCursor.NextFeature()) != null) {
                IFeature outFeature = outFC.CreateFeature();
                for (int i = 0; i < outFields.FieldCount; i += 1) {
                    IField field = outFields.Field[i];
                    if (field.Editable && (field.Type != esriFieldType.esriFieldTypeGeometry)) {
                        outFeature.set_Value(i, inFeature.get_Value(i));
                    }
                }
                IPolygon4 inShape = inFeature.Shape as IPolygon4;
                PolygonClass outShape = new PolygonClass();

                IGeometryBag extRingBag = inShape.ExteriorRingBag;
                IGeometryCollection extRings = extRingBag as IGeometryCollection;
                for (int i = 0; i < extRings.GeometryCount; i += 1) {
                    IGeometry inExtRingGeom = extRings.get_Geometry(i);
                    IPointCollection inExtRing = inExtRingGeom as IPointCollection;
                    RingClass outExtRing = new RingClass();
                    for (int j = 0; j < inExtRing.PointCount; j += 1) {
                        IPoint point = inExtRing.get_Point(j);
                        point.M = vIndex;
                        vIndex += 2;
                        outExtRing.AddPoint(point);
                    }
                    outShape.AddGeometry(outExtRing);
                    IGeometryBag intRingBag = inShape.get_InteriorRingBag(inExtRingGeom as IRing);
                    IGeometryCollection intRings = intRingBag as IGeometryCollection;
                    for (int j = 0; j < intRings.GeometryCount; j += 1) {
                        IGeometry intRingGeom = intRings.get_Geometry(j);
                        IPointCollection inIntRing = intRingGeom as IPointCollection;
                        RingClass outIntRing = new RingClass();
                        for (int k = 0; k < inIntRing.PointCount; k += 1) {
                            IPoint point = inExtRing.get_Point(k);
                            point.M = vIndex;
                            vIndex += 2;
                            outIntRing.AddPoint(point);
                        }
                        outShape.AddGeometry(outIntRing);
                    }
                }
                outFeature.Shape = outShape;
                outFeature.Store();
            }
        }
예제 #52
0
        private IFeatureClass CreatNewShapefile(string Path, string Name, ISpatialReference sref)
        {
            IWorkspaceFactory2 workspaceFactory;
            workspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace featureWorkspace;
            featureWorkspace = workspaceFactory.OpenFromFile(Path, 0) as IFeatureWorkspace;

            IFields fields;
            fields = new FieldsClass();
            IFieldsEdit fieldsEdit;
            fieldsEdit = fields as IFieldsEdit;

            IField field;
            IFieldEdit fieldEdit;

            field = new FieldClass();
            fieldEdit = field as IFieldEdit;
            fieldEdit.Name_2 = "Shape";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef geometryDef;
            geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit;
            geometryDefEdit = geometryDef as IGeometryDefEdit;
            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            //geometryDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass() as ISpatialReference;
            geometryDefEdit.SpatialReference_2 = sref;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            fieldEdit = field as IFieldEdit;
            fieldEdit.Name_2 = "Text";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldEdit.Length_2 = 25;
            fieldsEdit.AddField(field);

            IFeatureClass featureClass;
            featureClass = featureWorkspace.CreateFeatureClass(Name, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            return featureClass;
        }
        /// <summary>
        /// 储存凸包shp,聚类号在"index"字段中标注
        /// </summary>
        public void CreatePolygonShapefile()
        {
            string filePath = m_dataInfo.GetOutputFilePath();
            string fileName = m_dataInfo.GetOutputFileName();
            ISpatialReference spatialReference = m_dataInfo.GetSpatialReference();

            //打开工作空间
            const string strShapeFieldName = "shape";
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(filePath, 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.esriGeometryPolygon;
            pGeoDefEdit.SpatialReference_2 = spatialReference;

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

            pField = new FieldClass();
            pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "index";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            pFieldEdit.Precision_2 = 7;//数值精度
            pFieldsEdit.AddField(pField);

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

            //在featureclass中创建feature
            IWorkspaceEdit workspaceEdit = pWS as IWorkspaceEdit;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            IFeatureClass featureClass = pWS.OpenFeatureClass(fileName);
            IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
            IFeatureCursor featureCursor = featureClass.Search(null, true);
            IFeature feature = featureCursor.NextFeature();
            while (feature != null)
            {
                feature.Delete();
                feature = featureCursor.NextFeature();
            }
            featureCursor = featureClass.Insert(true);
            int typeFieldIndex = featureClass.FindField("index");
            for (int i = 0; i < m_clusters.GetClusterCount(); i++)
            {
                Cluster currentCluster = m_clusters.GetCluster(i);
                IPolygon currentPolygon = currentCluster.GetConvexHull();
                //we know that there are IPoints only in the Geometrycollection.
                //But this is the safe and recommended way
                if (currentPolygon != null)
                {
                    featureBuffer.set_Value(typeFieldIndex, currentCluster.GetClusterIndex());
                    featureBuffer.Shape = currentPolygon as IGeometry;
                    object featureOID = featureCursor.InsertFeature(featureBuffer);
                }
            }
            featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

            //将新创建的shapfile作为图层添加到map里
            IFeatureLayer featureLayer = new FeatureLayerClass();
            featureLayer.FeatureClass = featureClass;
            featureLayer.Name = featureClass.AliasName;

            m_polygonLayer = featureLayer;

            /*
            //提前设置渲染
            DefinePolygonUniqueValueRenderer(featureLayer as IGeoFeatureLayer, "ClusterIndex");
            m_mapControl.AddLayer(featureLayer as ILayer);
            this.m_mapControl.Refresh();
             */
        }
예제 #54
0
        public IFields createReferencePointFields(string ReferenceFieldName, string OriginalLineIDFieldName, ISpatialReference pSpatRef)
        {
            //Create field object and set number of fields
              IFields pFields = new FieldsClass();
              IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
              pFieldsEdit.FieldCount_2 = 4;

              //Create objectID field
              IField pField = new FieldClass();
              IFieldEdit pFieldEdit = pField as IFieldEdit;
              pFieldEdit.Name_2 = "OBJECTID";
              pFieldEdit.Type_2= esriFieldType.esriFieldTypeOID;
              pFieldsEdit.set_Field(0,pField);

              //Create Shape field
              pField = new FieldClass();
              pFieldEdit = pField as IFieldEdit;
              pFieldEdit.Name_2 = "SHAPE";
              pFieldEdit.Type_2= esriFieldType.esriFieldTypeGeometry;

              IGeometryDef pGeomDef = new GeometryDefClass();
              IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;
              pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
              pGeomDefEdit.SpatialReference_2 = pSpatRef;
              pGeomDefEdit.HasZ_2 = true;
              pFieldEdit.GeometryDef_2 = pGeomDef;
              pFieldsEdit.set_Field(1, pField);

              //Create reference id field
              pField = new FieldClass();
              pFieldEdit = pField as IFieldEdit;
              pFieldEdit.Name_2 = ReferenceFieldName;
              pFieldEdit.Type_2= esriFieldType.esriFieldTypeInteger;
              pFieldsEdit.set_Field(2,pField);

              //Create reference id field
              pField = new FieldClass();
              pFieldEdit = pField as IFieldEdit;
              pFieldEdit.Name_2 = OriginalLineIDFieldName;
              pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
              pFieldsEdit.set_Field(3, pField);

              return pFields;
        }
예제 #55
0
        private void confirmbutton_Click(object sender, EventArgs e)
        {
            List<List<double>> param = new List<List<double>>();
            List<List<double>> newparam = new List<List<double>>();
            if (openfilepath != null && savefilepath != null)
            {
                try
                {
                    //动态数组按行读取txt文档
                    System.IO.FileStream  file = new System.IO.FileStream(openfilepath, FileMode.Open);
                    StreamReader sr = new StreamReader(file);
                    string strLine0 = sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string[] line = sr.ReadLine().Split(' ');
                        string imgname = line[0].Substring(4, line[0].Length - 8);
                        List<double> item = new List<double>();
                        item.Add(double.Parse(imgname));
                        item.Add(double.Parse(line[1]));
                        item.Add(double.Parse(line[2]));
                        item.Add(double.Parse(line[3]));
                        item.Add(double.Parse(line[4]));
                        item.Add(double.Parse(line[5]));
                        item.Add(double.Parse(line[6]));
                        param.Add(item);
                    }
                    sr.Close();
                    sr.Dispose();
                    file.Close();
                    file.Dispose();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("请选择文件!");
            }
            if (FdisBox.Text != "" && cxBox.Text != "" && cyBox.Text != "" && param != null)
            {
                for (int i = 0; i < param.Count; i++)
                {
                    scale = param[i][3] / double.Parse(FdisBox.Text) * 1000;
                    double w = double.Parse(cxBox.Text) / 2000 * scale;
                    double h = double.Parse(cyBox.Text) / 2000 * scale;
                    double x = param[i][1];
                    double y = param[i][2];

                    //三维旋转矩阵
                    var mb = Matrix<double>.Build;
                    var vb = Vector<double>.Build;
                    var pi = Math.PI;

                    var omega = param[i][4] * pi / 180;
                    var phi = param[i][5] * pi / 180;
                    var kappa = param[i][6] * pi / 180; ;
                    var a1 = Math.Cos(phi) * Math.Cos(kappa);
                    var a2 = -Math.Cos(phi) * Math.Sin(kappa);
                    var a3 = -Math.Sin(phi);
                    var b1 = Math.Cos(omega) * Math.Sin(kappa) - Math.Sin(omega) * Math.Sin(phi) * Math.Cos(kappa);
                    var b2 = Math.Cos(omega) * Math.Cos(kappa) + Math.Sin(omega) * Math.Sin(phi) * Math.Sin(kappa);
                    var b3 = -Math.Sin(omega) * Math.Cos(phi);
                    var c1 = Math.Sin(omega) * Math.Sin(kappa) + Math.Cos(omega) * Math.Sin(phi) * Math.Cos(kappa);
                    var c2 = Math.Sin(omega) * Math.Cos(kappa) - Math.Cos(omega) * Math.Sin(phi) * Math.Sin(kappa);
                    var c3 = Math.Cos(omega) * Math.Cos(phi);
                    var matrix = mb.DenseOfArray(new[,] { { a1, a2, a3 }, { b1, b2, b3 }, { c1, c2, c3 } });

                    //点向量
                    var vector1 = vb.Dense(new[] { -w, -h, 0 });
                    var vector2 = vb.Dense(new[] { w, -h, 0 });
                    var vector3 = vb.Dense(new[] { w, h, 0 });
                    var vector4 = vb.Dense(new[] { -w, h, 0 });

                    //矩阵运算
                    var resultv1 = matrix * vector1;
                    var resultv2 = matrix * vector2;
                    var resultv3 = matrix * vector3;
                    var resultv4 = matrix * vector4;
                    double x1 = resultv1[0] + x;
                    double y1 = resultv1[1] + y;
                    double x2 = resultv2[0] + x;
                    double y2 = resultv2[1] + y;
                    double x3 = resultv3[0] + x;
                    double y3 = resultv3[1] + y;
                    double x4 = resultv4[0] + x;
                    double y4 = resultv4[1] + y;

                    List<double> item = new List<double>();
                    item.Add(param[i][0]);
                    item.Add(param[i][1]);
                    item.Add(param[i][2]);
                    item.Add(param[i][3]);
                    item.Add(param[i][4]);
                    item.Add(param[i][5]);
                    item.Add(param[i][6]);
                    item.Add(x1);
                    item.Add(y1);
                    item.Add(x2);
                    item.Add(y2);
                    item.Add(x3);
                    item.Add(y3);
                    item.Add(x4);
                    item.Add(y4);
                    newparam.Add(item);

                }

                ////按行写入text文档
                //FileStream cfile = new FileStream(closefilepath, FileMode.Open);
                //StreamWriter sw = new StreamWriter(cfile);
                //sw.WriteLine("x y z omega phi kappa x1 y1 x2 y2 x3 y3 x4 y4");
                //if (newparam != null)
                //{
                //    for (var i = 0; i < newparam.Count; i++)
                //    {
                //        string wstr = "IMG_" + newparam[i][0] + " " + newparam[i][1] + " " + newparam[i][2] + " " + newparam[i][3] + " " + newparam[i][4] + " " +
                //            newparam[i][5] + " " + newparam[i][6] + " " + newparam[i][7] + " " + newparam[i][8] + " " + newparam[i][9] + " " + newparam[i][10] +
                //            " " + newparam[i][11] + " " + newparam[i][12] + " " + newparam[i][13] + " " + newparam[i][14];
                //        sw.WriteLine(wstr);
                //    }
                //}
                //sw.Close();
                //sw.Dispose();
                //cfile.Close();
                //cfile.Dispose();

                //shp文件存储
                int index = 0;
                index = savefilepath.LastIndexOf("\\");
                string filePath = savefilepath.Substring(0, index);
                string fileName = savefilepath.Substring(index + 1, savefilepath.Length - index - 1);
                Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                System.Object obj = Activator.CreateInstance(factoryType);
                ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;
                ISpatialReference spatialReference = spatialReferenceFactory.CreateSpatialReference(4490);

                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(filePath, 0);
                //检查文件是否存在
                if (System.IO.File.Exists(savefilepath))
                {
                    //if (MessageBox.Show("该文件夹下已经有同名面文件,替换原文件?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    //{
                    //    //IFeatureWorkspace FWS = pWSF.OpenFromFile(filePath, 0) as IFeatureWorkspace;
                    //    IFeatureClass pFeatureClass = pFWS.OpenFeatureClass(fileName);
                    //    IDataset pDataset = pFeatureClass as IDataset;
                    //    pDataset.Delete();
                    //}
                    //else
                    //    return;

                    IFeatureClass pFeatureClass = pFWS.OpenFeatureClass(fileName);
                    IDataset pDataset = pFeatureClass as IDataset;
                    pDataset.Delete();
                }

                //创建shp
                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit;
                pFieldsEdit = (IFieldsEdit)pFields;

                //shape字段是要素类必需的字段
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef pGeometryDef = new GeometryDefClass();
                IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //添加shape字段
                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "img_number";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "center_x";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "center_y";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.AddField(pField);

                IFeatureClass pFClass;
                pFClass = pFWS.CreateFeatureClass(fileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //点状shape文件
                int pindex = 0;
                pindex = savepointpath.LastIndexOf("\\");
                string pfilePath = savepointpath.Substring(0, pindex);
                string pfileName = savepointpath.Substring(pindex + 1, savepointpath.Length - pindex - 1);

                IWorkspaceFactory ppWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace ppFWS = (IFeatureWorkspace)ppWSF.OpenFromFile(pfilePath, 0);
                //检查文件是否存在
                if (System.IO.File.Exists(savepointpath))
                {
                    IFeatureClass ppFeatureClass = ppFWS.OpenFeatureClass(pfileName);
                    IDataset ppDataset = ppFeatureClass as IDataset;
                    ppDataset.Delete();
                }
                //创建shp
                IFields ppFields = new FieldsClass();
                IFieldsEdit ppFieldsEdit;
                ppFieldsEdit = (IFieldsEdit)ppFields;

                //shape字段是要素类必需的字段
                IField ppField = new FieldClass();
                IFieldEdit ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Name_2 = "Shape";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef ppGeometryDef = new GeometryDefClass();
                IGeometryDefEdit ppGDefEdit = (IGeometryDefEdit)ppGeometryDef;
                ppGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                ppFieldEdit.GeometryDef_2 = ppGeometryDef;
                ppFieldsEdit.AddField(ppField);

                //添加shape字段
                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "number";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                ppFieldsEdit.AddField(ppField);

                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "x";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                ppFieldsEdit.AddField(ppField);

                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "y";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                ppFieldsEdit.AddField(ppField);

                IFeatureClass ppFClass;
                ppFClass = ppFWS.CreateFeatureClass(pfileName, ppFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                for (int i = 0; i < newparam.Count; i++)
                {
                    string imgnumber = "IMG_" + newparam[i][0];
                    double x = newparam[i][1];
                    double y = newparam[i][2];
                    double x1 = newparam[i][7];
                    double y1 = newparam[i][8];
                    double x2 = newparam[i][9];
                    double y2 = newparam[i][10];
                    double x3 = newparam[i][11];
                    double y3 = newparam[i][12];
                    double x4 = newparam[i][13];
                    double y4 = newparam[i][14];

                    //画面
                    IPoint pPoint;
                    //IElement pm = new PolygonElementClass();
                    IPointCollection pPoints=new PolygonClass();
                    object missing = Type.Missing;

                    pPoint = new PointClass();
                    pPoint.PutCoords(x1, y1);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x4, y4);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x3, y3);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x2, y2);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x1, y1);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    IFeature pFeature = pFClass.CreateFeature();
                    pFeature.Shape = pPoints as IPolygon;
                    pFeature.Store();

                    pFeature.set_Value(pFeature.Fields.FindField("img_number"), imgnumber);
                    pFeature.set_Value(pFeature.Fields.FindField("center_x"), x);
                    pFeature.set_Value(pFeature.Fields.FindField("center_y"), y);
                    pFeature.Store();

                    //画点
                   // IElement ppm = new MarkerElement();
                    pPoint = new PointClass();
                    pPoint.PutCoords(x, y);
                    pPoint.SpatialReference = spatialReference;
                    IFeature ppFeature = ppFClass.CreateFeature();
                    ppFeature.Shape = pPoint;
                    ppFeature.Store();

                    ppFeature.set_Value(ppFeature.Fields.FindField("number"), imgnumber);
                    ppFeature.set_Value(ppFeature.Fields.FindField("x"), x);
                    ppFeature.set_Value(ppFeature.Fields.FindField("y"), y);
                    ppFeature.Store();
                }
                IFeatureLayer pFeaturelayer = new FeatureLayerClass();
                pFeaturelayer.FeatureClass = pFClass;
                pFeaturelayer.Name = fileName;
                pFeaturelayer.SpatialReference = spatialReference;
                pmap.SpatialReference = spatialReference;
                pmap.AddLayer(pFeaturelayer);

                IFeatureLayer ppFeaturelayer = new FeatureLayerClass();
                ppFeaturelayer.FeatureClass = ppFClass;
                ppFeaturelayer.Name = pfileName;
                ppFeaturelayer.SpatialReference = spatialReference;
                pmap.AddLayer(ppFeaturelayer);

              // this.Close();

            }
            else
            {
                MessageBox.Show("请输入相关参数!");
                return;
            }
        }
예제 #56
0
        /// <summary>
        /// Creates the field collection for a new feature class or standalone table.
        /// </summary>
        /// <param name="bSpatial">True if the new fields collection is for a feature class, false if a table.</param>
        /// <param name="bHasZ">True if the geometry field of the fields collection to be created is to be Z aware.</param>
        /// <param name="bHasM">True if the geometry field of the fields collection to be created is to be M aware.</param>
        /// <param name="oWorkspace">The workspace in which a new feature class will be created from the fields collection.</param>
        /// <param name="geomType">The geometry type of the feature class to be created from the new fields collection.</param>
        /// <param name="aFldLengths">An array of field lengths of the fields collection to be created.</param>
        /// <param name="aFldNames">An array of field names of the fields collection to be created.</param>
        /// <param name="aFldAliases">An array of field aliases of the fields collection to be created.</param>
        /// <param name="aFldTypes">An array of field types of the fields collection to be created.</param>
        /// <param name="spatialReference">The coordinate system to be assigned to the new feature class.</param>
        /// <returns>Returns the new field collection. Throws an error if no field collection can be created.</returns>
        private IFields CreateFieldsCollection(bool hasGeom, bool hasZ, bool hasM, object outWorkspace,
            esriGeometryType geometryType, int[] fieldLengths, string[] fieldNames, string[] fieldAliases,
            esriFieldType[] fieldTypes, bool[] fieldNullable, ISpatialReference spatialReference)
        {
            if ((hasGeom) && (outWorkspace is IWorkspace) && (spatialReference == null))
                throw new Exception("Spatial reference must be defined for standalone feature classes");

            IWorkspace outputWorkspace = null;
            if (outWorkspace is IWorkspace)
            {
                outputWorkspace = outWorkspace as IWorkspace;
            }
            else if (outWorkspace is IFeatureDataset)
            {
                outputWorkspace = ((IDataset)((IFeatureDataset)outWorkspace)).Workspace;
            }

            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
            if (hasGeom)
            {
                IGeometryDef geometryDef = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2 = geometryType;
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, 0); // (0, 0.5);
                geometryDefEdit.AvgNumPoints_2 = 2;
                geometryDefEdit.HasM_2 = hasM;
                geometryDefEdit.HasZ_2 = hasZ;
                if (outWorkspace is IWorkspace) geometryDefEdit.SpatialReference_2 = spatialReference;
                IField fieldOID = new FieldClass();
                IFieldEdit fieldEditOID = (IFieldEdit)fieldOID;
                fieldEditOID.Name_2 = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldOID);
                IField fieldShape = new FieldClass();
                IFieldEdit fieldEditShape = (IFieldEdit)fieldShape;
                fieldEditShape.Name_2 = "SHAPE";
                fieldEditShape.AliasName_2 = "SHAPE";
                fieldEditShape.Type_2 = esriFieldType.esriFieldTypeGeometry;
                fieldEditShape.GeometryDef_2 = geometryDef;
                fieldsEdit.AddField(fieldShape);
            }
            else
            {
                IField fieldOID = new FieldClass();
                IFieldEdit fieldEditOID = (IFieldEdit)fieldOID;
                fieldEditOID.Name_2 = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldOID);
            }

            if (fieldAliases == null) fieldAliases = fieldNames;

            IField fieldAtt;
            IFieldEdit fieldEditAtt;
            for (int i = 0; i < fieldTypes.Length; i++)
            {
                if (String.IsNullOrEmpty(fieldNames[i]))
                    throw new Exception(String.Format("Error creating field {0}", i));
                if ((fieldTypes[i] == esriFieldType.esriFieldTypeOID) ||
                    (fieldTypes[i] == esriFieldType.esriFieldTypeGeometry))
                    continue;
                fieldAtt = new FieldClass();
                fieldEditAtt = (IFieldEdit)fieldAtt;
                fieldEditAtt.Name_2 = fieldNames[i];
                if (!String.IsNullOrEmpty(fieldAliases[i]))
                    fieldEditAtt.AliasName_2 = fieldAliases[i];
                fieldEditAtt.Type_2 = fieldTypes[i];
                fieldEditAtt.Editable_2 = true;
                fieldEditAtt.Required_2 = false;
                fieldEditAtt.IsNullable_2 = fieldNullable[i];// true;
                if (fieldTypes[i] == esriFieldType.esriFieldTypeString)
                {
                    //if ((fieldLengths[i] == -1) || ((fieldLengths[i] > 0) && (fieldLengths[i] < 256)))
                    fieldEditAtt.Length_2 = fieldLengths[i];
                    //else
                    //    fieldEditAtt.Length_2 = 255;
                }
                fieldsEdit.AddField(fieldAtt);
            }
            IFieldChecker fldChk = new FieldCheckerClass();
            fldChk.ValidateWorkspace = outputWorkspace;

            IFields outFields;
            IEnumFieldError fieldErrors;
            fldChk.Validate(fields, out fieldErrors, out outFields);
            return outFields;
        }
예제 #57
0
        //求六度重叠
        //路径
        private void instersectfilebutton_Click(object sender, EventArgs e)
        {
            //保存面状图层
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Shape文件(*.shp)|*.shp";
            saveFileDialog.Title = "新建面状shp文件";
            saveFileDialog.CheckFileExists = false;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string instfilepath = saveFileDialog.FileName;
                instpathBox.Text = instfilepath;

                //已存在文件判断覆盖
                int pindex = 0;
                pindex = instfilepath.LastIndexOf("\\");
                string pfilePath = instfilepath.Substring(0, pindex);
                string instfileName = instfilepath.Substring(pindex + 1, instfilepath.Length - pindex - 1);

                IWorkspaceFactory pfWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pfFWS = (IFeatureWorkspace)pfWSF.OpenFromFile(pfilePath, 0);
                if (System.IO.File.Exists(instfilepath))
                {
                    IFeatureClass ppFeatureClass = pfFWS.OpenFeatureClass(instfileName);
                    IDataset ppDataset = ppFeatureClass as IDataset;
                    ppDataset.Delete();
                }
                //创建shp
                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit;
                pFieldsEdit = (IFieldsEdit)pFields;

                //shape字段是要素类必需的字段
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef pGeometryDef = new GeometryDefClass();
                IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //添加shape字段
                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "fis_number";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);

                pfFClass = pfFWS.CreateFeatureClass(instfileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            }
            else
            {
                MessageBox.Show("请输入图层保存路径!");
            }
        }
예제 #58
0
        public static void CreateFClassInPDB(string filePath)
        {
            string shapeFieldName = "shape";
            IFeatureWorkspace pFWS;
            try
            {
                pFWS = openPDB(filePath);
                //IEnumDataset pDatasets;
                //pDatasets=pWS.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                IFeatureDataset pFeatureDataset = pFWS.OpenFeatureDataset("Water");
                //MessageBox.Show(pFeatureDataset.Name);
                //	IDataset pDataset=pDatasets.Next();
                //	IFeatureDataset pFeatureDataset=pDataset as IFeatureDataset;
                IGeoDataset pGeoDataset = pFeatureDataset as IGeoDataset;
                IFields pFields = null;
                IFieldsEdit pFieldsEdit = null;
                pFields = new FieldsClass();
                pFieldsEdit = pFields as IFieldsEdit;
                pFieldsEdit.FieldCount_2 = 2;
                IField pField = null;
                IFieldEdit pFieldEdit = null;
                //Make the shape field it will need a geometry definition, with a spatial reference
                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Name_2 = shapeFieldName;
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef pGeomDef = null;
                IGeometryDefEdit pGeomDefEdit = null;
                pGeomDef = new GeometryDefClass();
                pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeomDefEdit.SpatialReference_2 = pGeoDataset.SpatialReference;//get the spatial reference
                pFieldEdit.GeometryDef_2 = pGeomDefEdit;
                //pFieldsEdit.AddField(pField);
                pFieldsEdit.set_Field(0, pField);
                //Add another miscellaneous text field
                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "TextField";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                //pFieldsEdit.AddField(pField);
                pFieldsEdit.set_Field(1, pField);

                //pFeatureDataset.CreateFeatureClass("test",pFields,null,null,esriFeatureType.esriFTSimple,"Shape","");
                UID pUID;
                pUID = new UIDClass();
                pUID.Value = "esriGeoDatabase.Feature";

                //pFeatureDataset.CreateFeatureClass("test",pFields,pUID,null,esriFeatureType.esriFTSimple,"Shape","");
                pFeatureDataset.CreateFeatureClass("test", pFields, pUID, null, esriFeatureType.esriFTSimple, "Shape", "");

                MessageBox.Show("�����ɹ�");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);

            }
        }
예제 #59
0
        /// <summary>
        /// ����shapeͼ��
        /// </summary>
        /// <param name="strShpPath"></param>
        /// <param name="strFtName"></param>
        /// <returns></returns>
        private IFeatureClass CreateShpFile(string strShpPath, string strFtName, string strAliasFtName, ISpatialReference pSpatial)
        {
            string connectionstring = "DATABASE=" + strShpPath;
            IWorkspaceFactory2 pFactory = (IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
            IWorkspace workspace = pFactory.OpenFromString(connectionstring, 0);
            IFeatureWorkspace ipFtWs = (IFeatureWorkspace)workspace;

            //�����ֶ�IFields
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
            ///�������������ֶ�
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            ////����FID�ֶ�
            //IFieldEdit ipFldEdit = new FieldClass(); //(__uuidof(Field));
            //ipFldEdit.Name_2 = "FID";
            //ipFldEdit.AliasName_2 = "Ψһ��־��";
            //ipFldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            //pFieldsEdit.AddField(ipFldEdit);

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.AliasName_2 = "��������";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef pGeomDef = new GeometryDefClass();
            IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;
            pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            pGeomDefEdit.SpatialReference_2 = pSpatial;
            pFieldEdit.GeometryDef_2 = pGeomDef;
            pFieldsEdit.AddField(pField);

            IFeatureClass _featureClass =
                ipFtWs.CreateFeatureClass(strFtName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            //����ͼ�����
            //IClassSchemaEdit ipEdit = (IClassSchemaEdit)_featureClass;
            //ipEdit.AlterAliasName(strAliasFtName);

            pFactory = null;
            workspace = null;
            ipFtWs = null;

            return _featureClass;
        }
예제 #60
0
        //
        //
        //
        public static void createShapeFile(String folderName, String shapeName)
        {
            if (folderName == "" || shapeName == "") return;
            string shapeFieldName = "shape";
            try
            {
                IFeatureWorkspace pFWS = null;
                IWorkspaceFactory pWorkspaceFactory = null;
                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                //if(pWorkspaceFactory.IsWorkspace(folderName)==false) return;
                pFWS = pWorkspaceFactory.OpenFromFile(folderName, 0) as IFeatureWorkspace;
                IFields pFields = null;
                IFieldsEdit pFieldsEdit = null;
                pFields = new FieldsClass();
                pFieldsEdit = pFields as IFieldsEdit;
                IField pField = null;
                IFieldEdit pFieldEdit = null;
                //Make the shape field it will need a geometry definition, with a spatial reference
                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Name_2 = shapeFieldName;
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef pGeomDef = null;
                IGeometryDefEdit pGeomDefEdit = null;
                pGeomDef = new GeometryDefClass();
                pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();
                pFieldEdit.GeometryDef_2 = pGeomDefEdit;
                pFieldsEdit.AddField(pField);
                //Add another miscellaneous text field
                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "TextField";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);

                IFeatureClass pFeatClass = null;
                pFeatClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, shapeFieldName, "");
                MessageBox.Show("��Ϊ" + shapeName + "��shape�ļ������ɹ�");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);

            }
        }