Beispiel #1
0
        private void GetSecondPoint()
        {
            INumberDialog numDialog = new NumberDialogClass();

            // Set the second point equal to the active point which may have been snapped
            m_secondPoint = m_activePoint;

            // Get the angle
            if (numDialog.DoModal("Angle 2", -45, 2, m_editor.Display.hWnd))
            {
                m_secondAngle = numDialog.Value * Math.PI / 180;
            }
            else
            {
                m_etoolPhase = ToolPhase.Inactive;
                return;
            }

            // Get the intersection point
            IConstructPoint constructPoint = new PointClass();

            constructPoint.ConstructAngleIntersection(m_firstPoint, m_firstAngle, m_secondPoint, m_secondAngle);

            IPoint point = constructPoint as IPoint;

            if (point.IsEmpty)
            {
                m_etoolPhase = ToolPhase.Inactive;
                MessageBox.Show("No Point Calculated");
                return;
            }

            // Draw the calculated intersection point and erase previous snap feedback
            m_activePoint = point;
            m_etoolPhase  = ToolPhase.Intersection;
            m_snappingFeedback.Update(null, 0);
            DrawPoint(m_activePoint);
        }
Beispiel #2
0
        void MapImage_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (m_ToolPhase == ToolPhase.WaitFirst)
            {
                return;
            }
            //if (DataProvider == null) NoDataProvider();

            //compleate polygon
            if (m_Vertices.Count < 3)
            {
                return;
            }

            m_Vertices.Add(m_Vertices[0]);

            var      linearRing = new LinearRing(m_Vertices);
            Geometry polygon    = new Polygon(linearRing);

            //polygon = GeometryTransform.TransformGeometry(polygon, CoordinateSystems.SphericalMercatorCS,
            //                                                      CoordinateSystems.WGS84);
            m_ToolPhase = ToolPhase.WaitFirst;

            var connectionString = ConnectionManager.DefaultInstance.ConnectionString;
            var connection       = new SqlConnection(connectionString);

            var valid = SqlExecHelper.SqlGeometryValidation(connection, polygon);

            if (!valid)
            {
                MessageForm.Show(Resources.gis_MtIndependentPolygonBufferZone_CheckValidityMsg);
            }
            else
            {
                //show form
                var frm = new PolygonBufZone();
                //frm.ZoneLayer = string.Empty;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (m_TargetLayerGuid == Guid.Empty)
                    {
                        return;
                    }

                    var eidssUserBufZoneLayer =
                        (EidssUserBufZoneLayer)UserDbLayersManager.GetUserLayer(m_TargetLayerGuid);

                    if (eidssUserBufZoneLayer == null)
                    {
                        return;
                    }


                    var userBufZone = new EidssUserBufZoneLayer.UserBufZone
                    {
                        Geometry    = polygon,
                        Description = frm.Description,
                        Name        = frm.ZoneName,
                        //Center = new Point(0, 0)
                    };

                    eidssUserBufZoneLayer.AddNewZone(userBufZone);
                }
            }
            MapImage.Refresh();

            m_Vertices.Clear();
            m_Points.Clear();
            m_LastMousePosition = System.Drawing.Point.Empty;
        }
 private void GetIntersection()
 {
   IEditSketch editSketch = m_editor as IEditSketch;
   editSketch.AddPoint(m_activePoint, true);
   // Set the phase to inactive, back to beginning
   m_etoolPhase = ToolPhase.Inactive;
 }
    private void GetSecondPoint()
    {
      INumberDialog numDialog = new NumberDialogClass();
      // Set the second point equal to the active point which may have been snapped 
      m_secondPoint = m_activePoint;

      // Get the angle
      if (numDialog.DoModal("Angle 2", -45, 2, m_editor.Display.hWnd))
      {
        m_secondAngle = numDialog.Value * Math.PI / 180;
      }
      else
      {
        m_etoolPhase = ToolPhase.Inactive;
        return;
      }

      // Get the intersection point
      IConstructPoint constructPoint = new PointClass();
      constructPoint.ConstructAngleIntersection(m_firstPoint, m_firstAngle, m_secondPoint, m_secondAngle);

      IPoint point = constructPoint as IPoint;
      if (point.IsEmpty)
      {
        m_etoolPhase = ToolPhase.Inactive;
        MessageBox.Show("No Point Calculated");
        return;
      }

      // Draw the calculated intersection point and erase previous snap feedback
      m_activePoint = point;
      m_etoolPhase = ToolPhase.Intersection;
      m_snappingFeedback.Update(null, 0);
      DrawPoint(m_activePoint);
    }
 private void GetFirstPoint()
 {
   INumberDialog numDialog = new NumberDialogClass();
   // Set first point to the active point which may have been snapped
   m_firstPoint = m_activePoint;
   // Get the angle
   if (numDialog.DoModal("Angle 1", 45, 2, m_editor.Display.hWnd))
   {
     m_firstAngle = numDialog.Value * Math.PI / 180;
     m_etoolPhase = ToolPhase.SecondPoint;
   }
 }
 public void OnKeyDown(int keyState, int shift)
 {
   // If the escape key is used, throw away the calculated point 
   if (keyState == (int)Keys.Escape)
     m_etoolPhase = ToolPhase.Inactive;
 }
    public void Initialize(IEditor pEditor)
    {
      // Initialize the constructor
      m_editor = pEditor as IEditor;
      m_edSketch = pEditor as IEditSketch3;

      //Get the snap environment
      m_snappingEnv = m_editor.Parent.FindExtensionByName("ESRI Snapping") as ISnappingEnvironment;
      m_snapper = m_snappingEnv.PointSnapper;
      m_snappingFeedback = new SnappingFeedbackClass();
      m_snappingFeedback.Initialize(m_editor.Parent, m_snappingEnv, true);

      m_firstPoint = new PointClass();
      m_secondPoint = new PointClass();
      m_activePoint = new PointClass();

      // Set the phase to inactive so we start at the beginning 
      m_etoolPhase = ToolPhase.Inactive;
    }
        private void CutSelectedPolygon()
        {
            if (m_selectedFeature == null)
            {
                MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                m_toolPhase = ToolPhase.SelectFeature;
                return;
            }

            //在屏幕上绘制用于分割的线要素
            IScreenDisplay    screenDisplay = m_activeView.ScreenDisplay;
            ISimpleLineSymbol sym           = new SimpleLineSymbolClass();
            IRgbColor         color         = new RgbColorClass();

            color.Red   = 255;
            color.Green = 128;
            color.Blue  = 128;
            sym.Color   = color;
            sym.Style   = esriSimpleLineStyle.esriSLSSolid;
            sym.Width   = 2;
            IRubberBand cutBand     = new RubberLineClass();
            IGeometry   cutGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol);

            screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            screenDisplay.SetSymbol(sym as ISymbol);
            screenDisplay.DrawPolyline(cutGeometry);
            screenDisplay.FinishDrawing();

            IFeatureClass  featureClass  = m_selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            //分割选择的面要素
            if (cutGeometry.IsEmpty == true)
            {
                return;
            }
            try
            {
                workspaceEdit.StartEditOperation();
                IFeatureEdit featureEdit = m_selectedFeature as IFeatureEdit;
                //分割产生新的面要素
                ISet newFeaturesSet = featureEdit.Split(cutGeometry);
                //亮闪新要素
                if (newFeaturesSet != null)
                {
                    newFeaturesSet.Reset();
                    for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++)
                    {
                        IFeature newFeature = newFeaturesSet.Next() as IFeature;
                        FlashGeometry(newFeature.Shape, 3, 20);
                    }
                }
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                //SysLogHelper.WriteOperationLog("要素分割错误", ex.Source, "数据编辑");
                MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_toolPhase = ToolPhase.SelectFeature;
        }
        private void CutSelectedPolygon()
        {
            bool isSuccess = false;

            if (m_selectedFeature == null)
            {
                MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                m_toolPhase = ToolPhase.SelectFeature;
                return;
            }

            //在屏幕上绘制用于分割的线要素
            IScreenDisplay    screenDisplay = m_activeView.ScreenDisplay;
            ISimpleLineSymbol sym           = new SimpleLineSymbolClass();
            IRgbColor         color         = new RgbColorClass();

            color.Red   = 255;
            color.Green = 128;
            color.Blue  = 128;
            sym.Color   = color;
            sym.Style   = esriSimpleLineStyle.esriSLSSolid;
            sym.Width   = 2;
            IRubberBand cutBand         = new RubberLineClass();
            IGeometry   reshaprGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol);

            screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            screenDisplay.SetSymbol(sym as ISymbol);
            screenDisplay.DrawPolyline(reshaprGeometry);
            screenDisplay.FinishDrawing();

            IFeatureClass  featureClass  = m_selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            //分割选择的面要素
            if (reshaprGeometry.IsEmpty == true)
            {
                return;
            }
            try
            {
                IPolyline           reshapePolyline, sourcePolyline = null;
                IPolygon4           polygon = null;
                IRing               ring = null, innerRing = null, outRing = null;
                IPath               reshapePath    = null;
                IGeometryCollection pathCollection = null;

                IGeometry geometry = m_selectedFeature.Shape;
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    bool                outerSuccess = false, innerSuccess = false;
                    IGeometryBag        innerRingGeometryBag        = null;
                    IGeometryCollection innerRingGeometryCollection = null;
                    reshapePolyline = reshaprGeometry as IPolyline;
                    pathCollection  = reshapePolyline as IGeometryCollection;
                    //只可能产生一条polyline,直接写死
                    reshapePath = pathCollection.Geometry[0] as IPath;
                    polygon     = geometry as IPolygon4;
                    IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
                    IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;
                    for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
                    {
                        outRing = exteriorRingGeometryCollection.Geometry[i] as IRing;
                        bool a = outRing.Reshape(reshapePath);
                        outerSuccess = outerSuccess || a;

                        innerRingGeometryBag        = polygon.get_InteriorRingBag(outRing);
                        innerRingGeometryCollection = innerRingGeometryBag as IGeometryCollection;
                        for (int j = 0; j < innerRingGeometryCollection.GeometryCount; j++)
                        {
                            innerRing = innerRingGeometryCollection.Geometry[j] as IRing;
                            bool b = innerRing.Reshape(reshapePath);
                            innerSuccess = innerSuccess || b;
                        }
                    }
                    isSuccess = innerSuccess || outerSuccess;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    sourcePolyline  = geometry as IPolyline;
                    reshapePolyline = reshaprGeometry as IPolyline;
                    pathCollection  = reshapePolyline as IGeometryCollection;
                    //只可能产生一条polyline,直接写死
                    reshapePath = pathCollection.Geometry[0] as IPath;
                    isSuccess   = sourcePolyline.Reshape(reshapePath);
                    break;
                }

                if (isSuccess)
                {
                    workspaceEdit.StartEditOperation();
                    m_selectedFeature.Shape = geometry;//如果没加这句gdb无法编辑
                    m_selectedFeature.Store();
                    m_activeView.Refresh();
                    workspaceEdit.StopEditOperation();
                }
                else
                {
                    throw new Exception("重塑要素失败!");
                }
                m_activeView.Refresh();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_toolPhase = ToolPhase.SelectFeature;
        }