Image on pagelayout c#

1153
6
12-08-2010 08:00 AM
YashikaSareen
New Contributor
Hi
I want to implement that on select of a point in the shapefile in the pagelayout mode it should display an image(in graphic container).
I got several codes involving vb but i cant understand vb so can any1 provide me a code that can help me.
I know it has an inbuilt feature for adding a picture but i want to implement through programming.
its urgent
0 Kudos
6 Replies
YashikaSareen
New Contributor
I want the code in c# please help.its urgent

Hi
I want to implement that on select of a point in the shapefile in the pagelayout mode it should display an image(in graphic container).
I got several codes involving vb but i cant understand vb so can any1 provide me a code that can help me.
I know it has an inbuilt feature for adding a picture but i want to implement through programming.
its urgent
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
I want the code in c# please help.its urgent


Can you please explain your task....
0 Kudos
YashikaSareen
New Contributor
Hi,
actualy my task is that as we can see in arcmap if we need to include image in the page layout mode then we have inbuilt picturebox to add picture but my task is to implement the same with the code i.e i need to write code in c# to display a picture in pagelayout mode...


I have a point shapefile that has a field that contain the path of the picture.I want on mouse down event if i mouse down on a point it should be highlighted and the corresponding picture shud be dispalyed.I want in c#

its urgent
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Hi,

Please find the code....


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 CountPoints
{
    /// <summary>
    /// Summary description for InsertPic.
    /// </summary>
    [Guid("b311d914-e999-4014-8bcb-2cef2da34b71")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("CountPoints.InsertPic")]
    public sealed class InsertPic : 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 InsertPic()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "PageLayout"; //localizable text
            base.m_caption = "Insert Pic";  //localizable text
            base.m_message = "Insert Picture into Pagelayout";  //localizable text
            base.m_toolTip = "Insert Picture into Pagelayout";  //localizable text
            base.m_name = "Insert_pic";   //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 InsertPic.OnClick implementation

            IMxDocument pMxDoc = m_application.Document as IMxDocument;

            ESRI.ArcGIS.Carto.IPictureElement pPictureElement;

            pPictureElement = new ESRI.ArcGIS.Carto.JpgPictureElementClass();

            pPictureElement.ImportPictureFromFile(@"D:\PROJECTS\MyProject\Images\Excel2.jpg");

            ESRI.ArcGIS.Geometry.IEnvelope pEnv = new ESRI.ArcGIS.Geometry.EnvelopeClass();

            pEnv.PutCoords(1, 1, 5, 5);

            ESRI.ArcGIS.Carto.IElement pElement;

            pElement = pPictureElement as ESRI.ArcGIS.Carto.IElement;

            pElement.Geometry = pEnv;

            ESRI.ArcGIS.Carto.IGraphicsContainer pGraphicContainer;

            pGraphicContainer = pMxDoc.PageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;

            pGraphicContainer.AddElement(pElement, 0);

            ESRI.ArcGIS.Carto.IActiveView pActiveView;

            pActiveView = pGraphicContainer as ESRI.ArcGIS.Carto.IActiveView;

            pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, pElement, pEnv);
        }

        #endregion
    }
}


I hope this helps you...

Thanks and Regards,

Venkat
0 Kudos
YashikaSareen
New Contributor
Thanks a lot...
It was my answer..
can u help me in one more thing....

if i want to select feature on mousedown event--->
first,i created a point,then i buffered it.
now i need to check whether this point intersects with any other feature(i have a polyline shapefile also)
If it does intersect then that line shud be selected....
I used spatial filter but it returns null value

can u check the code please:

  public void OnMouseDown(int button, int shift, int x, int y)
        {
           // # region attribute
            activeView = m_mxDoc.ActiveView;
            IPoint ppoint = new PointClass();
        
            ppoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            ITopologicalOperator topologicalOperator = ppoint as ITopologicalOperator;
            IGeometry gm = topologicalOperator.Buffer(1);
            ISpatialFilter spatialFilter = new SpatialFilterClass();
           
          
        
            IMap map = activeView.FocusMap;
            pageLayout = (PageLayout)m_mxDoc.PageLayout;
            l1 = map.get_Layer(0);
            l2 = map.get_Layer(1);
            if (l1.Name == "SSE_Access")
            {
                layer_working = l1;
            }
            else if (l2.Name == "SSE_Access")
            {
                layer_working = l2;
            }
            else
            {
                layer_working = null;
                MessageBox.Show("Layer for attribute information does not exists");
            }
           
            IFeatureLayer pfl = (IFeatureLayer)layer_working;
            IFeatureClass featureClass = pfl.FeatureClass;
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.Geometry = gm;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            IFeatureCursor featureCursor1 = featureClass.Search(spatialFilter, true);
            IFeature Feat1 = featureCursor1.NextFeature();
            while (Feat1 != null)
            {
                map.SelectFeature(layer_working, Feat1);
                Feat1 = featureCursor1.NextFeature();

            }

thanks in adv.
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Thanks a lot...
It was my answer..
can u help me in one more thing....

if i want to select feature on mousedown event--->
first,i created a point,then i buffered it.
now i need to check whether this point intersects with any other feature(i have a polyline shapefile also)
If it does intersect then that line shud be selected....
I used spatial filter but it returns null value

can u check the code please:

  public void OnMouseDown(int button, int shift, int x, int y)
        {
           // # region attribute
            activeView = m_mxDoc.ActiveView;
            IPoint ppoint = new PointClass();
        
            ppoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            ITopologicalOperator topologicalOperator = ppoint as ITopologicalOperator;
            IGeometry gm = topologicalOperator.Buffer(1);
            ISpatialFilter spatialFilter = new SpatialFilterClass();
           
          
        
            IMap map = activeView.FocusMap;
            pageLayout = (PageLayout)m_mxDoc.PageLayout;
            l1 = map.get_Layer(0);
            l2 = map.get_Layer(1);
            if (l1.Name == "SSE_Access")
            {
                layer_working = l1;
            }
            else if (l2.Name == "SSE_Access")
            {
                layer_working = l2;
            }
            else
            {
                layer_working = null;
                MessageBox.Show("Layer for attribute information does not exists");
            }
           
            IFeatureLayer pfl = (IFeatureLayer)layer_working;
            IFeatureClass featureClass = pfl.FeatureClass;
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.Geometry = gm;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            IFeatureCursor featureCursor1 = featureClass.Search(spatialFilter, true);
            IFeature Feat1 = featureCursor1.NextFeature();
            while (Feat1 != null)
            {
                map.SelectFeature(layer_working, Feat1);
                Feat1 = featureCursor1.NextFeature();

            }

thanks in adv.


hi,

Please can you post the complete code what suppose to use .. where you getting error....

Thanks and Regards,

Venkat Tammineni
0 Kudos