当前位置: 首页>>代码示例>>C#>>正文


C# FieldsClass类代码示例

本文整理汇总了C#中FieldsClass的典型用法代码示例。如果您正苦于以下问题:C# FieldsClass类的具体用法?C# FieldsClass怎么用?C# FieldsClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FieldsClass类属于命名空间,在下文中一共展示了FieldsClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InMemoryWorkspaceFactoryClass

        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;
        }
开发者ID:hijushen,项目名称:WindowDemo,代码行数:100,代码来源:MainForm.cs

示例2: CreatePolylineFeatureClass

        /// <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;
        }
开发者ID:Esri,项目名称:distance-direction-addin-dotnet,代码行数:33,代码来源:FeatureClassUtils.cs

示例3: CreateFClassInPDB

        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;
            }
        }
开发者ID:chinasio,项目名称:minegis,代码行数:30,代码来源:GDBData.cs

示例4: CreatePointLayer

        /// <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();
            }
        }
开发者ID:chinasio,项目名称:minegis,代码行数:35,代码来源:CreateLayer.cs

示例5: CreateFeatureClass

        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", "");
        }
开发者ID:NGFieldScope,项目名称:Geoprocessing,代码行数:25,代码来源:Program.cs

示例6: CreateFeatureClass

        //http://resources.esri.com/help/9.3/arcgisengine/arcobjects/esriGeoDatabase/IFeatureWorkspace.CreateFeatureClass_Example.htm
        static IFeatureClass CreateFeatureClass(string name, IFeatureWorkspace ftrSpc, esriGeometryType type, int epsg, List<dynamic> extraFields)
        {
            IFeatureClass ftrc = null;
            if(null != ftrSpc && null != name)
            {
                IFieldsEdit flds = new FieldsClass();
                flds.FieldCount_2 = 2 + (extraFields == null ? 0 : extraFields.Count);

                IFieldEdit fld = new FieldClass();
                fld.Name_2 = OBJECT_ID;
                fld.Type_2 = esriFieldType.esriFieldTypeOID;
                flds.Field_2[0] = fld;

                fld = new FieldClass();
                fld.Name_2 = SHP_NAME;
                fld.Type_2 = esriFieldType.esriFieldTypeGeometry;
                fld.GeometryDef_2 = CreateGeometryDef(type, epsg);
                flds.Field_2[1] = fld;
                int eidx = 2;
                foreach(var efld in extraFields)
                {
                    fld = new FieldClass();
                    fld.Name_2 = efld.Name;
                    fld.Type_2 = efld.Type;
                    flds.Field_2[eidx++] = fld;
                }
                ftrc = ftrSpc.CreateFeatureClass(name, flds, null, null, esriFeatureType.esriFTSimple, SHP_NAME, null);
            }
            return ftrc;
        }
开发者ID:hellocomrade,项目名称:ArcObject,代码行数:31,代码来源:Program.cs

示例7: CreateFeatureClassOutput

        /// <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);
        }
开发者ID:nicogis,项目名称:Voronoi,代码行数:64,代码来源:Program.cs

示例8: CreateFields

        public static IFields CreateFields(TableInfo tInfo)
        {
            if (tInfo == null || tInfo.FieldsInfo == null || tInfo.FieldsInfo.Count == 0)
                return null;

            IFieldsEdit fields=new FieldsClass();
            foreach (FieldInfo fInfo in tInfo.FieldsInfo)
            {
                fields.AddField(CreateField(fInfo));
            }
            return fields;
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:12,代码来源:StandardHelper.cs

示例9: CreatePointFile

        public IFeatureClass CreatePointFile(String strFolder, String filename, IEnvelope pEnvBorder, ISpatialReference pSR)
        {
            // Open the folder to contain the shapefile as a workspace
            IWorkspaceFactory pWF = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pfws = (IFeatureWorkspace)pWF.OpenFromFile(strFolder, 0);

            //Set up a simple fields collection
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            // Make the shape field
            //it will need a geometry definition, with a spatial reference

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

            IGeometryDef pGeomDef = new GeometryDef();
            IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;

            pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

            pGeomDefEdit.SpatialReference_2 = pSR;

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

            // Add ID field
            IField pFieldOID = new Field();
            pFieldEdit = (IFieldEdit)pFieldOID;
            pFieldEdit.Name_2 = "OBJECTID";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            pFieldEdit.IsNullable_2 = false;

            pFieldsEdit.AddField(pFieldOID);

            if (File.Exists(strFolder + filename + ".shp") == true)
            {
                DialogResult result = MessageBox.Show("There is a shapefile have the same name in this foler, do you want to overwrite it?", "", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    File.Delete(strFolder + filename);

                }
                else
                {
                    return null;
                }
            }
            IFeatureClass pFeatclass = pfws.CreateFeatureClass(filename, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            return pFeatclass;
        }
开发者ID:afocusman,项目名称:PRSS_programYM,代码行数:53,代码来源:CCCreatePolygonFile.cs

示例10: CreateFeatureClass

        public static IFeatureClass CreateFeatureClass(fulcrumform form, string pathToGeoDB)
        {
            try
            {
                ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                ISpatialReference sr = geographicCoordinateSystem;

                IWorkspaceFactory2 wsf = new FileGDBWorkspaceFactoryClass();
                IWorkspace2 workspace = (IWorkspace2)wsf.OpenFromFile(pathToGeoDB, 0);
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                string fcName = GetUniqueFeatureClassName(form.name, workspace);

                IFields fieldsCollection = new FieldsClass();
                IFieldEdit newField = fieldsCollection as IFieldEdit;

                IFeatureClassDescription fcDesc = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

                IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
                // create required fields using the required fields method
                IFields fields = ocDesc.RequiredFields;

                //Grab the GeometryDef from the shape field, edit it and give it back
                int shapeFieldIndex = fields.FindField(fcDesc.ShapeFieldName);
                IField shapeField = fields.get_Field(shapeFieldIndex);
                IGeometryDef geomDef = shapeField.GeometryDef;
                IGeometryDefEdit geomDefEdit = (IGeometryDefEdit)geomDef;
                geomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                geomDefEdit.GridCount_2 = 1;
                geomDefEdit.set_GridSize(0, 0);
                geomDefEdit.SpatialReference_2 = sr;

                IFields newFields = CreateNewFields(form, fields, sr);

                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass
                    (fcName, newFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");

                return featureClass;
            }
            catch (Exception e)
            {
                string errMsg = e.Message;
                return null;
            }
        }
开发者ID:brightrain,项目名称:arcgis-fulcrum-add-in,代码行数:46,代码来源:ArcStuff.cs

示例11: CreatePolygonLayer

        /// <summary>
        /// �½���ͼ��
        /// </summary>
        public IFeatureClass CreatePolygonLayer(IPolygon polygon)
        {
            //LocalFilePath = sfdPoint.FileName;
               FilePath = Application.StartupPath + "\\tempSHP";
               FileName = "test";

               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.esriGeometryPolygon;
               pFieldEdit.GeometryDef_2 = pGeometryDef;
               pFieldsEdit.AddField(pField);

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

               IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
               IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(FilePath, 0) as IFeatureWorkspace;
               IFeatureClass feaC = pFeatureWorkspace.CreateFeatureClass(FileName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
               IFeature pFeature = feaC.CreateFeature();
               pFeature.Shape = polygon as IGeometry;
               pFeature.Store();

               IFeatureCursor feaCur = feaC.Search(null, true);
               pFeature = feaCur.NextFeature();
               while (pFeature != null)
               {
               //pFeature.set_Value(2, "181");
               pFeature.Store();
               pFeature = feaCur.NextFeature();
               }

               //m_mapControl.AddShapeFile(FilePath, FileName);
               //m_mapControl.ActiveView.Refresh();
               return feaC;
        }
开发者ID:chinasio,项目名称:minegis,代码行数:48,代码来源:CreateLayerM.cs

示例12: UpdateParameters

        public void UpdateParameters(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager pEnvMgr)
        {
            IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

            IGPParameter targetDatasetParameter = paramvalues.get_Element(out_targetDatasetNumber) as IGPParameter;
            IGPValue targetDatasetGPValue = gpUtilities3.UnpackGPValue(targetDatasetParameter);

            IDEFeatureDataset targetDEFeatureDataset = targetDatasetGPValue as IDEFeatureDataset;

            IGPParameter3 outPointsFeatureClassParameter = null;
            IGPValue outPointsFeatureClass = null;
            string outpointsPath = String.Empty;

            IGPParameter3 outLinesFeatureClassParameter = null;
            IGPValue outLinesFeatureClass = null;
            string outlinesPath = String.Empty;

            IGPParameter3 outPolygonFeatureClassParameter = null;
            IGPValue outPolygonFeatureClass = null;
            string outpolygonsPath = String.Empty;

            if (((IGPValue)targetDEFeatureDataset).GetAsText().Length != 0)
            {
                IDataElement dataElement = targetDEFeatureDataset as IDataElement;
                try
                {
                    gpUtilities3.QualifyOutputDataElement(gpUtilities3.UnpackGPValue(targetDatasetParameter));
                }
                catch
                {
                    return;
                }

                string nameOfPointFeatureClass = dataElement.GetBaseName() + "_osm_pt";
                string nameOfLineFeatureClass = dataElement.GetBaseName() + "_osm_ln";
                string nameOfPolygonFeatureClass = dataElement.GetBaseName() + "_osm_ply";


                try
                {
                    outpointsPath = dataElement.CatalogPath + System.IO.Path.DirectorySeparatorChar + nameOfPointFeatureClass;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
                outPointsFeatureClassParameter = paramvalues.get_Element(out_osmPointsNumber) as IGPParameter3;
                outPointsFeatureClass = gpUtilities3.UnpackGPValue(outPointsFeatureClassParameter);

                outlinesPath = dataElement.CatalogPath + System.IO.Path.DirectorySeparatorChar + nameOfLineFeatureClass;
                outLinesFeatureClassParameter = paramvalues.get_Element(out_osmLinesNumber) as IGPParameter3;
                outLinesFeatureClass = gpUtilities3.UnpackGPValue(outLinesFeatureClassParameter);

                outpolygonsPath = dataElement.CatalogPath + System.IO.Path.DirectorySeparatorChar + nameOfPolygonFeatureClass;
                outPolygonFeatureClassParameter = paramvalues.get_Element(out_osmPolygonsNumber) as IGPParameter3;
                outPolygonFeatureClass = gpUtilities3.UnpackGPValue(outPolygonFeatureClassParameter);
            }


            // TE - 10/20/2014
            if (((IGPParameter)paramvalues.get_Element(in_attributeSelector)).Altered)
            {
                IGPParameter tagCollectionParameter = paramvalues.get_Element(in_attributeSelector) as IGPParameter;
                IGPMultiValue tagCollectionGPValue = gpUtilities3.UnpackGPValue(tagCollectionParameter) as IGPMultiValue;

                IGPCodedValueDomain codedTagDomain = tagCollectionParameter.Domain as IGPCodedValueDomain;

                for (int attributeValueIndex = 0; attributeValueIndex < tagCollectionGPValue.Count; attributeValueIndex++)
                {
                    string valueString = tagCollectionGPValue.get_Value(attributeValueIndex).GetAsText();
                    IGPValue testFieldValue = codedTagDomain.FindValue(valueString);

                    if (testFieldValue == null)
                    {
                        codedTagDomain.AddStringCode(valueString, valueString);
                    }
                }

                string illegalCharacters = "`[email protected]#$%^&()-+=,{}.![];";
                IFieldsEdit fieldsEdit = new FieldsClass();

                for (int valueIndex = 0; valueIndex < tagCollectionGPValue.Count; valueIndex++)
                {
                    string tagString = tagCollectionGPValue.get_Value(valueIndex).GetAsText();

                    if (tagString != "ALL")
                    {
                        // Check if the input field already exists.
                        string cleanedTagKey = OSMToolHelper.convert2AttributeFieldName(tagString, illegalCharacters);

                        IFieldEdit fieldEdit = new FieldClass();
                        fieldEdit.Name_2 = cleanedTagKey;
                        fieldEdit.AliasName_2 = tagCollectionGPValue.get_Value(valueIndex).GetAsText();
                        fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                        fieldEdit.Length_2 = 100;
                        fieldsEdit.AddField(fieldEdit);
                    }
                }
                IFields fields = fieldsEdit as IFields;

//.........这里部分代码省略.........
开发者ID:leijiancd,项目名称:arcgis-osm-editor,代码行数:101,代码来源:OSMGPFileLoader.cs

示例13: buildZoneClassCount

        private void buildZoneClassCount()
        {
            string cTblName = geoUtil.getSafeOutputNameNonRaster(wks,tblName.Replace("_VAT","_CLASS"));
            if (rd != null) rd.addMessage("Output table name = " + wks.PathName + "\\" + cTblName);

            IFields nflds = new FieldsClass();
            IFieldsEdit nfldsE = (IFieldsEdit)nflds;
            IField nfld = new FieldClass();
            IFieldEdit nfldE = (IFieldEdit)nfld;
            nfldE.Name_2 = "Band";
            nfldE.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfldE);
            IField nfld2 = new FieldClass();
            IFieldEdit nfld2E = (IFieldEdit)nfld2;
            nfld2E.Name_2 = "Zone";
            nfld2E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld2E);
            IField nfld4 = new FieldClass();
            IFieldEdit nfld4E = (IFieldEdit)nfld4;
            nfld4E.Name_2 = "Class";
            nfld4E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld4E);
            IField nfld3 = new FieldClass();
            IFieldEdit nfld3E = (IFieldEdit)nfld3;
            nfld3E.Name_2 = "Count";
            nfld3E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld3E);
            oTbl2 = geoUtil.createTable(wks,cTblName,nflds);
            IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
            if (wksE.IsBeingEdited())
            {
                wksE.StopEditing(true);
            }
            //ITransactions trs = (ITransactions)wks;
            //trs.StartTransaction();
            try
            {
                int bdIndex = oTbl2.FindField("Band");
                int vlIndex = oTbl2.FindField("Zone");
                int cntIndex = oTbl2.FindField("Count");
                int clsIndex = oTbl2.FindField("Class");
                int bndCnt = 1;
                ICursor cur = oTbl2.Insert(true);
                IRowBuffer rw = oTbl2.CreateRowBuffer();
                foreach (Dictionary<double, object[]> zoneValueDicOut in zoneValueDicArr)
                {
                    foreach (KeyValuePair<double, object[]> kVp in zoneValueDicOut)
                    {

                        double key = kVp.Key;
                        object[] vl = kVp.Value;
                        Dictionary<double, int> uDic = (Dictionary<double, int>)vl[5];
                        foreach(KeyValuePair<double,int> uKvp in uDic)
                        {
                            double uDicKey = uKvp.Key;
                            int uDicVl = uKvp.Value;
                            rw.set_Value(bdIndex, bndCnt);
                            rw.set_Value(vlIndex, key);
                            rw.set_Value(cntIndex, uDicVl);
                            rw.set_Value(clsIndex, uDicKey);
                            cur.InsertRow(rw);
                        }
                    }
                    bndCnt += 1;
                }
                cur.Flush();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rw);
                //trs.CommitTransaction();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
                //trs.AbortTransaction();
            }
            finally
            {
            }
        }
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:79,代码来源:zonalHelper.cs

示例14: fillFields

        private void fillFields()
        {
            if (rd != null) rd.addMessage("Output table name = " + wks.PathName + "\\" + tblName);
            //bool weCreate = true;
            //if (!geoUtil.ftrExists(wks, tblName))
            //{
            IFields nflds = new FieldsClass();
            IFieldsEdit nfldsE = (IFieldsEdit)nflds;
            IField nfld = new FieldClass();
            IFieldEdit nfldE = (IFieldEdit)nfld;
            nfldE.Name_2 = "Band";
            nfldE.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfldE);
            IField nfld2 = new FieldClass();
            IFieldEdit nfld2E = (IFieldEdit)nfld2;
            nfld2E.Name_2 = "Zone";
            nfld2E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld2E);
            IField nfld3 = new FieldClass();
            IFieldEdit nfld3E = (IFieldEdit)nfld3;
            nfld3E.Name_2 = "Count";
            nfld3E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld3E);
            oTbl = geoUtil.createTable(wks, tblName, nflds);
            int[] fldIndex = new int[ZoneTypes.Length];
            for (int zIndex=0; zIndex<ZoneTypes.Length;zIndex++)
            {
                string fldNm = ZoneTypes[zIndex].ToString();
                fldNm = geoUtil.createField(oTbl, fldNm, esriFieldType.esriFieldTypeDouble);
                fldIndex[zIndex] = oTbl.FindField(fldNm);
            }
            IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
            if (wksE.IsBeingEdited())
            {
                wksE.StopEditing(true);
            }
            try
            {
                int bdIndex = oTbl.FindField("Band");
                int vlIndex = oTbl.FindField("Zone");
                int cntIndex = oTbl.FindField("Count");
                int bndCnt = 1;
                ICursor cur = oTbl.Insert(true);
                IRowBuffer rw = oTbl.CreateRowBuffer();
                foreach (Dictionary<double, object[]> zoneValueDicOut in zoneValueDicArr)
                {
                    foreach (KeyValuePair<double, object[]> kVp in zoneValueDicOut)
                    {

                        double key = kVp.Key;
                        object[] vl = kVp.Value;
                        Dictionary<rasterUtil.zoneType, double> vDic = getValueDic(vl);

                        //IRow rw = null;
                        //if (!weCreate)
                        //{
                        //    string qry = "Band = " + bndCnt.ToString() + " and Zone = " + key;
                        //    IQueryFilter qf = new QueryFilterClass();
                        //    qf.WhereClause = qry;
                        //    ISelectionSet tblSelectionSet = oTbl.Select(qf, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionOnlyOne, wks);
                        //    if (tblSelectionSet.Count > 0)
                        //    {
                        //        int id = tblSelectionSet.IDs.Next();
                        //        rw = oTbl.GetRow(id);
                        //    }
                        //    else
                        //    {
                        //        rw = oTbl.CreateRow();
                        //    }

                        //}
                        //else
                        //{
                        //rw = oTbl.CreateRow();
                        //}
                        //Console.WriteLine(key.ToString());
                        rw.set_Value(bdIndex, bndCnt);
                        rw.set_Value(vlIndex, key);
                        rw.set_Value(cntIndex, vl[0]);
                        for(int zIndex=0;zIndex<ZoneTypes.Length;zIndex++)// (rasterUtil.zoneType zT in ZoneTypes)
                        {
                            rasterUtil.zoneType zT = ZoneTypes[zIndex];
                            double zVl = vDic[zT];
                            //Console.WriteLine("\t"+fldNm+ ": " + zVl.ToString());
                            rw.set_Value(fldIndex[zIndex], zVl);
                        }
                        //rw.Store();
                        cur.InsertRow(rw);
                    }
                    bndCnt += 1;
                }
                //trs.CommitTransaction();
                cur.Flush();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rw);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                //trs.AbortTransaction();
//.........这里部分代码省略.........
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:101,代码来源:zonalHelper.cs

示例15: CreatePointsShapefile

        /// <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();
        }
开发者ID:huangxy31,项目名称:VagueRegionModelling,代码行数:91,代码来源:SaveShapefile.cs


注:本文中的FieldsClass类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。