コード例 #1
0
        //获得管线的属性字段和信息
        private void GetWaterLineValue(out string var1, out string var2, out string var3, out string var4, out string var5)
        {
            IFields pFields = pFeatureWaterLine.Fields;

            var1 = pFeatureWaterLine.get_Value(pFields.FindField("WATER_ID")).ToString();
            var2 = pFeatureWaterLine.get_Value(pFields.FindField("PIPEUSE_CODE")).ToString();
            var3 = pFeatureWaterLine.get_Value(pFields.FindField("SHAPE_LENGTH")).ToString();
            var4 = pFeatureWaterLine.get_Value(pFields.FindField("PWDIAM")).ToString();
            var5 = pFeatureWaterLine.get_Value(pFields.FindField("PWMATERIAL")).ToString();
            //根据子类型代码获得子类型名称
            ISubtypes    pWaterLineSubtypes = pFeatLayerWaterLines.FeatureClass as ISubtypes;
            IRowSubtypes pRowSubtypes       = pFeatureWaterLine as IRowSubtypes;

            if (pRowSubtypes != null)
            {
                var2 = pWaterLineSubtypes.get_SubtypeName(pRowSubtypes.SubtypeCode);
                //获取属性域
                IDomain pDomain = pWaterLineSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWMATERIAL");
                if (pDomain != null)
                {
                    ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain;
                    for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++)
                    {
                        if (pCodedValDomain.get_Value(i) == var5)
                        {
                            var5 = pCodedValDomain.get_Name(i);
                        }
                    }
                }
            }
        }
コード例 #2
0
        //IFeatureClass CreateFeature Example
        private IFeature IFeatureClass_Create(IFeatureClass featureClass, IGeometry pGeometry)
        {
            if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
            {
                return(null);
            }
            IWorkspaceEdit iWE = (featureClass as IDataset).Workspace as IWorkspaceEdit;

            if (!iWE.IsBeingEdited())
            {
                iWE.StartEditing(false);
            }

            IFeature feature = featureClass.CreateFeature();

            //Apply the constructed shape to the new features shape
            feature.Shape = pGeometry;
            ISubtypes    subtypes    = (ISubtypes)featureClass;
            IRowSubtypes rowSubtypes = (IRowSubtypes)feature;

            if (subtypes.HasSubtype)         // does the feature class have subtypes?
            {
                rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype
            }
            // initalize any default values that the feature has
            rowSubtypes.InitDefaultValues();
            //Commit the default values in the feature to the database
            feature.Store();
            iWE.StopEditing(true);
            iWE = null;
            return(feature);
        }
コード例 #3
0
ファイル: NewFeatureClass.cs プロジェクト: sishui198/ArcGis-
        /**
         * 官网示例
         * */
        public void IFeatureClass_CreateFeature_Example(IFeatureClass featureClass)
        {
            //Function is designed to work with polyline data
            if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
            {
                return;
            }
            //create a geometry for the features shape
            ESRI.ArcGIS.Geometry.IPolyline polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
            ESRI.ArcGIS.Geometry.IPoint    point    = new ESRI.ArcGIS.Geometry.PointClass();
            point.X            = 0; point.Y = 0;
            polyline.FromPoint = point;
            point   = new ESRI.ArcGIS.Geometry.PointClass();
            point.X = 10; point.Y = 10; polyline.ToPoint = point;
            IFeature feature = featureClass.CreateFeature();

            //Apply the constructed shape to the new features shape
            feature.Shape = polyline;
            ISubtypes    subtypes    = (ISubtypes)featureClass;
            IRowSubtypes rowSubtypes = (IRowSubtypes)feature;

            if (subtypes.HasSubtype)         // does the feature class have subtypes?
            {
                rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype
            }
            // initalize any default values that the feature has
            rowSubtypes.InitDefaultValues();
            //Commit the default values in the feature to the database
            feature.Store();
            //update the value on a string field that indicates who installed the feature.
            feature.set_Value(feature.Fields.FindField("InstalledBy"), "K Johnston");
            //Commit the updated values in the feature to the database
            feature.Store();
        }
コード例 #4
0
        //获得阀门的属性字段和信息
        private void GetValves(IFeature pFeature, out string var1, out string var2, out string var3)
        {
            IFields   pFields          = pFeature.Fields;
            ISubtypes pWaterPtSubtypes = pFeatLayerValves.FeatureClass as ISubtypes;

            var1 = pFeature.get_Value(pFields.FindField("WATER_ID")).ToString();
            var2 = pFeature.get_Value(pFields.FindField("PWV_TYPE")).ToString();
            var3 = pFeature.get_Value(pFields.FindField("PWSHEETNO")).ToString();
            IRowSubtypes pRowSubtypes = pFeature as IRowSubtypes;

            if (pRowSubtypes != null)
            {
                IDomain pDomain = pWaterPtSubtypes.get_Domain(pRowSubtypes.SubtypeCode, "PWV_TYPE");
                if (pDomain != null)
                {
                    ICodedValueDomain pCodedValDomain = pDomain as ICodedValueDomain;
                    for (int i = 0; i <= pCodedValDomain.CodeCount - 1; i++)
                    {
                        if (pCodedValDomain.get_Value(i).ToString() == var2)
                        {
                            var2 = pCodedValDomain.get_Name(i).ToString();
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: CreateFeatureTool.cs プロジェクト: secondii/Yutai
 public static void CreateDimensionFeature(IDimensionShape pDimensionShape, esriDimensionType pDimensionType,
                                           IActiveView pActiveView, IFeatureLayer pFeatureLayer)
 {
     if (pDimensionShape != null)
     {
         IWorkspaceEdit workspace = (IWorkspaceEdit)((IDataset)pFeatureLayer.FeatureClass).Workspace;
         workspace.StartEditOperation();
         IFeature     esriDimensionType0 = pFeatureLayer.FeatureClass.CreateFeature();
         IRowSubtypes rowSubtype         = (IRowSubtypes)esriDimensionType0;
         try
         {
             rowSubtype.InitDefaultValues();
         }
         catch (Exception exception)
         {
             //Logger.Current.Error("",exception, "");
             Logger.Current.Warn(exception.Message);
         }
         (esriDimensionType0 as IDimensionFeature).DimensionType  = pDimensionType;
         (esriDimensionType0 as IDimensionFeature).DimensionShape = pDimensionShape;
         EditorEvent.NewRow(esriDimensionType0);
         esriDimensionType0.Store();
         workspace.StopEditOperation();
         EditorEvent.AfterNewRow(esriDimensionType0);
         pActiveView.FocusMap.ClearSelection();
         pActiveView.FocusMap.SelectFeature(pFeatureLayer, esriDimensionType0);
         pActiveView.Refresh();
     }
 }
コード例 #6
0
ファイル: AddFeature.cs プロジェクト: siszoey/geosufan
        //IFeatureClass CreateFeature Example
        private IFeature IFeatureClass_Create(IFeatureClass featureClass, IGeometry pGeometry)
        {
            IWorkspaceEdit iWE = (featureClass as IDataset).Workspace as IWorkspaceEdit;

            if (!iWE.IsBeingEdited())
            {
                iWE.StartEditing(false);
            }
            iWE.StartEditOperation();
            IFeature feature = featureClass.CreateFeature();

            //Apply the constructed shape to the new features shape
            feature.Shape = pGeometry;
            //如果不是shp 则初始化子类型
            if ((featureClass as IDataset).Workspace.WorkspaceFactory.WorkspaceType != esriWorkspaceType.esriFileSystemWorkspace)
            {
                ISubtypes    subtypes    = (ISubtypes)featureClass;
                IRowSubtypes rowSubtypes = (IRowSubtypes)feature;
                if (subtypes.HasSubtype)         // does the feature class have subtypes?
                {
                    rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype
                }
                // initalize any default values that the feature has
                rowSubtypes.InitDefaultValues();
                //Commit the default values in the feature to the database
            }
            feature.Store();
            iWE.StopEditOperation();
            //iWE.StopEditing(true);
            iWE = null;
            return(feature);
        }
コード例 #7
0
ファイル: TableExtensions.cs プロジェクト: wey12138/Wave
        /// <summary>
        ///     Creates a row in the table with the default values.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>
        ///     Returns a <see cref="IRow" /> representing the new row.
        /// </returns>
        public static IRow CreateNew(this ITable source)
        {
            if (source == null)
            {
                return(null);
            }

            var          row         = source.CreateRow();
            IRowSubtypes rowSubtypes = row as IRowSubtypes;

            if (rowSubtypes != null)
            {
                rowSubtypes.InitDefaultValues();
            }

            return(row);
        }
コード例 #8
0
ファイル: ClassExtensions.cs プロジェクト: wey12138/Wave
        /// <summary>
        ///     Creates a feature in the table with the default values.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>
        ///     Returns a <see cref="IFeature" /> representing the new feature.
        /// </returns>
        public static IFeature CreateNew(this IFeatureClass source)
        {
            if (source == null)
            {
                return(null);
            }

            var          row         = source.CreateFeature();
            IRowSubtypes rowSubtypes = row as IRowSubtypes;

            if (rowSubtypes != null)
            {
                rowSubtypes.InitDefaultValues();
            }

            return(row);
        }
コード例 #9
0
        /// <summary>
        /// 获取距离鼠标点击最近的点
        /// </summary>
        public void CreateFeature(IFeatureClass featureClass, IPointCollection PointCollection)
        {
            //是否为点图层
            if (featureClass.ShapeType != esriGeometryType.esriGeometryPoint)
            {
                return;
            }

            for (int i = 0; i < PointCollection.PointCount; i++)
            {
                IFeature feature = featureClass.CreateFeature();

                feature.Shape = PointCollection.get_Point(i);
                IRowSubtypes rowSubtypes = (IRowSubtypes)feature;
                feature.Store();
            }
        }
コード例 #10
0
        /// <summary>
        ///     Gets the domain that is assigned to the field.
        /// </summary>
        /// <param name="source">The row.</param>
        /// <param name="index">The index.</param>
        /// <returns>
        ///     Returns a <see cref="IDomain" /> representing the domain for the field.
        /// </returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        public static IDomain GetDomain(this IRow source, int index)
        {
            if (source == null)
            {
                return(null);
            }
            if (index < 0 || index > source.Fields.FieldCount - 1)
            {
                throw new IndexOutOfRangeException();
            }

            ISubtypes subtypes = (ISubtypes)source.Table;

            if (subtypes.HasSubtype)
            {
                string       fieldName   = source.Fields.Field[index].Name;
                IRowSubtypes rowSubtypes = (IRowSubtypes)source;
                return(subtypes.Domain[rowSubtypes.SubtypeCode, fieldName]);
            }

            return(source.Fields.Field[index].Domain);
        }
コード例 #11
0
ファイル: CmdFollowAlong.cs プロジェクト: secondii/Yutai
 public void CreateFeature(IGeometry igeometry_0)
 {
     try
     {
         if (igeometry_0 != null)
         {
             IFeatureLayer  featureLayer  = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer;
             IDataset       dataset       = (IDataset)featureLayer.FeatureClass;
             IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace;
             int            index         = featureLayer.FeatureClass.FindField(featureLayer.FeatureClass.ShapeFieldName);
             IGeometryDef   geometryDef   = featureLayer.FeatureClass.Fields.get_Field(index).GeometryDef;
             if (geometryDef.HasZ)
             {
                 IZAware iZAware = (IZAware)igeometry_0;
                 iZAware.ZAware = true;
                 IZ     iZ = (IZ)igeometry_0;
                 double constantZ;
                 double num;
                 geometryDef.SpatialReference.GetZDomain(out constantZ, out num);
                 iZ.SetConstantZ(constantZ);
             }
             if (geometryDef.HasM)
             {
                 IMAware iMAware = (IMAware)igeometry_0;
                 iMAware.MAware = true;
             }
             workspaceEdit.StartEditOperation();
             IFeature feature = featureLayer.FeatureClass.CreateFeature();
             if (igeometry_0 is ITopologicalOperator)
             {
                 (igeometry_0 as ITopologicalOperator).Simplify();
             }
             feature.Shape = igeometry_0;
             try
             {
                 IRowSubtypes rowSubtypes = (IRowSubtypes)feature;
                 rowSubtypes.InitDefaultValues();
             }
             catch (Exception exception_)
             {
                 CErrorLog.writeErrorLog(this, exception_, "");
             }
             feature.Store();
             workspaceEdit.StopEditOperation();
             EditorEvent.AddFeature(featureLayer, feature);
             IActiveView activeView = (IActiveView)_context.FocusMap;
             _context.FocusMap.ClearSelection();
             _context.FocusMap.SelectFeature(featureLayer, feature);
             if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPoint)
             {
                 double distance = Common.ConvertPixelsToMapUnits((IActiveView)_context.FocusMap, 30.0);
                 ITopologicalOperator topologicalOperator = (ITopologicalOperator)igeometry_0;
                 topologicalOperator.Buffer(distance);
                 activeView.Refresh();
             }
             else
             {
                 activeView.Refresh();
             }
         }
     }
     catch (COMException ex)
     {
         if (ex.ErrorCode == -2147220936)
         {
             System.Windows.Forms.MessageBox.Show("坐标值或量测值超出范围!", "创建要素",
                                                  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
     }
 }
コード例 #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IFeature  pAttributeFeature = default(IFeature);
            ISubtypes pSubtypes         = default(ISubtypes);
            ArrayList colAttributes     = null;
            IFeature  pCurFeature       = default(IFeature);

            IFeature pNewFeature = default(IFeature);


            IGeometry             pCurGeom      = default(IGeometry);
            IGeometry             pTmpGeom      = default(IGeometry);
            ITopologicalOperator5 pTopoOperator = default(ITopologicalOperator5);
            IRowSubtypes          pOutRSType    = default(IRowSubtypes);
            IFields             pFlds           = default(IFields);
            IField              pFld            = default(IField);
            IDomain             pDomain         = default(IDomain);
            IGeometryCollection pGeomColl       = default(IGeometryCollection);

            IInvalidArea        pRefresh = null;
            IComplexEdgeFeature pCEF     = null;
            IMap pMap = null;

            try
            {
                long lGTotalVal = 0;


                int    lSubTypeCode = 0;
                string strOID       = null;
                int    intOID       = -1;

                int i, j;

                //Screen.MousePointer = vbHourglass

                //The Next button doesn't get enabled until at least 1 FC is selected, but just in case...
                if (lstMergeFeatures.Items.Count == 0)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("SlctOneFtr"));
                    return;
                }

                //For Next loop which iterates through the array populating colSelClasses
                //This is for when I implement selecting multiple feature classes from the listbox....
                for (i = 0; i <= lstMergeFeatures.Items.Count - 1; i++)
                {
                    if (lstMergeFeatures.Items[i].Selected)
                    {
                        strOID = lstMergeFeatures.Items[i].Text;
                        intOID = Convert.ToInt32(strOID);
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

                if (strOID == null)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("SlctMainFtr"));
                    return;
                }

                //Get the field values of the selected feature for use later
                pAttributeFeature = (IFeature)m_colFeatures[strOID];



                colAttributes = new ArrayList();
                for (i = 0; i < pAttributeFeature.Fields.FieldCount; i++)
                {
                    colAttributes.Add(pAttributeFeature.get_Value(i).ToString());
                }

                pSubtypes = (ISubtypes)m_FeatLay.FeatureClass;
                if (pSubtypes.HasSubtype)
                {
                    lSubTypeCode = (int)pAttributeFeature.get_Value(pSubtypes.SubtypeFieldIndex);
                }
                else
                {
                    lSubTypeCode = 0;
                }

                //If the features being merged and the target layer are the same FC and if that FC has subtypes, get the subtype code of the selected feature or target layer
                //If not, get the default
                //pSubtypes = m_pFC;
                //if pSubtypes.HasSubtype Then
                //  lSubTypeCode = m_lSubtype
                //End If

                //start edit operation
                m_editor.StartOperation();

                //pEnumFeature = m_pEditor.EditSelection
                //pEnumFeature.Reset

                //create a new feature to be the merge feature
                //pNFC = m_pFC                             'QI
                //Create the new feature
                pNewFeature = m_FeatLay.FeatureClass.CreateFeature();


                //create the new geometry.
                //initialize the default values for the new feature
                pOutRSType = (IRowSubtypes)pNewFeature;    //Set the RowSubtypes to the NewFeature
                //if (lSubTypeCode <> 0 )
                pOutRSType.SubtypeCode = lSubTypeCode;     //If there's a subtype code, set it
                //End If
                pOutRSType.InitDefaultValues();            //Init the Default values for the feature


                pFlds = m_FeatLay.FeatureClass.Fields;
                //Loop until we've gone through all the selected features (pCurFeature)
                i = 0;
                IList <MergeSplitFlds> pFldsNames = new List <MergeSplitFlds>();
                if (m_Config != null)
                {
                    if (m_Config.Count > 0)
                    {
                        if (m_Config[0] != null)
                        {
                            if (m_Config[0].Fields != null)
                            {
                                foreach (A4LGSharedFunctions.Field FldNam in m_Config[0].Fields)
                                {
                                    int idx = Globals.GetFieldIndex(pFlds, FldNam.Name);
                                    if (idx > -1)
                                    {
                                        try
                                        {
                                            pFldsNames.Add(new MergeSplitFlds(FldNam.Name, idx, "", FldNam.MergeRule, FldNam.SplitRule));
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }
                    }
                }
                foreach (string ky in m_colFeatures.Keys)
                {
                    //}

                    //for (i = 0; i < m_colFeatures.Count; i++)
                    //{

                    pCurFeature = (IFeature)m_colFeatures[ky];
                    if (pFldsNames != null)
                    {
                        foreach (MergeSplitFlds FldNam in pFldsNames)
                        {
                            string testVal = pCurFeature.get_Value(FldNam.FieldIndex).ToString();
                            //if (Globals.IsNumeric(testVal))
                            //{
                            //    FldNam.Value = FldNam.Value + Convert.ToDouble(testVal);
                            //}

                            switch (FldNam.MergeType.ToUpper())
                            {
                            case "MAX":
                                if (FldNam.Value == "")
                                {
                                    FldNam.Value = testVal;
                                }
                                else
                                {
                                    if (Convert.ToDouble(FldNam.Value) < Convert.ToDouble(testVal))
                                    {
                                        FldNam.Value = testVal;
                                    }
                                }

                                break;

                            case "MIN":
                                if (FldNam.Value == "")
                                {
                                    FldNam.Value = testVal;
                                }
                                else
                                {
                                    if (Convert.ToDouble(FldNam.Value) > Convert.ToDouble(testVal))
                                    {
                                        FldNam.Value = testVal;
                                    }
                                }
                                break;

                            case "SUM":
                                if (FldNam.Value == "")
                                {
                                    FldNam.Value = testVal;
                                }
                                else
                                {
                                    FldNam.Value += Convert.ToDouble(FldNam.Value) + Convert.ToDouble(testVal);
                                }

                                break;

                            case "AVERAGE":
                                if (FldNam.Value == "")
                                {
                                    FldNam.Value = testVal;
                                }
                                else
                                {
                                    FldNam.Value += Convert.ToDouble(FldNam.Value) + Convert.ToDouble(testVal);
                                }
                                FldNam.AvgCount++;
                                break;

                            case "CONCAT":
                                if (FldNam.Value.Contains(testVal.ToString() + ConcatDelim))
                                {
                                }
                                else if (FldNam.Value.Contains(ConcatDelim + testVal.ToString()))
                                {
                                }
                                else
                                {
                                    if (FldNam.Value == "")
                                    {
                                        FldNam.Value = testVal.ToString();
                                    }
                                    else
                                    {
                                        FldNam.Value += ConcatDelim + testVal.ToString();
                                    }
                                }

                                break;

                            default:

                                break;
                            }
                        }
                    }
                    //get the geometry of the current feature, if it's the first feature, set it to pTmpGeom
                    //Otherwise, pTmpGeom is already set so Union the Geom of this feature with pTmpGeom
                    //And set that equal to the new pTmpGeom......
                    pCurGeom = pCurFeature.ShapeCopy;
                    if (i == 0)
                    {
                        pTmpGeom      = pCurGeom;
                        pTopoOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator5)pTmpGeom;
                        pTopoOperator.IsKnownSimple_2 = false; //051710
                        pTopoOperator.Simplify();              // 051710
                    }
                    else
                    {
                        //Simplify the just obtained OtherPolyLine
                        pTopoOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator5)pCurGeom;//051710
                        pTopoOperator.IsKnownSimple_2 = false;
                        pTopoOperator.Simplify();

                        //Reset the pTopoOp to pNewPolyLine in prep for the union
                        pTopoOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator5)pTmpGeom;
                        pTmpGeom      = pTopoOperator.Union(pCurGeom);

                        //Simplify the resulting New Line
                        pTopoOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator5)pTmpGeom;
                        pTopoOperator.IsKnownSimple_2 = false;
                        pTopoOperator.Simplify();
                        //pTopoOperator = (ITopologicalOperator5)pTmpGeom;
                        //pTopoOperator.Simplify();
                        //pOutputGeometry = pTopoOperator.Union(pCurGeom);
                        //pTopoOperator.Simplify();
                        //pTmpGeom = pOutputGeometry;

                        //pTopoOperator.SimplifyAsFeature();
                        //pOutputGeometry = pTopoOperator.UnionEx(pCurGeom,true);
                        //pTopoOperator.SimplifyAsFeature();
                        //pTmpGeom = pOutputGeometry;


                        //pTopoOperator.Simplify();
                        //pOutputGeometry = pTopoOperator.Union(pCurGeom);
                        //pTmpGeom = pOutputGeometry;
                    }



                    //now go through each field, if it has a domain associated with it, then evaluate the merge policy...
                    //If not domain, then grab the value from the selected feature

                    for (j = 0; j < pFlds.FieldCount; j++)
                    {
                        pFld    = pFlds.get_Field(j);
                        pDomain = pSubtypes.get_Domain(lSubTypeCode, pFld.Name);
                        if (pDomain != null && pFld.DefaultValue != null)
                        {
                            if (pDomain.MergePolicy == esriMergePolicyType.esriMPTSumValues)
                            {
                                //if (lCount == 1)
                                //    pNewFeature.set_Value(j, pCurFeature.get_Value(j));
                                //else
                                if (pNewFeature.get_Value(j) != null && pCurFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()) && Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (double)pNewFeature.get_Value(j) + (double)pCurFeature.get_Value(j));
                                    }

                                    else if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (double)pNewFeature.get_Value(j));
                                    }
                                    else if (Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (double)pCurFeature.get_Value(j));
                                    }
                                }
                                else if (pNewFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (double)pNewFeature.get_Value(j));
                                    }
                                }
                                else if (pCurFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (double)pCurFeature.get_Value(j));
                                    }
                                }
                                else
                                {
                                }
                            }
                            else if (pDomain.MergePolicy == esriMergePolicyType.esriMPTAreaWeighted)
                            {
                                if (pNewFeature.get_Value(j) != null && pCurFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()) && Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (Double)pNewFeature.get_Value(j) + ((Double)pCurFeature.get_Value(j) * (Globals.GetGeometryLength(pCurFeature) / lGTotalVal)));
                                    }

                                    else if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (Double)pNewFeature.get_Value(j) * (Globals.GetGeometryLength(pCurFeature) / lGTotalVal));
                                    }
                                    else if (Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (Double)pCurFeature.get_Value(j) * (Globals.GetGeometryLength(pCurFeature) / lGTotalVal));
                                    }
                                }
                                else if (pNewFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pNewFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (Double)pNewFeature.get_Value(j) * (Globals.GetGeometryLength(pCurFeature) / lGTotalVal));
                                    }
                                }
                                else if (pCurFeature.get_Value(j) != null)
                                {
                                    if (Globals.IsNumeric(pCurFeature.get_Value(j).ToString()))
                                    {
                                        pNewFeature.set_Value(j, (Double)pCurFeature.get_Value(j) * (Globals.GetGeometryLength(pCurFeature) / lGTotalVal));
                                    }
                                }
                                else
                                {
                                }
                            }
                            else if (pCurFeature.OID == pAttributeFeature.OID)
                            {
                                try
                                {
                                    pNewFeature.set_Value(j, pCurFeature.get_Value(j));
                                }
                                catch
                                { }
                            }
                        }
                        else
                        if (pCurFeature.OID == intOID)
                        {
                            //Set the field values from the selected feature; ignore Subtype, non-editable and Shape field

                            if (pFld.Editable == true && pSubtypes.SubtypeFieldIndex != j && m_FeatLay.FeatureClass.ShapeFieldName.ToUpper() != pFld.Name.ToUpper())
                            {
                                //if (colAttributes[j] != null)
                                //{
                                try
                                {
                                    pNewFeature.set_Value(j, colAttributes[j]);
                                }
                                catch { }

                                // }
                            }
                        }
                    }
                    pCurFeature.Delete(); //delete the feature
                    i++;
                }
                //Check if the merged geometry is multi-part. If so, raise an error and abort
                //Multipart geometries are not supported in the geometric network.
                pGeomColl = (IGeometryCollection)pTmpGeom;

                if (pGeomColl.GeometryCount > 1)
                {
                    m_editor.AbortOperation();
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("SlctOneFtr"), A4LGSharedFunctions.Localizer.GetString("ErrorOn") + A4LGSharedFunctions.Localizer.GetString("MergeOprt_4"));
                    this.Close();
                    return;
                }
                pNewFeature.Shape = pTmpGeom;
                pNewFeature.Store();



                if (m_FeatLay.FeatureClass.FeatureType == esriFeatureType.esriFTComplexEdge)
                {
                    pCEF = (IComplexEdgeFeature)pNewFeature;
                    pCEF.ConnectAtIntermediateVertices();
                }

                if (chkMergeElevationData.Checked)
                {
                    if (pFldsNames != null)
                    {
                        foreach (MergeSplitFlds FldNam in pFldsNames)
                        {
                            if (FldNam.MergeType.ToUpper() == "Average".ToUpper())
                            {
                                FldNam.Value = (Convert.ToDouble(FldNam.Value) / FldNam.AvgCount).ToString();
                            }
                            try
                            {
                                pNewFeature.set_Value(FldNam.FieldIndex, FldNam.Value);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                //finish edit operation
                m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("MergeOprt_4"));

                //refresh features

                pRefresh         = new InvalidArea();
                pRefresh.Display = m_editor.Display;
                pRefresh.Add(pNewFeature);
                pRefresh.Invalidate(-2);

                //    'select new feature

                pMap = m_editor.Map;
                pMap.ClearSelection();
                pMap.SelectFeature((ILayer)m_FeatLay, pNewFeature);

                this.Close();
            }
            catch (Exception ex)
            {
                if (ex.ToString().ToString().Contains("Key cannot be null"))
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorOn") + A4LGSharedFunctions.Localizer.GetString("MergeOprt_5") + "\r\n" + A4LGSharedFunctions.Localizer.GetString("MergeOprt_6"));
                }
                else
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorOn") + A4LGSharedFunctions.Localizer.GetString("MergeOprt_5") + "\r\n" + ex.ToString());
                }

                try
                {
                    //finish edit operation
                    m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("MergeOprt_4"));
                }
                catch
                { }
                this.Close();
            }
            finally
            {
                pAttributeFeature = null;
                pSubtypes         = null;
                colAttributes     = null;
                pCurFeature       = null;

                pNewFeature = null;


                pCurGeom      = null;
                pTmpGeom      = null;
                pTopoOperator = null;
                pOutRSType    = null;
                pFlds         = null;
                pFld          = null;
                pDomain       = null;
                pGeomColl     = null;

                pRefresh = null;
                pCEF     = null;
                pMap     = null;
            }
        }
コード例 #13
0
        /// <summary>
        /// Gets a property set of name values converted to string
        /// for a given feature or row.
        /// </summary>
        /// <param name="row">One row feature to descrive</param>
        /// <returns>List</returns>
        public static List <NameValuePair> PropertySet(IRow row)
        {
            String    subtypeFieldName = string.Empty;
            ISubtypes subtypes         = row.Table as ISubtypes;

            List <NameValuePair> result = new List <NameValuePair>();

            IFields fields = row.Fields;
            int     count  = fields.FieldCount;

            // -------------------------------------
            // For each field check the types and
            // do the appropriate thing to convert
            // to a string representation for
            // display purposes.
            //
            // Also need to deal with domain values.
            // --------------------------------------
            for (int idx = 0; idx < count; idx++)
            {
                // get name and alias
                IField  field  = fields.get_Field(idx);
                IDomain domain = field.Domain;
                string  alias  = field.AliasName;
                string  name   = field.Name;
                string  value  = string.Empty;

                // Are we dealing with a subtype field?
                if (subtypes.HasSubtype &&
                    (0 == string.Compare(subtypes.SubtypeFieldName, field.Name, true)))
                {
                    IRowSubtypes rowSubTypes = row as IRowSubtypes;
                    value = subtypes.SubtypeName[rowSubTypes.SubtypeCode];
                }
                else if (domain != null) // field has domain
                {
                    if (domain is ICodedValueDomain)
                    {
                        // If field type is text
                        if (field.Type == esriFieldType.esriFieldTypeString ||
                            field.Type == esriFieldType.esriFieldTypeInteger)
                        {
                            value = GdbUtils.CheckForCodedName(field, row.get_Value(idx));
                        }
                    }
                    else  // Its a range domain (numeric only)
                    {
                        // Can just use value as is
                        value = row.get_Value(idx).ToString();
                    }
                }
                else  // non domain or subtype field, just get string representation
                {
                    value = row.get_Value(idx).ToString();
                }

                NameValuePair item = new NameValuePair(alias, name, value);
                result.Add(item);
            }
            return(result);
        }
コード例 #14
0
        private void miAddItem_Click(object sender, System.EventArgs e)
        {
            //可以双击该项来编辑属性
            //只为新项填充initDefaultValues方法中的默认值和自动生成的名称值。

            IMapControl3 mapControl = (IMapControl3)axMapControl1.Object;

            IEngineNAWindowCategory2 activeCategory = m_naWindow.ActiveCategory as IEngineNAWindowCategory2;
            IDataLayer pDataLayer = activeCategory.DataLayer;
            // 在类中创建一个新行并填充并初始默认值
            ITable       table       = pDataLayer as ITable;
            IRow         row         = table.CreateRow();
            IRowSubtypes rowSubtypes = row as IRowSubtypes;

            rowSubtypes.InitDefaultValues();
            // 自动生成显示名称
            IFeatureLayer    ipFeatureLayer    = activeCategory.Layer as IFeatureLayer;
            IStandaloneTable ipStandaloneTable = pDataLayer as IStandaloneTable;
            string           name = "";

            if (ipFeatureLayer != null)
            {
                name = ipFeatureLayer.DisplayField;
            }
            else if (ipStandaloneTable != null)
            {
                name = ipStandaloneTable.DisplayField;
            }
            //如果显示字段为空字符串或不代表NaClass上的实际字段,则跳过自动生成
            string currentName = "";
            int    fieldIndex  = row.Fields.FindField(name);

            if (fieldIndex >= 0)
            {
                currentName = row.get_Value(fieldIndex) as string;
                if (currentName.Length <= 0)
                {
                    row.set_Value(fieldIndex, "Item" + ++autogenInt);
                }
            }
            INAClassDefinition naClassDef = activeCategory.NAClass.ClassDefinition;

            if (naClassDef.Name == "OrderPairs")
            {
                fieldIndex = row.Fields.FindField("SecondOrderName");
                if (fieldIndex >= 0)
                {
                    string secondName = row.get_Value(fieldIndex) as string;
                    if (secondName.Length <= 0)
                    {
                        row.set_Value(fieldIndex, "Item" + ++autogenInt);
                    }
                }
            }
            row.Store();

            // 向naclass添加项
            INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit;

            contextEdit.ContextChanged();

            // 刷新 NAWindow 和屏幕界面
            INALayer naLayer = m_naWindow.ActiveAnalysis;

            mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent);
            m_naWindow.UpdateContent(m_naWindow.ActiveCategory);
        }
コード例 #15
0
        private void addItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IMapControl3 mapControl = (IMapControl3)axMapControl1.Object;

            IEngineNAWindowCategory2 activeCategory = m_naWindow.ActiveCategory as IEngineNAWindowCategory2;
            IDataLayer pDataLayer = activeCategory.DataLayer;

            // In order to add an item, we need to create a new row in the class and populate it
            // with the initial default values for that class.
            ITable       table       = pDataLayer as ITable;
            IRow         row         = table.CreateRow();
            IRowSubtypes rowSubtypes = row as IRowSubtypes;

            rowSubtypes.InitDefaultValues();

            IFeatureLayer    ipFeatureLayer    = activeCategory.Layer as IFeatureLayer;
            IStandaloneTable ipStandaloneTable = pDataLayer as IStandaloneTable;
            string           name = "";

            if (ipFeatureLayer != null)
            {
                name = ipFeatureLayer.DisplayField;
            }
            else if (ipStandaloneTable != null)
            {
                name = ipStandaloneTable.DisplayField;
            }

            string currentName = "";
            int    fieldIndex  = row.Fields.FindField(name);

            if (fieldIndex >= 0)
            {
                currentName = row.get_Value(fieldIndex) as string;
                if (currentName.Length <= 0)
                {
                    row.set_Value(fieldIndex, "Item" + ++autogenInt);
                }
            }

            INAClassDefinition naClassDef = activeCategory.NAClass.ClassDefinition;

            if (naClassDef.Name == "OrderPairs")
            {
                fieldIndex = row.Fields.FindField("SecondOrderName");
                if (fieldIndex >= 0)
                {
                    string secondName = row.get_Value(fieldIndex) as string;
                    if (secondName.Length <= 0)
                    {
                        row.set_Value(fieldIndex, "Item" + ++autogenInt);
                    }
                }
            }

            row.Store();

            // notify that the context has changed because we have added an item to a NAClass within it
            INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit;

            contextEdit.ContextChanged();

            // refresh the NAWindow and the Screen
            INALayer naLayer = m_naWindow.ActiveAnalysis;

            mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent);
            m_naWindow.UpdateContent(m_naWindow.ActiveCategory);
        }