Ejemplo n.º 1
0
        private bool IsSaveable()
        {
            if (this.cboTargetLayer.Items.Count == 0)
            {
                return(false);
            }

            ILayer        layer        = _utilitiesArcmap.Layer(this.cboTargetLayer.Text);
            IFeatureLayer featurelayer = layer as IFeatureLayer;

            if (!(featurelayer == null))
            {
                IFeatureClass   featureclass  = featurelayer.FeatureClass;
                IWorkspace2     workspace     = ((IDataset)featureclass).Workspace as IWorkspace2;
                IWorkspaceEdit2 workspaceedit = (IWorkspaceEdit2)workspace;

                if (!workspaceedit.IsBeingEdited())
                {
                    return(false);
                }

                bool hasedits = false;
                workspaceedit.HasEdits(ref hasedits);
                if (!hasedits)
                {
                    return(false);
                }

                if (workspaceedit.IsInEditOperation)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void OnClick()
        {
            m_Map          = m_hookHelper.FocusMap;
            m_activeView   = m_Map as IActiveView;
            m_EngineEditor = MapManager.EngineEditor;
            Boolean bSave = true;

            if (m_EngineEditor == null)
            {
                return;
            }
            if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing)
            {
                return;
            }
            IWorkspaceEdit2 pWsEdit2 = m_EngineEditor.EditWorkspace as IWorkspaceEdit2;

            if (pWsEdit2.IsBeingEdited())
            {
                Boolean bHasEdit = m_EngineEditor.HasEdits();
                if (bHasEdit)
                {
                    if (MessageBox.Show("是否保存所做的编辑?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        bSave = true;
                    }
                    else
                    {
                        bSave = false;
                    }
                }
                m_EngineEditor.StopEditing(bSave);
            }
            m_Map.ClearSelection();
            m_activeView.Refresh();
        }
Ejemplo n.º 3
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            #region 处理各种交互情况
            switch (m_sketchshape)
            {
            case "polygon":
            {
                IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay;

                IPoint newPoint = new PointClass();
                newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

                if (e.button == 1)
                {
                    //左单击画多边形添加点:
                    if (m_NewPolygonFeedback == null)
                    {
                        m_NewPolygonFeedback = new NewPolygonFeedbackClass();

                        m_NewPolygonFeedback.Display = iSDisplay;
                        m_NewPolygonFeedback.Start(newPoint);
                    }
                    else
                    {
                        m_NewPolygonFeedback.AddPoint(newPoint);
                    }
                }
                if (e.button == 2)
                {
                    if (m_NewPolygonFeedback == null)
                    {
                        return;
                    }
                    //右键结束绘制:
                    m_NewPolygonFeedback.AddPoint(newPoint);
                    m_NewPolygon = m_NewPolygonFeedback.Stop();

                    //若是逆时针创建,反转一下,变为顺时针:
                    IArea feedBackArea = m_NewPolygon as IArea;
                    if (feedBackArea.Area < 0)
                    {
                        m_NewPolygon.ReverseOrientation();
                    }

                    IGeometry         newGeometry       = m_NewPolygon as IGeometry;
                    IFeatureWorkspace checkWorkspace    = m_GlobalWorkspace as IFeatureWorkspace;
                    IFeatureClass     checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea");


                    if (!(m_EditWorkspace.IsBeingEdited()))
                    {
                        m_EditWorkspace.StartEditing(false);
                    }

                    m_EditWorkspace.StartEditOperation();
                    int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName);
                    m_EditWorkspace.StopEditOperation();
                    //ISelectionEnvironment selectionEnv = new SelectionEnvironmentClass();
                    //selectionEnv.AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelOverlaps;
                    //selectionEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
                    //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, null, true);
                    //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, selectionEnv, true);
                    //m_MapCtrls.Map.SelectByShape(m_NewPolygon, null, true);
                    ILayer   iLayer   = m_MapCtrls.Layer[0];
                    IFeature iFeature = checkFeatureClass.GetFeature(OID);

                    clearFeatureSelection();

                    m_MapCtrls.Map.SelectFeature(iLayer, iFeature);
                    m_NewPolygonFeedback = null;
                    m_MapCtrls.ActiveView.Refresh();
                }
                break;
            }

            case "rectangle":
            {
                IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay;

                IPoint newPoint = new PointClass();
                newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                if (e.button == 1)
                {
                    if (m_RecFeedback == null)
                    {
                        m_RecFeedback         = new NewRectangleFeedbackClass();
                        m_RecFeedback.Display = iSDisplay;
                        m_RecFeedback.Angle   = 90;
                        m_RecFeedback.Start(newPoint);

                        newPoint.Y = newPoint.Y + 20;

                        m_RecFeedback.SetPoint(newPoint);
                    }
                    else
                    {
                        m_RecFeedback.SetPoint(newPoint);
                    }
                }
                if (e.button == 2)
                {
                    if (m_RecFeedback != null)
                    {
                        m_NewPolygon = m_RecFeedback.Stop(newPoint) as IPolygon;

                        //若是逆时针创建,反转一下,变为顺时针:
                        IArea feedBackArea = m_NewPolygon as IArea;
                        if (feedBackArea.Area < 0)
                        {
                            m_NewPolygon.ReverseOrientation();
                        }

                        IGeometry         newGeometry       = m_NewPolygon as IGeometry;
                        IFeatureWorkspace checkWorkspace    = m_GlobalWorkspace as IFeatureWorkspace;
                        IFeatureClass     checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea");


                        if (!(m_EditWorkspace.IsBeingEdited()))
                        {
                            m_EditWorkspace.StartEditing(false);
                        }

                        m_EditWorkspace.StartEditOperation();
                        int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName);
                        m_EditWorkspace.StopEditOperation();

                        ILayer   iLayer   = m_MapCtrls.Layer[0];
                        IFeature iFeature = checkFeatureClass.GetFeature(OID);

                        clearFeatureSelection();

                        m_MapCtrls.Map.SelectFeature(iLayer, iFeature);
                        m_MapCtrls.ActiveView.Refresh();
                        m_RecFeedback = null;
                    }
                }

                break;
            }
            }
            #endregion
        }
Ejemplo n.º 4
0
        private void btnInserir_Click(object sender, EventArgs e)
        {
            // valida os campos
            if (!this.ValidarCampos())
            {
                return;
            }


            // workspace
            IWorkspace workspace =
                ArcMapUtils.GetFeatureLayerWorkspace(this._layerDeUnidadesDeSaude);

            IWorkspaceEdit2 workspaceEdit = workspace as IWorkspaceEdit2;

            if (workspaceEdit.IsBeingEdited())
            {
                MessageBox.Show(this, "O workspace está em edição. Aguarde.", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            // filtro para achar o bairro e o distrito sanitário a que a unidade de saúde pertence
            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.Geometry   = this._featureParaCopia.ShapeCopy;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;


            // pegar o código do bairro
            IFeatureCursor featCursorBairros = this._layerDeBairros.Search(spatialFilter, false);
            IFeature       featureBairro     = featCursorBairros.NextFeature();

            int nomeIndex = this._layerDeBairros.FeatureClass.FindField("nome");

            int    codigoBairro = featureBairro.OID;
            string nomeBairro   = (string)featureBairro.get_Value(nomeIndex);


            //pegar o código do distrito sanitário
            IFeatureCursor featCursorDistritos = this._layerDeDistritos.Search(spatialFilter, false);
            IFeature       featureDistrito     = featCursorDistritos.NextFeature();

            int nomeIndex1 = this._layerDeDistritos.FeatureClass.FindField("nome");

            int    codigoDistrito = featureDistrito.OID;
            string nomeDistrito   = (string)featureDistrito.get_Value(nomeIndex1);

            this.Cursor = Cursors.WaitCursor;


            //cadastra a nova unidade de saúde
            try
            {
                // inicia edição
                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();

                // dados da nova Unidade de Saúde
                UnidadeSaude unidadeDeSaude = new UnidadeSaude();
                unidadeDeSaude.Nome                    = txtNomeUS.Text.ToString();
                unidadeDeSaude.Endereco                = txtEnderecoUS.Text.ToString();
                unidadeDeSaude.Bairro                  = txtBairroUS.Text.ToString();
                unidadeDeSaude.DistritoSanitario       = txtDistritoUS.Text.ToString();
                unidadeDeSaude.CodigoBairro            = (int)codigoBairro;
                unidadeDeSaude.CodigoDistritoSanitario = (int)codigoDistrito;

                // criação da nova feature
                IFeature featureUnidadeDeSaude = this._layerDeUnidadesDeSaude.FeatureClass.CreateFeature();
                featureUnidadeDeSaude.Shape = _featureParaCopia.ShapeCopy;
                unidadeDeSaude.ToFeature(featureUnidadeDeSaude);

                // finaliza edição
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(true);

                MessageBox.Show(this, "Unidade de Saúde inserida com sucesso !", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                // limpa seleção
                ArcMap.Document.FocusMap.ClearSelection();

                // fecha o formulário
                this.Close();
            }
            catch
            {
                // cancela edição
                if (workspaceEdit.IsInEditOperation)
                {
                    workspaceEdit.AbortEditOperation();
                }
                workspaceEdit.StopEditing(false);

                MessageBox.Show(this, "Não foi possível realizar a inserção de uma nova unidade de saúde !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                // refresh
                IActiveView activeView = ArcMap.Document.FocusMap as IActiveView;
                activeView.Refresh();

                // cursor
                this.Cursor = Cursors.Default;
            }
        }