private void BuildFeatureListDataSouce() { _treeRecords = new List <TreeRecord>(); if (_lineFeature1 == null) { return; } if (_lineFeature2 == null) { return; } for (int i = 0; i < _lineFeature1.Fields.FieldCount; i++) { IField pField = _lineFeature1.Fields.Field[i]; if (pField.Type == esriFieldType.esriFieldTypeOID || pField.Type == esriFieldType.esriFieldTypeGeometry || pField.Type == esriFieldType.esriFieldTypeRaster || pField.Editable == false) { continue; } TreeRecord pRecord = new TreeRecord(); if (pField.Domain == null) { pRecord = new TreeRecord(false, pField.Type, pField.AliasName, _lineFeature1.Value[i], null, i, -1, _lineFeature2.Value[i], ""); } else { IDomain pDomain = pField.Domain; if (pDomain is CodedValueDomain) { ICodedValueDomain pCodeDomain = pDomain as ICodedValueDomain; if (pCodeDomain == null) { continue; } List <CodeValuePair> pairs = new List <CodeValuePair>(); for (int j = 0; j < pCodeDomain.CodeCount; j++) { CodeValuePair pair = new CodeValuePair { Name = pCodeDomain.Name[j], Value = pCodeDomain.Value[j] }; pairs.Add(pair); } pRecord = new TreeRecord(true, pField.Type, pField.AliasName, _lineFeature1.Value[i], pairs, i, -1, _lineFeature2.Value[i], ""); } else { IRangeDomain pRangeDomain = pDomain as IRangeDomain; } } _treeRecords.Add(pRecord); } }
private void btnDetele_Click(object sender, EventArgs e) { try { if (_lineFeature1 == null) { return; } if (_lineFeature2 == null) { return; } IPolyline firstPolyline = _lineFeature1.Shape as IPolyline; IPolyline secondPolyline = _lineFeature2.Shape as IPolyline; if (firstPolyline == null) { return; } if (secondPolyline == null) { return; } List <IPoint> points = new List <IPoint>() { firstPolyline.FromPoint, firstPolyline.ToPoint, secondPolyline.FromPoint, secondPolyline.ToPoint }; IPoint startPoint = CommonHelper.GetFarthestPoint(firstPolyline, _linkPoint); IPoint endPoint = CommonHelper.GetFarthestPoint(secondPolyline, _linkPoint); int firstfrompointcount = points.Count(point1 => Math.Abs(firstPolyline.FromPoint.X - point1.X) < 0.01 && Math.Abs(firstPolyline.FromPoint.Y - point1.Y) < 0.01); IFeatureClass pFeatureClass = _featureLayer.FeatureClass; bool hasZ = FeatureClassUtil.CheckHasZ(pFeatureClass); bool hasM = FeatureClassUtil.CheckHasM(pFeatureClass); IFeature pFeature = pFeatureClass.CreateFeature(); startPoint = GeometryHelper.CreatePoint(startPoint.X, startPoint.Y, startPoint.Z, startPoint.M, hasZ, hasM); endPoint = GeometryHelper.CreatePoint(endPoint.X, endPoint.Y, endPoint.Z, endPoint.M, hasZ, hasM); pFeature.Shape = GeometryHelper.CreatePointCollection(startPoint, endPoint, hasZ, hasM) as IPolyline; foreach (TreeRecord treeRecord in _treeRecords) { if (treeRecord.IsDomain) { List <CodeValuePair> pairs = treeRecord.DoaminValue as List <CodeValuePair>; CodeValuePair pair = pairs.FirstOrDefault(p => p.Name == treeRecord.FirstValue.ToString()); pFeature.Value[treeRecord.FieldId] = pair == null ? null : pair.Value; } pFeature.Value[treeRecord.FieldId] = treeRecord.MergeValue; } pFeature.Store(); _featureoid = pFeature.OID; this.DialogResult = DialogResult.OK; } catch (Exception exception) { MessageBox.Show(exception.Message); } }