Пример #1
0
        //构造偏转角度法
        private void button5_Click(object sender, EventArgs e)
        {
            delFeature("point");
            IPoint fromPoint = new PointClass();

            fromPoint.PutCoords(0, 0);
            IPoint toPoint = new PointClass();

            toPoint.PutCoords(1, 1);
            ILine line = new LineClass();

            line.PutCoords(fromPoint, toPoint);
            double          distance          = 1.4142135623731;
            double          angle             = Math.PI / 4;
            IConstructPoint constructionPoint = new PointClass();

            constructionPoint.ConstructDeflection(line, distance, angle);
            IPoint point = constructionPoint as IPoint;

            addFeature("point", fromPoint);
            addFeature("point", toPoint);
            addFeature("point", point);
            axMapControl1.Refresh();
        }
Пример #2
0
        public override void OnMouseDown(int button, int shift, int x, int y)
        {
            if (button != 1)
            {
                return;
            }

            if (_context.Config.EngineSnapEnvironment.SnapToleranceUnits ==
                esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels)
            {
                _tolerance = ArcGIS.Common.Helpers.CommonHelper.ConvertPixelsToMapUnits(_context.ActiveView,
                                                                                        _tolerance);
            }
            this.SelectByClick(x, y);
            IEnumFeature enumFeature = _context.FocusMap.FeatureSelection as IEnumFeature;
            IFeature     feature     = enumFeature.Next();

            if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                _pointFeature = feature;
            }
            if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                _lineFeature = feature;
            }
            if (_pointFeature == null || _lineFeature == null)
            {
                return;
            }
            this.SelectByShape(_pointFeature.Shape);
            enumFeature = _context.FocusMap.FeatureSelection as IEnumFeature;
            enumFeature.Reset();
            List <IFeature> linkFeatures = new List <IFeature>();
            IFeature        lineFeature;

            while ((lineFeature = enumFeature.Next()) != null)
            {
                IPolyline polyline = lineFeature.Shape as IPolyline;
                if (polyline == null)
                {
                    continue;
                }
                linkFeatures.Add(lineFeature);
            }
            if (linkFeatures.Count <= 0)
            {
                return;
            }
            _linkFeature = linkFeatures[0];
            if (_linkFeature == null || _linkFeature.Shape.GeometryType != esriGeometryType.esriGeometryPolyline)
            {
                return;
            }
            _context.FocusMap.SelectFeature(_pointFeatureLayer, _pointFeature);
            _context.FocusMap.SelectFeature(_lineFeatureLayer, _lineFeature);
            _context.FocusMap.SelectFeature(_lineFeatureLayer, _linkFeature);
            try
            {
                IPoint datumPoint = GeometryHelper.GetIntersectPoint(_lineFeature.Shape as IPolyline,
                                                                     _linkFeature.Shape as IPolyline);
                double angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0;
                ILine  line1 = new LineClass();

                line1.PutCoords(datumPoint, GeometryHelper.GetAnotherPoint(_lineFeature.Shape as IPolyline, datumPoint));
                angle1 = line1.Angle;
                ILine line2 = new LineClass();
                line2.PutCoords(datumPoint, _pointFeature.Shape as IPoint);
                angle2 = line2.Angle;

                angle3 = angle2 - angle1;
                if ((angle3 > 0 && angle3 < Math.PI) || angle3 < (0 - Math.PI))
                {
                    angle4 = Math.PI / 2;
                }
                else
                {
                    angle4 = Math.PI * 1.5;
                }
                if (MessageBox.Show($@"要素:{_linkFeature.OID},将旋转{angle4:0.0000},是否继续?", @"提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    IConstructPoint constructPoint = new PointClass();
                    constructPoint.ConstructDeflection(line1, line2.Length, angle4);
                    IPoint point = constructPoint as IPoint;

                    CommonHelper.MovePointWithLine(_pointFeature, new List <IFeature>()
                    {
                        _linkFeature
                    }, point, _tolerance);
                    _context.ActiveView.Refresh();
                    _linkFeature  = null;
                    _lineFeature  = null;
                    _pointFeature = null;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }