public void Excute() { IPolygon tempLine = SketchToolAssist.TempLine as IPolygon; IInvalidArea invalidAreaClass = new InvalidArea() { Display = (_context.FocusMap as IActiveView).ScreenDisplay }; invalidAreaClass.Add(tempLine); tempLine.SimplifyPreserveFromTo(); IEnumFeature featureSelection = _context.FocusMap.FeatureSelection as IEnumFeature; featureSelection.Reset(); IFeature feature = featureSelection.Next(); if (feature != null) { IPolygon shapeCopy = feature.ShapeCopy as IPolygon; if (!(shapeCopy as IRelationalOperator).Disjoint(tempLine)) { IGeometry geometry = (shapeCopy as ITopologicalOperator).Difference(tempLine); if (!geometry.IsEmpty) { invalidAreaClass.Add(feature); Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(geometry, shapeCopy); Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); try { feature.Shape = geometry; feature.Store(); IGeometry geometry1 = (shapeCopy as ITopologicalOperator).Difference(geometry); if (!geometry1.IsEmpty) { Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(geometry1, shapeCopy); IFeature feature1 = RowOperator.CreatRowByRow(feature as Row) as IFeature; feature1.Shape = geometry1; feature1.Store(); } } catch (Exception exception) { CErrorLog.writeErrorLog(this, exception, ""); } Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); _context.UpdateUI(); } } } invalidAreaClass.Invalidate(-2); }
/// <summary> /// 刷新修改要素 /// </summary> /// <params name="pObject"></params> private void RefreshModifyFeature(IObject pObject) { IInvalidArea pRefreshArea; pRefreshArea = new InvalidArea(); pRefreshArea.Display = m_hookHelper.ActiveView.ScreenDisplay; pRefreshArea.Add(pObject); pRefreshArea.Invalidate(-2); }
public void Excute() { IGeometry shapeCopy = this.pFeature.ShapeCopy; IGeometryServer2 geometryServer = new GeometryServerImpl() as IGeometryServer2; IInvalidArea invalidArea = new InvalidArea(); invalidArea.Display = (_context.FocusMap as IActiveView).ScreenDisplay; invalidArea.Add(SketchToolAssist.TempLine); IGeometry geometry = geometryServer.Reshape(shapeCopy.SpatialReference, shapeCopy, SketchToolAssist.TempLine as IPolyline); if (geometry != null && !geometry.IsEmpty) { Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); this.pFeature.Shape = geometry; this.pFeature.Store(); Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); invalidArea.Add(this.pFeature); } invalidArea.Invalidate(-2); }
/// <summary> /// ˢ����Ҫ�� /// </summary> /// <params name="pObject"></params> private void RefreshModifyFeature(IObject pObject) { IInvalidArea pRefreshArea; pRefreshArea =new InvalidArea(); pRefreshArea.Display = m_hookHelper.ActiveView.ScreenDisplay; pRefreshArea.Add(pObject); pRefreshArea.Invalidate(-2); }
/// <summary> /// ˢ����Ҫ�� /// </summary> /// <params name="pObject"></params> private static void RefreshModifyFeature(IObject pObject) { IInvalidArea pRefreshArea; pRefreshArea = new InvalidArea(); pRefreshArea.Display = g_pAxMapControl.ActiveView.ScreenDisplay; pRefreshArea.Add(pObject); pRefreshArea.Invalidate(-2); }
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; } }
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.Message.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.Message); } 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; } }