Esempio n. 1
0
        public override void OnMouseDown(int button, int shift, int x, int y)
        {
            if (_feature == null)
            {
                return;
            }
            IPoint       mapPoint         = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            IInvalidArea invalidAreaClass = new InvalidAreaClass()
            {
                Display = (_context.FocusMap as IActiveView).ScreenDisplay
            };

            invalidAreaClass.Add(_feature);
            Yutai.ArcGIS.Common.Editor.Editor.StartEditOperation(_feature.Class as IDataset);
            try
            {
                if (_codeSetting == null)
                {
                    _codeSetting = new FrmCode(_pointFeatureLayer, _gdbhFieldName);
                }
                _codeSetting.Next();
                if (_codeSetting.ShowDialog() == DialogResult.OK)
                {
                    ILineFeatureCalculate pCalculate = new LineFeatureCalculate(_feature, _lineFeatureLayer, _pointFeatureLayer);
                    pCalculate.LineFeatureLayer  = _lineFeatureLayer;
                    pCalculate.PointFeatureLayer = _pointFeatureLayer;
                    pCalculate.LineFeature       = _feature;
                    pCalculate.Point             = mapPoint;
                    pCalculate.IdxDMGCField      = _idxDmgcField;
                    pCalculate.IdxQDMSField      = _idxQdmsField;
                    pCalculate.IdxZDMSField      = _idxZdmsField;
                    double dmgcValue = pCalculate.GetGroundHeightByPoint();
                    double gxmsValue = pCalculate.GetDepthByPoint();
                    ISet   set       = (_feature as IFeatureEdit).Split(mapPoint);
                    set.Reset();

                    IFeature feature = set.Next() as IFeature;
                    if (CommonHelper.IsFromPoint(feature.Shape as IPolyline, mapPoint))
                    {
                        feature.Value[_idxQdbhField] = _codeSetting.Code;
                        feature.Value[_idxQdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxQdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    else
                    {
                        feature.Value[_idxZdbhField] = _codeSetting.Code;
                        feature.Value[_idxZdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxZdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    feature.Store();

                    feature = set.Next() as IFeature;
                    if (CommonHelper.IsFromPoint(feature.Shape as IPolyline, mapPoint))
                    {
                        feature.Value[_idxQdbhField] = _codeSetting.Code;
                        feature.Value[_idxQdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxQdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    else
                    {
                        feature.Value[_idxZdbhField] = _codeSetting.Code;
                        feature.Value[_idxZdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxZdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    feature.Store();


                    IFeature newFeature = _pointFeatureLayer.FeatureClass.CreateFeature();
                    newFeature.Value[_idxGdbhField] = _codeSetting.Code;
                    newFeature.Value[_idxDmgcField] = dmgcValue.ToString("##0.0000");
                    IPoint nearPoint = CommonHelper.GetNearestPoint(feature.Shape as IPolyline, mapPoint);
                    newFeature.Shape = GeometryHelper.CreatePoint(nearPoint.X, nearPoint.Y, nearPoint.Z, nearPoint.M, FeatureClassUtil.CheckHasZ(_pointFeatureLayer.FeatureClass), FeatureClassUtil.CheckHasM(_pointFeatureLayer.FeatureClass));
                    newFeature.Store();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            Yutai.ArcGIS.Common.Editor.Editor.StopEditOperation(_feature.Class as IDataset);
            invalidAreaClass.Invalidate(-2);
            _context.ClearCurrentTool();
            _feature = null;
            _context.ActiveView.Refresh();
        }
Esempio n. 2
0
        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);
            }
        }