Select to view content in your preferred language

Help: Changing a point via form control makes existing point disappear

711
3
12-20-2010 04:43 AM
JSan
by
New Contributor
Hi,
New to ArcObjects - I have a point in an .mxd layer that I would like to change via user interaction on a form (button click).  However, when I run my application and click to update the point, the existing point in the target layer completely disappears.  Can anyone point me in the right direction?

                        IMxDocument _mxDoc = (IMxDocument)_doc;
                        IMap map = (IMap)_mxDoc.FocusMap;
                        IGeoFeatureLayer gLayer = (IGeoFeatureLayer)map.get_Layer(2);
                       
                       
                        IRgbColor pColor = new RgbColorClass();
                        pColor.Red = 255;
                        pColor.Green = 255;
                        pColor.Blue = 0;

                       
                        ISimpleMarkerSymbol sMarker = new SimpleMarkerSymbol();
                        sMarker.Color = pColor;
                        sMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond;
                        sMarker.Size = 20;

                       
                        ISimpleRenderer sRender = (ISimpleRenderer)gLayer.Renderer;
                        sRender.Symbol = (ISymbol)sMarker;
                        gLayer.Renderer = (IFeatureRenderer)sRender;

                       
                        IActiveView vActive = (IActiveView)map;
                        vActive.Refresh();
0 Kudos
3 Replies
Venkata_RaoTammineni
Regular Contributor
Hi,
New to ArcObjects - I have a point in an .mxd layer that I would like to change via user interaction on a form (button click).  However, when I run my application and click to update the point, the existing point in the target layer completely disappears.  Can anyone point me in the right direction?

                        IMxDocument _mxDoc = (IMxDocument)_doc;
                        IMap map = (IMap)_mxDoc.FocusMap;
                        IGeoFeatureLayer gLayer = (IGeoFeatureLayer)map.get_Layer(2);
                       
                       
                        IRgbColor pColor = new RgbColorClass();
                        pColor.Red = 255;
                        pColor.Green = 255;
                        pColor.Blue = 0;

                       
                        ISimpleMarkerSymbol sMarker = new SimpleMarkerSymbol();
                        sMarker.Color = pColor;
                        sMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond;
                        sMarker.Size = 20;

                       
                        ISimpleRenderer sRender = (ISimpleRenderer)gLayer.Renderer;
                        sRender.Symbol = (ISymbol)sMarker;
                        gLayer.Renderer = (IFeatureRenderer)sRender;

                       
                        IActiveView vActive = (IActiveView)map;
                        vActive.Refresh();


what _doc is it Iapplication instance ? please can you send me complete code so that i understand the issue...
0 Kudos
JSan
by
New Contributor
Below is the code I have been using.  I stripped out all of the other form controls.  I think I cast everything correctly and the problem was with the render.  Thanks for taking a look at this.

public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        //These hold the document and application references
        private IDocument _doc = null;
        private IApplication _app = null;
       
               

        //Point button code
        private void btnPointColor_Click(object sender, EventArgs e)
        {
            IMxDocument _mxDoc = (IMxDocument)_doc;     //Cast as IMxDocument Interface
            IMap map = (IMap)_mxDoc.FocusMap;           //cast _mxDoc as Carto IMap interface
            IGeoFeatureLayer gLayer = (IGeoFeatureLayer)map.get_Layer(2);   //Cast map layer 3 as IGeoFeature layer
                       
            //Set the new color for the point
            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 255;
            pColor.Green = 255;
            pColor.Blue = 0;

            //Point so we need a simple marker symbol
            ISimpleMarkerSymbol sMarker = new SimpleMarkerSymbol();
            sMarker.Color = pColor;
            sMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond;
            sMarker.Size = 20;

            //Need to render
            ISimpleRenderer sRender = new SimpleRenderer();
            sRender.Symbol = (ISymbol)sMarker;
            gLayer.Renderer = sRender;

            //_mxDoc.UpdateContents();
            IActiveView vActive = (IActiveView)map;
            vActive.Refresh();
        }
    }
0 Kudos
Venkata_RaoTammineni
Regular Contributor
Below is the code I have been using.  I stripped out all of the other form controls.  I think I cast everything correctly and the problem was with the render.  Thanks for taking a look at this.

public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        //These hold the document and application references
        private IDocument _doc = null;
        private IApplication _app = null;
       
               

        //Point button code
        private void btnPointColor_Click(object sender, EventArgs e)
        {
            IMxDocument _mxDoc = (IMxDocument)_doc;     //Cast as IMxDocument Interface
            IMap map = (IMap)_mxDoc.FocusMap;           //cast _mxDoc as Carto IMap interface
            IGeoFeatureLayer gLayer = (IGeoFeatureLayer)map.get_Layer(2);   //Cast map layer 3 as IGeoFeature layer
                       
            //Set the new color for the point
            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 255;
            pColor.Green = 255;
            pColor.Blue = 0;

            //Point so we need a simple marker symbol
            ISimpleMarkerSymbol sMarker = new SimpleMarkerSymbol();
            sMarker.Color = pColor;
            sMarker.Style = esriSimpleMarkerStyle.esriSMSDiamond;
            sMarker.Size = 20;

            //Need to render
            ISimpleRenderer sRender = new SimpleRenderer();
            sRender.Symbol = (ISymbol)sMarker;
            gLayer.Renderer = sRender;

            //_mxDoc.UpdateContents();
            IActiveView vActive = (IActiveView)map;
            vActive.Refresh();
        }
    }


Hi Please follow below steps..

1) add basecommand class


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;

namespace PointRenderer
{
    /// <summary>
    /// Summary description for ShowPoint.
    /// </summary>
    [Guid("797af0fa-03d9-4e41-8c61-1109e3aff787")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("PointRenderer.ShowPoint")]
    public sealed class ShowPoint : BaseCommand
    {
        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryRegistration(registerType);

            //
            // TODO: Add any COM registration code here
            //
        }

        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryUnregistration(registerType);

            //
            // TODO: Add any COM unregistration code here
            //
        }

        #region ArcGIS Component Category Registrar generated code
        /// <summary>
        /// Required method for ArcGIS Component Category registration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            MxCommands.Register(regKey);

        }
        /// <summary>
        /// Required method for ArcGIS Component Category unregistration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            MxCommands.Unregister(regKey);

        }

        #endregion
        #endregion

        private IApplication m_application;
        public ShowPoint()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "GIS_FORM"; //localizable text
            base.m_caption = "Render Point";  //localizable text
            base.m_message = "Render Point";  //localizable text
            base.m_toolTip = "Render Point";  //localizable text
            base.m_name = "Render Point";   //unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")

            try
            {
                //
                // TODO: change bitmap name if necessary
                //
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }

        #region Overriden Class Methods

        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
                return;

            m_application = hook as IApplication;

            //Disable if it is not ArcMap
            if (hook is IMxApplication)
                base.m_enabled = true;
            else
                base.m_enabled = false;

            // TODO:  Add other initialization code
        }

        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ShowPoint.OnClick implementation
            PointRender _pointRender = new PointRender(m_application);

            _pointRender.ShowDialog();
          
        }

        #endregion
    }
}

2) Add Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Display;

namespace PointRenderer
{
    public partial class PointRender : Form
    {
        private IApplication pApp = null;
        public PointRender(IApplication pApp)
        {
            this.pApp = pApp;

            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IMxDocument pMxDoc = pApp.Document as IMxDocument;

                IMap pMap = pMxDoc.FocusMap;

                IGeoFeatureLayer pGeoFeatLayer;

                pGeoFeatLayer = pMap.get_Layer(0) as IGeoFeatureLayer;

                IRgbColor pRGB = new RgbColorClass();

                pRGB.Red = 84;

                pRGB.Green = 156;

                pRGB.Blue = 227;

                ISimpleMarkerSymbol pSimpleMarkerSinboml = new SimpleMarkerSymbolClass();

                pSimpleMarkerSinboml.Color = pRGB;

                pSimpleMarkerSinboml.Style = esriSimpleMarkerStyle.esriSMSDiamond;

                pSimpleMarkerSinboml.Size = 10;

                ISimpleRenderer pSimpleRender = new SimpleRendererClass();

                pSimpleRender.Symbol = pSimpleMarkerSinboml as ISymbol;

                pGeoFeatLayer.Renderer = pSimpleRender as IFeatureRenderer;

                pMxDoc.UpdateContents();

                pMxDoc.ActiveView.Refresh();
            }
            catch (Exception exp) { }


        }
    }
}
0 Kudos