public int OnPopup(object Hook)
    {
      IApplication app = Hook as IApplication;
      if (app == null)
        return 0;

      m_doc = app.Document as IMxDocument;
      m_map = m_doc.FocusMap;

      return m_map.LayerCount;
    }
Beispiel #2
0
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute attribute)
        {
            // Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
            Type t = Type.GetTypeFromProgID("esriFramework.AppRef");

            try
            {
                // Activator.CreateInstance(t) is expected to error if the evaluator is created in an engine application
                // which can�t get a reference to the AppRef singleton.
                // This evaluator won�t work in Engine due to this design limitation.  It is, however,
                // fully functional in ArcMap.
                System.Object obj = Activator.CreateInstance(t);
                IApplication  app = obj as IApplication;
                if (app != null && app is IMxApplication)
                {
                    m_mxDocument = app.Document as IMxDocument;
                }
            }
            catch (Exception e)
            {
                m_mxDocument = null;
            }

            // Store reference to the network dataset and the network source
            m_networkDataset = networkDataset;
            m_networkSource  = source;

            // Create a new Dictionary hashtable for this network source
            m_sourceHashTable = new Dictionary <int, int>();
        }
Beispiel #3
0
        //Returns the map title as string given the IApplciation variable of the current mxd
        public static string getPageSize(IMxDocument pMxDoc, string pFrameName)
        {
            string pageSize = null;
            Dictionary <string, string> mapProps = PageLayoutProperties.getDataframeProperties(pMxDoc, pFrameName);
            string pageFormId = mapProps["page_size"];

            Dictionary <string, string> pageSizes = new Dictionary <string, string>();

            pageSizes.Add("esriPageFormLetter", "Letter");
            pageSizes.Add("esriPageFormLegal", "Legal");
            pageSizes.Add("esriPageFormTabloid", "Tabloid");
            pageSizes.Add("esriPageFormC", "C");
            pageSizes.Add("esriPageFormD", "D");
            pageSizes.Add("esriPageFormE", "E");
            pageSizes.Add("esriPageFormA5", "A5");
            pageSizes.Add("esriPageFormA4", "A4");
            pageSizes.Add("esriPageFormA3", "A3");
            pageSizes.Add("esriPageFormA2", "A2");
            pageSizes.Add("esriPageFormA1", "A1");
            pageSizes.Add("esriPageFormA0", "A0");
            pageSizes.Add("esriPageFormCUSTOM", "Custom");
            pageSizes.Add("esriPageFormSameAsPrinter", "Same as printer");

            foreach (var i in pageSizes)
            {
                if (pageFormId == i.Key)
                {
                    pageSize = i.Value;
                }
            }
            return(pageSize);
        }
Beispiel #4
0
        //Checks the element names of the page layout
        //returns boolean true if duplicates exist
        public static Boolean checkLayoutTextElementsForDuplicates(IMxDocument pMxDoc, string pFrameName)
        {
            //create list to store name of text elements
            List <string> lst = new List <string>();
            Boolean       duplicates;

            //check if the frame passed exists in the map document
            if (PageLayoutProperties.detectMapFrame(pMxDoc, pFrameName))
            {
                //Declare variables
                IPageLayout        pLayout   = pMxDoc.PageLayout;
                IGraphicsContainer pGraphics = pLayout as IGraphicsContainer;
                pGraphics.Reset();

                IElement            element = new TextElementClass();
                IElementProperties2 pElementProp;
                ITextElement        pTextElement;

                //loop through the text elements in the frame
                try
                {
                    element = (IElement)pGraphics.Next();
                    while (element != null)
                    {
                        if (element is ITextElement)
                        {
                            pTextElement = element as ITextElement;
                            pElementProp = element as IElementProperties2;
                            //where the name is not blank
                            //System.Diagnostics.Debug.WriteLine(pElementProp.Name);
                            if (pElementProp.Name != "")
                            {
                                //store the name of the elements and the values in the dictionary as pairs
                                lst.Add(pElementProp.Name);
                            }
                        }
                        element = pGraphics.Next() as IElement;
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Error detecting duplicate elements from the map frame");
                    System.Diagnostics.Debug.WriteLine(e);
                }
            }

            //Find if duplicates exist
            int duplicateCount = lst.Count() - lst.Distinct().Count();

            if (duplicateCount != 0)
            {
                duplicates = true;
                return(duplicates);
            }
            else
            {
                duplicates = false;
                return(duplicates);
            }
        }
        public ZingerForm()
        {
            _document   = ArcMap.Application.Document as IMxDocument;
            _activeView = _document.ActiveView;

            InitializeComponent();
        }
Beispiel #6
0
        public void CreateTextElment(double x, double y, int index)
        {
            IMxDocument doc = ArcMap.Document;
            IMap        map = doc.FocusMap;

            IPoint pPoint = new PointClass();
            //IMap pMap = axMapControl.Map;
            IMap               pMap        = doc.FocusMap;
            IActiveView        pActiveView = pMap as IActiveView;
            IGraphicsContainer pGraphicsContainer;
            IElement           pElement  = new MarkerElementClass();
            IElement           pTElement = new TextElementClass();

            pGraphicsContainer = (IGraphicsContainer)pActiveView;
            IFormattedTextSymbol pTextSymbol     = new TextSymbolClass();
            IBalloonCallout      pBalloonCallout = CreateBalloonCallout(x, y);
            IRgbColor            pColor          = new RgbColorClass();

            pColor.Red        = 150;
            pColor.Green      = 0;
            pColor.Blue       = 0;
            pTextSymbol.Color = pColor;
            ITextBackground pTextBackground;

            pTextBackground                  = (ITextBackground)pBalloonCallout;
            pTextSymbol.Background           = pTextBackground;
            ((ITextElement)pTElement).Symbol = pTextSymbol;
            ((ITextElement)pTElement).Text   = index.ToString();
            pPoint.X = x + 420;
            pPoint.Y = y + 420;
            //axMapControl.CenterAt(pPoint);
            pTElement.Geometry = pPoint;
            pGraphicsContainer.AddElement(pTElement, 1);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Beispiel #7
0
        /// <summary>
        /// Clear Graphics
        /// </summary>
        internal void ClearGraphics()
        {
            try
            {
                IMxDocument        mxDocument        = ArcMap.Application.Document as IMxDocument;
                IActiveView        activeView        = mxDocument.ActiveView;
                IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;

                //Pre fresh the Graphics Container
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                //Loop thro the Elements Clearing the Locator Graphics
                graphicsContainer.Reset();
                for (IElement element = graphicsContainer.Next(); element != null; element = graphicsContainer.Next())
                {
                    IElementProperties elementProperties = element as IElementProperties;
                    if (elementProperties.Name == LOCATOR_ELEMENT_NAME)
                    {
                        graphicsContainer.DeleteElement(element);
                    }
                }
                this.CalloutAdded = false;
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
        /// <summary>
        /// Flash the feature geometry on the map
        /// <param name="pFeature">The feature being flashed</param>
        /// <param name="pMxDoc">A hook to the application display</param>
        /// <param name="direction">The digitized direction of the barrier with respect to the underlying source feature</param>
        /// </summary>
        private void FlashFeature(IFeature pFeature, esriNetworkEdgeDirection direction)
        {
            IMxDocument pMxDoc = m_app.Document as IMxDocument;

            // Start drawing on screen.
            pMxDoc.ActiveView.ScreenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);

            // Switch functions based on Geometry type.
            switch (pFeature.Shape.GeometryType)
            {
            case esriGeometryType.esriGeometryPolyline:
                FlashLine(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape, direction);
                break;

            case esriGeometryType.esriGeometryPolygon:
                // no network elements can be polygons
                break;

            case esriGeometryType.esriGeometryPoint:
                FlashPoint(pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape);
                break;

            default:
                throw new Exception("Unexpected Geometry Type");
            }

            // Finish drawing on screen.
            pMxDoc.ActiveView.ScreenDisplay.FinishDrawing();
        }
        /// <summary>
        /// Occurs when the user clicks the Zoom To Barrier Geometry button.
        ///   The map will zoom to the extent of the Shape of the barrier.
        /// <param name="sender">The control raising this event</param>
        /// <param name="e">Arguments associated with the event</param>
        /// </summary>
        private void btnZoomToBarrier_Click(object sender, EventArgs e)
        {
            IMxDocument mxDoc = m_app.Document as IMxDocument;

            mxDoc.ActiveView.Extent = m_barrier.Extent;
            mxDoc.ActiveView.Refresh();
        }
Beispiel #10
0
        private static void MapUsingSimpleMarkerRenderer()
        {
            string layerName = CboLayers.GetSelectedLayer();
            ILayer layer     = GetLayerByName(layerName);

            string     colorName   = CboColors.GetSelectedColor();
            ICmykColor markerColor = ColorbrewerExtension.GetSingleCMYKColor();

            ISimpleMarkerSymbol marker = new SimpleMarkerSymbol();

            marker.Style = esriSimpleMarkerStyle.esriSMSCircle;
            marker.Color = markerColor;
            marker.Size  = 5;

            ISimpleRenderer renderer = new SimpleRenderer();

            renderer.Symbol = marker as ISymbol;
            renderer.Label  = layer.Name;

            IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer;

            gFLayer.Renderer = renderer as IFeatureRenderer;
            IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;
            IMap        map   = mxDoc.FocusMap;

            mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,
                                            gFLayer, mxDoc.ActiveView.Extent);
            mxDoc.UpdateContents();
        }
Beispiel #11
0
        private static void MapUsingSimpleFillRenderer()
        {
            string layerName = CboLayers.GetSelectedLayer();
            ILayer layer     = GetLayerByName(layerName);

            string     colorName = CboColors.GetSelectedColor();
            ICmykColor fillColor = ColorbrewerExtension.GetSingleCMYKColor();

            ISimpleFillSymbol fill = new SimpleFillSymbol();

            fill.Style = esriSimpleFillStyle.esriSFSSolid;
            fill.Color = fillColor;

            ISimpleRenderer simpleRenderer = new SimpleRenderer();

            simpleRenderer.Symbol = fill as ISymbol;
            simpleRenderer.Label  = layer.Name;

            IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer;

            gFLayer.Renderer = simpleRenderer as IFeatureRenderer;
            IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;
            IMap        map   = mxDoc.FocusMap;

            mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography
                                            , gFLayer, mxDoc.ActiveView.Extent);
        }
Beispiel #12
0
        public void Init()
        {
            IMxDocument        mxDocument      = AppSingleton.Instance().MxDocument;
            IMap               map             = mxDocument.FocusMap;
            int                layerCount      = map.LayerCount;
            List <LayerObject> LayerObjectList = new List <LayerObject>();

            for (int i = 0; i < layerCount; i++)
            {
                ILayer        layer  = map.get_Layer(i);
                IFeatureLayer fLayer = layer as IFeatureLayer;
                if (fLayer != null)
                {
                    IFeatureClass fclass = fLayer.FeatureClass;

                    LayerObject lObject = new LayerObject();
                    lObject.layer = layer;
                    lObject.Name  = layer.Name;
                    LayerObjectList.Add(lObject);
                }
            }
            UpdateComboboxWithLayers(cmbProjectArea, LayerObjectList);
            UpdateComboboxWithLayers(cmbVeriAylik, LayerObjectList);
            UpdateComboboxWithLayers(cmbVeriYillik, LayerObjectList);
        }
Beispiel #13
0
        private void addBottomLine()
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            ISimpleLineSymbol  pLineSym     = null;
            IMxDocument        pMxDoc       = (IMxDocument)ArcMap.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;

            try
            {
                pLineSym = (ISimpleLineSymbol)oSpatialSubs.createSimpleLineSymbol(oSpatialSubs.createRGB(0, 0, 0), (1 * base.XFactor), esriSimpleLineStyle.esriSLSSolid);
                oSpatialSubs.addLineToGraphicsContainer(pGC,
                                                        pLineSym,
                                                        SPrintConst.MapFrame_XMax * base.XFactor,
                                                        SPrintConst.Neatline_XMax * base.XFactor,
                                                        (SPrintConst.Name_YMin - .02) * base.YFactor,
                                                        (SPrintConst.Name_YMin - .02) * base.YFactor);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:addCenterLine()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pLineSym = null;
                pMxDoc   = null;
                pGC      = null;
            }
        }
Beispiel #14
0
        public void InitForm(IMxDocument mxDocument)
        {
            IMap map        = mxDocument.FocusMap;
            int  layerCount = map.LayerCount;
            List <LayerObject> LayerObjectList = new List <LayerObject>();

            for (int i = 0; i < layerCount; i++)
            {
                ILayer        layer  = map.get_Layer(i);
                IFeatureLayer fLayer = layer as IFeatureLayer;
                if (fLayer != null)
                {
                    IFeatureClass fClass = fLayer.FeatureClass;

                    LayerObject lObject = new LayerObject();
                    lObject.layer = layer;
                    lObject.Name  = layer.Name;
                    listBoxTumKatmanlar.Items.Add(lObject);
                }
                else if (layer is IRasterLayer)
                {
                    LayerObject lObject = new LayerObject();
                    lObject.layer = layer;
                    lObject.Name  = layer.Name;
                    listBoxTumKatmanlar.Items.Add(lObject);
                }
            }
            updateComboBox();
        }
Beispiel #15
0
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            try
            {
                int x = arg.X;
                int y = arg.Y;

                IMxDocument pMxdoc = (IMxDocument)ArcMap.Application.Document;

                IFeatureLayer pfeaturelayer = (IFeatureLayer)pMxdoc.ActiveView.FocusMap.Layer[0];
                IDataset      pDS           = (IDataset)pfeaturelayer.FeatureClass;
                TowerManager  tm            = new TowerManager(pDS.Workspace);

                // THIS IS HOW YOU CREATE A POINT
                IPoint pPoint = pMxdoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                Tower t = tm.GetNearestTower(pPoint, 30);

                if (t == null)
                {
                    MessageBox.Show("No towers were found within the are you clicked");
                    return;
                }

                MessageBox.Show("Tower id " + t.ID + Environment.NewLine + "Type: " + t.TowerType + Environment.NewLine + "NetworkBand " + t.NetworkBand);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #16
0
        private List <ILayer> _GetLayers(IMxDocument mxDocument)
        {
            List <ILayer> layers = new List <ILayer>();

            if (mxDocument != null)
            {
                IMap map = null;
                try
                {
                    map = mxDocument.FocusMap;
                    for (int i = 0; i < map.LayerCount; i++)
                    {
                        ILayer pLayer = map.get_Layer(i);
                        if (pLayer is ICompositeLayer)
                        {
                            _AddSubLayers((ICompositeLayer)pLayer, layers);
                        }
                        else
                        {
                            layers.Add(pLayer);
                        }
                    }
                }
                finally
                {
                    UrbanDelineationExtension.ReleaseComObject(map);
                }
            }

            return(layers);
        }
Beispiel #17
0
        public SetupForm()
        {
            _document   = ArcMap.Document;
            _activeView = _document.ActiveView;

            InitializeComponent();
        }
        public void UpdateCurrentTime(double progress)
        {
            if (progress <= 0)
            {
                progress = 0.05;
            }
            else if (progress >= 100)
            {
                progress = 0.95;
            }

            //Calculate how far into the layer to jump
            ITimeDuration offsetToNewCurrentTime = m_myLayerTimeExtent.QueryTimeDuration();

            offsetToNewCurrentTime.Scale(progress);

            IMxDocument    pMxDoc         = ArcMap.Document;
            IMap           pMap           = pMxDoc.FocusMap;
            IActiveView    pActiveView    = pMap as IActiveView;
            IScreenDisplay pScreenDisplay = pActiveView.ScreenDisplay;
            ITimeDisplay   pTimeDisplay   = pScreenDisplay as ITimeDisplay;

            ITime startTime = m_myLayerTimeExtent.StartTime;
            ITime endTime   = (ITime)((IClone)startTime).Clone();

            ((ITimeOffsetOperator)endTime).AddDuration(m_layerInterval);
            ITimeExtent pTimeExt = new TimeExtentClass();

            pTimeExt.SetExtent(startTime, endTime);
            pTimeExt.Empty = false;
            ((ITimeOffsetOperator)pTimeExt).AddDuration(offsetToNewCurrentTime);
            pTimeDisplay.TimeValue = pTimeExt as ITimeValue;
            pActiveView.Refresh();
        }
Beispiel #19
0
        /// <summary>
        ///     Add the SMARTMAP text as an ITextElement to the map layout. Place the text on top
        ///     off the black rectangle that was placed in the lower right hand corner between
        ///     the mapframe and the neatline.
        /// </summary>
        public override void addMedfordText()
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            IMxDocument        pMxDoc       = (IMxDocument)ArcMap.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;

            try
            {
                ITextSymbol  pTextSym  = oSpatialSubs.createTextSymbol(255, 255, 255, (9 * base.YFactor), esriTextHorizontalAlignment.esriTHACenter, esriTextVerticalAlignment.esriTVACenter, "Arial");
                string       sText     = "CITY OF MEDFORD";
                ITextElement pTextElem = oSpatialSubs.addTextToGraphicsContainer(pGC,
                                                                                 pTextSym,
                                                                                 ((base.XFactor * 1.19) * SPrintConst.MapFrame_XMax),
                                                                                 (base.XFactor * SPrintConst.MapFrame_XMax),
                                                                                 (base.YFactor * (SPrintConst.Neatline_YMax - SPrintConst.Logo_Offset)),
                                                                                 (base.YFactor * SPrintConst.Neatline_YMax),
                                                                                 sText);
                pTextSym  = null;
                pTextElem = null;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CLandscapeLayout:addMedfordText()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pMxDoc = null;
                pGC    = null;
            }
        }
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

            IRubberBand pRabber = new RubberPolygon();

            //get polygon from screen
            IPolygon pPolygon = pRabber.TrackNew(pMxDoc.ActiveView.ScreenDisplay, null) as IPolygon;

            //get cordinate from hard coded
            //IPolygon pPolygon ;

            //IPoint pPoint1 = new Point();
            //pPoint1.X = -120.730273;
            //pPoint1.Y = 224.928212;

            //IPoint pPoint2 = new Point();
            //pPoint2.X = -25.280158;
            //pPoint2.Y = 27942068.023;

            //IPoint pPoint3 = new Point();
            //pPoint3.X = -117.895121;
            //pPoint3.Y = 150.269211;



            //IPointCollection pPointCollection = new Polygon();
            //pPointCollection.AddPoint(pPoint1);
            //pPointCollection.AddPoint(pPoint2);
            //pPointCollection.AddPoint(pPoint3);
            //pPointCollection.AddPoint(pPoint1);

            //pPolygon = pPointCollection as IPolygon;


            ////fix when draw wrong draw
            //IArea pArea = pPolygon as IArea;
            //if (pArea.Area < 0)
            //{
            //    pPolygon.ReverseOrientation();
            //}


            IFeatureLayer  pFlayer = pMxDoc.FocusMap.Layer[0] as IFeatureLayer;
            IDataset       pDS     = pFlayer.FeatureClass as IDataset;
            IWorkspaceEdit pWSE    = pDS.Workspace as IWorkspaceEdit;

            pWSE.StartEditing(false);
            pWSE.StartEditOperation();

            IFeature pFeature = pFlayer.FeatureClass.CreateFeature();

            pFeature.Shape = pPolygon;
            pFeature.Store();

            pWSE.StopEditOperation();
            pWSE.StopEditing(true);

            pMxDoc.ActiveView.Refresh();
        }
Beispiel #21
0
        public Button1()
        {
            mxdoc = ArcMap.Application.Document as IMxDocument;
            map   = mxdoc.FocusMap as IMap;
            IActiveViewEvents_Event evt = map as IActiveViewEvents_Event;

            evt.AfterDraw += (IDisplay disp, esriViewDrawPhase phase) =>
            {
                if (hasClicked && esriViewDrawPhase.esriViewForeground == phase)
                {
                    disp.StartDrawing(disp.hDC, Convert.ToInt16(esriScreenCache.esriNoScreenCache));
                    disp.SetSymbol(marker as ISymbol);
                    foreach (IPoint pc in pntclassList)
                    {
                        disp.DrawPoint(pc);
                    }
                    disp.FinishDrawing();
                }
            };

            IRgbColor color = new RgbColorClass();

            color.Red    = 255;
            color.Blue   = 0;
            color.Green  = 0;
            marker.Color = color;
        }
Beispiel #22
0
        public void OnCreate(object hook)
        {
            // TODO: Add CAddLayer.OnCreate implementation
            m_pApplication = hook as IApplication;
            m_pMxDoc       = (IMxDocument)m_pApplication.Document;
            m_pMap         = (IMap)m_pMxDoc.FocusMap;

            UID pUID = new UIDClass();

            pUID.Value   = "CoM_GISTools.CExtension";
            m_pExtension = (IExtensionConfig)m_pApplication.FindExtensionByCLSID(pUID);

            //// testing
            //if (m_pExtension.State == esriExtensionState.esriESEnabled)
            //    MessageBox.Show("CAddLayer::Enabled");
            //else if (m_pExtension.State == esriExtensionState.esriESDisabled)
            //    MessageBox.Show("CAddLayer::Disabled");
            //else
            //    MessageBox.Show("CAddLayer::Unavailable");

            m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream("CoM_GISTools.Images.addLayer.bmp"));    //("CoM_GISTools.AddLayer.CAddLayer.bmp"));
            if (m_bitmap != null)
            {
                m_bitmap.MakeTransparent(m_bitmap.GetPixel(1, 1));
                m_hBitmap = m_bitmap.GetHbitmap();
            }
        }
        private void RefreshView()
        {
            IMxDocument mxDocument2 = (IMxDocument)m_app.Document;

            if (mxDocument2 == null)
            {
                return;
            }

            IMap        map        = mxDocument2.FocusMap;
            IActiveView activeView = (IActiveView)map;

            if (activeView != null)
            {
                activeView.Refresh();
            }

            //refresh viewer window
            IApplicationWindows applicationWindows = m_app as IApplicationWindows;

            ISet mySet = applicationWindows.DataWindows;

            if (mySet != null)
            {
                mySet.Reset();
                IMapInsetWindow dataWindow = (IMapInsetWindow)mySet.Next();
                while (dataWindow != null)
                {
                    dataWindow.Refresh();
                    dataWindow = (IMapInsetWindow)mySet.Next();
                }
            }
        }
Beispiel #24
0
        public override void addSeperatorLine()
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            IMxDocument        pMxDoc       = (IMxDocument)ArcMap.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;

            try
            {
                ISimpleLineSymbol pLineSymbol = (ISimpleLineSymbol)oSpatialSubs.createSimpleLineSymbol(oSpatialSubs.createRGB(0, 0, 0), (this.XFactor * 2), esriSimpleLineStyle.esriSLSSolid);
                //oSpatialSubs.addLineToGraphicsContainer(pGC, pLineSymbol, (SPrintConst.MapFrame_XMax * this.XFactor), (SPrintConst.MapFrame_XMax * this.XFactor), (SPrintConst.MapFrame_YMin * this.YFactor), (SPrintConst.MapFrame_YMax * this.YFactor));
                oSpatialSubs.addLineToGraphicsContainer(pGC, pLineSymbol, (SPrintConst.MapFrame_XMax * this.XFactor), (SPrintConst.MapFrame_XMax * this.XFactor), (SPrintConst.Neatline_YMin * this.YFactor), (SPrintConst.Neatline_YMax * this.YFactor));

                addCenterLine();
                addBottomLine();

                pLineSymbol = null;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CLandscapeLayout:addSeperatorLine()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pMxDoc = null;
                pGC    = null;
            }
        }
Beispiel #25
0
        public static void ZoomToCurrentError(IMxDocument pMxDoc, double zoomingAdjust, IPoint pPoint)
        {
            IMap pMap = pMxDoc.FocusMap as IMap;
            IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
            //ILayer pLayer = null;
            //pLayer.Visible = false;
            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbol();
            IRgbColor           pLightGreen         = (IRgbColor) new RgbColor();

            pLightGreen.Red                  = 181;
            pLightGreen.Green                = 230;
            pLightGreen.Blue                 = 96;
            pSimpleMarkerSymbol.Color        = pLightGreen;
            pSimpleMarkerSymbol.Outline      = true;
            pSimpleMarkerSymbol.OutlineColor = pLightGreen;
            pSimpleMarkerSymbol.OutlineSize  = 2;
            pSimpleMarkerSymbol.Size         = 25;
            pSimpleMarkerSymbol.Style        = esriSimpleMarkerStyle.esriSMSCross;
            IMarkerElement pMarkerElement = (IMarkerElement) new MarkerElement();

            pMarkerElement.Symbol = pSimpleMarkerSymbol;
            IElement pElement = pMarkerElement as IElement;

            pElement.Geometry = pPoint as IGeometry;
            pGraphicsContainer.DeleteAllElements();
            pGraphicsContainer.AddElement(pElement, 0);

            // IEnvelope pExtent = Data.ErrorTable[Data.CurrentErrorIndex].Penvelope;
            // pExtent.Expand(zoomingAdjust, zoomingAdjust, true);
            IEnvelope pExtent = (IEnvelope) new Envelope();

            pExtent.PutCoords(pPoint.X - zoomingAdjust, pPoint.Y - zoomingAdjust, pPoint.X + zoomingAdjust, pPoint.Y + zoomingAdjust);
            pMxDoc.ActiveView.Extent = pExtent;
            pMxDoc.ActiveView.Refresh();
        }
Beispiel #26
0
        /// <summary>
        ///     Adds a black rectangle in the lower right corner area just below the mapframe. The white
        ///     text CITY OF MEDFORD is added on top of this rectangle.
        /// </summary>
        public override void addMedfordRectangle()
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            IMxDocument        pMxDoc       = (IMxDocument)ArcMap.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;

            try
            {
                ILineSymbol       pLineSym    = oSpatialSubs.createSimpleLineSymbol(oSpatialSubs.createRGB(0, 0, 0), base.XFactor, esriSimpleLineStyle.esriSLSSolid);
                ISimpleFillSymbol pFillSymbol = (ISimpleFillSymbol)oSpatialSubs.createSimpleFillSymbol(oSpatialSubs.createRGB(0, 0, 0), pLineSym, esriSimpleFillStyle.esriSFSSolid);

                oSpatialSubs.addRectangleToGraphicsContainer(pGC,
                                                             (IFillSymbol)pFillSymbol,
                                                             (base.XFactor * SPrintConst.MapFrame_XMax),
                                                             (base.XFactor * SPrintConst.Neatline_XMax),
                                                             (base.YFactor * (SPrintConst.Neatline_YMax - SPrintConst.Logo_Offset)),
                                                             (base.YFactor * SPrintConst.Neatline_YMax));
                pLineSym    = null;
                pFillSymbol = null;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CLandscapeLayout:addMedfordRectangle()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pMxDoc = null;
                pGC    = null;
            }
        }
Beispiel #27
0
        public override void addSeperatorLine()
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            IMxDocument        pMxDoc       = (IMxDocument)base.App.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;
            ISimpleLineSymbol  pLineSym     = null;

            try
            {
                pLineSym = (ISimpleLineSymbol)oSpatialSubs.createSimpleLineSymbol(oSpatialSubs.createRGB(0, 0, 0), (2 * base.XFactor), esriSimpleLineStyle.esriSLSSolid);
                oSpatialSubs.addLineToGraphicsContainer(pGC, pLineSym,
                                                        (SPrintConst.Neatline_XMin * base.XFactor),
                                                        (SPrintConst.Neatline_XMax * base.XFactor),
                                                        (SPrintConst.Neatline_YMin * base.YFactor),
                                                        (SPrintConst.Neatline_YMin * base.YFactor));
                addRightOfTitleLine();
                addLeftLine();
                addCenterLine();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:addSeperatorLine()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pMxDoc   = null;
                pGC      = null;
                pLineSym = null;
            }
        }
Beispiel #28
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            base.OnMouseDown(arg);


            IMxDocument        pMxdoc = ArcMap.Application.Document as IMxDocument;
            IPoint             pPoint = pMxdoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
            IGraphicsContainer pGC    = pMxdoc.ActiveView.GraphicsContainer;

            IElement       pElement       = new MarkerElement();
            IMarkerElement pMarkerElement = pElement as IMarkerElement;

            ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol();

            pMarkerSymbol.Size = 10;

            IRgbColor pColor = new RgbColor();

            pColor.Red   = 255;
            pColor.Green = 0;
            pColor.Blue  = 0;

            pMarkerSymbol.Color = pColor;

            pMarkerElement.Symbol = pMarkerSymbol;
            pElement.Geometry     = pPoint;


            pGC.AddElement(pElement, 0);
            pMxdoc.ActiveView.Refresh();
        }
Beispiel #29
0
 /// <summary>
 /// 初始化函数
 /// </summary>
 /// <param name="value">主窗体</param>
 /// <param name="Filename">保存文件路径</param>
 public Analize_ArcMap_Symbols(string Filename, IMxDocument mxDoc, WriteConverterLogDelegate WriteLog)
 {
     m_cFilename = Filename;
     m_ObjDoc    = mxDoc;
     m_WriteLog  = WriteLog;
     //CentralProcessingFunc();
 }
Beispiel #30
0
        private Dictionary <string, string> exportAllImages()
        {
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;
            //IActiveView pActiveView = pMxDoc.ActiveView;
            var dict = new Dictionary <string, string>();

            // Get the path and file name to pass to the various functions
            string exportPathFileName = getExportPathFileName(tbxExportZipPath.Text, tbxMapDocument.Text);

            //check to see variable exists
            if (!Directory.Exists(@tbxExportZipPath.Text) || tbxMapDocument.Text == "" || tbxMapDocument.Text == string.Empty)
            {
                Debug.WriteLine("Image export variables not valid.");
                return(dict);
            }
            else
            {
                //Output 3 image formats pdf, jpeg & emf
                dict.Add("pdf", MapAction.MapExport.exportImage(pMxDoc, "pdf", nudPdfResolution.Value.ToString(), exportPathFileName, null));
                dict.Add("jpeg", MapAction.MapExport.exportImage(pMxDoc, "jpeg", nudJpegResolution.Value.ToString(), exportPathFileName, null));
                dict.Add("emf", MapAction.MapExport.exportImage(pMxDoc, "emf", nudEmfResolution.Value.ToString(), exportPathFileName, null));
                MapAction.MapExport.exportImage(pMxDoc, "emf", nudEmfResolution.Value.ToString(), exportPathFileName, "Main map");
                MapAction.MapExport.exportImage(pMxDoc, "jpeg", nudEmfResolution.Value.ToString(), exportPathFileName, "Main map");
            }

            return(dict);
        }
Beispiel #31
0
        protected override void OnClick()
        {
            //Check if 'Main map' frame exists.  If not show a message box telling the user so. Don't open GUI.
            //if (!PageLayoutProperties.detectMainMapFrame())
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

            if (!MapAction.PageLayoutProperties.detectMapFrame(pMxDoc, "Main map"))
            {
                MessageBox.Show("This tool only works with the MapAction mapping templates.  The 'Main map' map frame could not be detected. Please load a MapAction template and try again.", "Invalid map template",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (!MapAction.Utilities.detectOperationConfig())
            {
                MessageBox.Show("The operation configuration file is required for this tool.  It cannot be located.",
                                "Configuration file required", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (MapAction.PageLayoutProperties.checkLayoutTextElementsForDuplicates(pMxDoc, "Main map"))
            {
                MessageBox.Show("Duplicate named elements have been identified in the layout. Please remove duplicate element names before trying again.", "Invalid map template",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (MapAction.PageLayoutProperties.detectMapFrame(pMxDoc, "Main map"))
            {
                var dlg = new frmMain();
                dlg.ShowDialog();
            }
        }
Beispiel #32
0
 /// <summary>
 /// Gets the full path name of the layer (including ancestor group layers and data frame)
 /// </summary>
 /// <param name="doc">The map document that this layer is in</param>
 /// <param name="layer">The ILayer whose name we want</param>
 /// <param name="mapSeparator">A character string used to data frame name from the group/layer names</param>
 /// <param name="layerSeparator">A character string used to the group names from the layer name</param>
 /// <returns>null if the layer does not exist in the map document, full name otherwise</returns>
 internal static string GetFullName(IMxDocument doc, ILayer layer, string mapSeparator = ":",
                                    string layerSeparator = "/")
 {
     IMaps maps = doc.Maps;
     for (int i = 0; i < maps.Count; i++)
     {
         IMap map = maps.Item[i];
         string name = GetFullName(map, layer, layerSeparator);
         if (name != null)
         {
             return map.Name + mapSeparator + name;
         }
     }
     return null;
 }
Beispiel #33
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public List<IElement> addMapSurroundM(IMxDocument pMxDoc, string nombreLayer, string campoLayer, string campoLayer2, double x, double x2,ref  List<IElement> pElem)
        {
            List<objetos> clave_zona = null;
            string clave = null;
            string[] arrayTmp = null;
            int j = 0;
            int i;
            IFeatureClass fc = default(IFeatureClass);
            int n = 0;
            double y = 0;
               // = new List<IElement>();
            fc = B.returnFeatureLayerByName(ArcMap.Document, nombreLayer).FeatureClass;
            try {
                clave_zona = lTools.returMatrizDataUnique(fc, campoLayer, campoLayer2);
                n = clave_zona.Count();
                y = 35.07;
                j = 0;
                for (i = 0; i <n; i++) {
                    Array.Resize(ref arrayTmp, i + 1);
                    arrayTmp[i] = clave_zona[i].clave;

                }
                System.Array.Sort(arrayTmp);
                vDiccionario v = new vDiccionario(clave_zona);
                for (i = 0; i < n; i++) {
                    //Array.Resize(ref pElem, j + 1);
                    clave = v.sayValorZ(arrayTmp[i]);
                    clave = "0";
                    clave = funcAux.convierteaMoneda(clave);
                    IElement m = addTitleToLayout(pMxDoc, 7.5, x2, y, (IGraphicsContainer)pMxDoc.PageLayout, false, clave);
                    pElem.Add(m);
                    j = j + 1;
                    y = y - 1.532;
                }
                return pElem;
            } catch (System.Exception ex) {
                MessageBox.Show("Error: " + ex.Message, "clsMapTools.addMapSurroundM");
                MessageBox.Show("Error: " + ex.StackTrace);
                return null;
            }
        }
Beispiel #34
0
        /// <summary>
        /// Gets all layers in a map document of a particular type 
        /// </summary>
        /// <param name="doc">The map document to search</param>
        /// <param name="type">A GUID type string for the layer type. see http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Loop_Through_Layers_of_Specific_UID_Snippet/00490000005w000000/ </param>
        /// <returns>a list (possibly empty) of layer that were found to match the type requested</returns>
        internal static IEnumerable<ILayer> GetAllLayers(IMxDocument doc, string type)
        {
            if (doc == null)
                throw new ArgumentNullException("doc");
            if (type == null)
                throw new ArgumentNullException("type");

            UID uid = new UIDClass();
            uid.Value = type;
            IMaps maps = doc.Maps;
            for (int i = 0; i < maps.Count; i++)
            {
                IMap map = maps.Item[i];
                IEnumLayer elayers = map.Layers[uid];
                ILayer layer = elayers.Next();
                while (layer != null)
                {
                    yield return layer;
                    layer = elayers.Next();
                }
            }
        }
Beispiel #35
0
        public Button1()
        {
            mxdoc = ArcMap.Application.Document as IMxDocument;
            map = mxdoc.FocusMap as IMap;
            IActiveViewEvents_Event evt = map as IActiveViewEvents_Event;
            evt.AfterDraw += (IDisplay disp, esriViewDrawPhase phase) =>
                {
                    if (hasClicked && esriViewDrawPhase.esriViewForeground == phase)
                    {
                        disp.StartDrawing(disp.hDC, Convert.ToInt16(esriScreenCache.esriNoScreenCache));
                        disp.SetSymbol(marker as ISymbol);
                        foreach (IPoint pc in pntclassList)
                            disp.DrawPoint(pc);
                        disp.FinishDrawing();
                    }
                };

            IRgbColor color = new RgbColorClass();
            color.Red = 255;
            color.Blue = 0;
            color.Green = 0;
            marker.Color = color;
        }
    /// <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_comboBoxHook = hook as IComboBoxHook;

      IApplication application = m_comboBoxHook.Hook as IApplication;
      m_doc = application.Document as IMxDocument;

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

    }
Beispiel #37
0
 private void initiliaze()
 {
     _application = this.Hook as IApplication;
     _mxdocument = (IMxDocument)_application.Document;
     _map = _mxdocument.FocusMap;
     ActiveViewEventTracking();
 }
    public void Startup(ref object initializationData)
    {
      m_application = initializationData as IApplication;
      if (m_application == null)
        return;

      m_doc = m_application.Document as IMxDocument;

      //Get dockable window.
      IDockableWindowManager dockableWindowManager = m_application as IDockableWindowManager;
      UID dockWinID = new UIDClass();
      dockWinID.Value = @"SelectionCOMSample.SelectionCountDockWin";
      s_dockWindow = dockableWindowManager.GetDockableWindow(dockWinID);

      //Wire up events.
      IDocumentEvents_Event docEvents = m_doc as IDocumentEvents_Event;
      docEvents.NewDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(ArcMap_NewOpenDocument);
      docEvents.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(ArcMap_NewOpenDocument);

    }
Beispiel #39
0
 public Form1()
 {
     InitializeComponent();
     pMxdocument = ArcMap.Document;
     pmap = pMxdocument.FocusMap;
 }
        private void ExportTable(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IStandaloneTable StandTable, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor)
        {
            ITableProperties TableProperties = null;
            IEnumTableProperties EnumTableProperties = null;
            ITableProperty3 TableProperty = null;
            ITableCharacteristics TableCharacteristics = null;
            ITableSelection TabSel = null;
            IDisplayTable DisplayTable = null;
            ITable Table = null;
            IRow TabRow = null;
            IObjectClass ObjectClass = null;
            ISubtypes Subtypes = null;
            ITableFields TableFields = null;

            ICursor Cursor = null;
            IField CurField = null;
            IDomain Domain = null;
            ICodedValueDomain CodedValueDomain = null;

            object missing = null;
            object sheet = null;
            Microsoft.Office.Interop.Excel.Style style = null;

            try
            {
                bool UseDescriptions;
                int subtype;
                string SheetName;

                int Col = 0;
                int Row = 0;
                int i;
                int j;

                missing = System.Reflection.Missing.Value;

                sheet = ExcelWbk.Sheets[ExcelWbk.Sheets.Count];
                Excel.Worksheet ExcelSheet;
                Excel.Range ExcelRange;

                //Add new Excel worksheet
                ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing);
                //style = ExcelWbk.Styles.Add("Style1");
                //style.NumberFormat = "@";
                //style.Font.Name = "Arial";
                //style.Font.Bold = True
                //style.Font.Size = 12;
                //style.Interior.Pattern = Microsoft.Office.Interop.Excel.XlPattern.xlPattern Solid
                //style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlighLe ft

                SheetName = StandTable.Name;
                if (SheetName.Length > 30)
                {
                    SheetName = SheetName.Substring(0, 30);
                }
                ExcelSheet.Name = SheetName;

                //Determine whether to use descriptions or codes for domains
                UseDescriptions = true;
                TableProperties = MxDoc.TableProperties;
                EnumTableProperties = (IEnumTableProperties)TableProperties;
                EnumTableProperties.Reset();
                TableProperty = (ITableProperty3)EnumTableProperties.Next();

                while (TableProperty != null)
                {
                    if (TableProperty.StandaloneTable != null)
                    {
                        if (TableProperty.StandaloneTable.Equals(StandTable))
                        {
                            TableCharacteristics = (ITableCharacteristics)TableProperty;
                            UseDescriptions = TableCharacteristics.ShowCodedValueDomainDescriptions;
                            break;
                        }
                    }
                    TableProperty = (ITableProperty3)EnumTableProperties.Next();
                }
                TabSel = (ITableSelection)StandTable;

                DisplayTable = (IDisplayTable)StandTable;
                Table = (ITable)DisplayTable.DisplayTable;

                //Get subtype info
                ObjectClass = Table as IObjectClass;
                Subtypes = ObjectClass as ISubtypes;

                //Get TableFields so later we can determine whether that field is visible
                TableFields = (ITableFields)StandTable;

                //loop through each field and write column headings
                Row = 1;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Write field alias name as Excel column header
                        ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias;
                        if (CurField.Type == esriFieldType.esriFieldTypeString)
                            ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@";

                    }
                }

                //Get all selected records for this table (use IDisplayTable to get any joined data)
                DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor);

                //subtype = Subtypes.DefaultSubtypeCode;

                //For each selected record

                TabRow = Cursor.NextRow();
                //stepProgressor.Step();
                //     progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                while (TabRow != null)
                {
                    Row += 1;

                    if (Subtypes != null && Subtypes.HasSubtype == true &&
                       (TabRow.get_Value(Subtypes.SubtypeFieldIndex) != null))
                    {
                        subtype = Convert.ToInt32(TabRow.get_Value(Subtypes.SubtypeFieldIndex));
                    }
                    else
                    {
                        subtype = -99999;
                    }

                    //For each column
                    Col = 0;
                    for (j = 0; j < TableFields.FieldCount; j++)
                    {
                        CurField = TableFields.get_Field(j);

                        //skip blob and geometry fields in data also
                        if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                        {
                            Col += 1;
                            ExcelSheet.Cells[Row, Col] = TabRow.get_Value(j);

                            if (UseDescriptions == true && subtype == -99999)
                            {
                                Domain = CurField.Domain;
                                if (Domain != null)
                                {
                                    if (Domain.Type == esriDomainType.esriDTCodedValue)
                                    {
                                        CodedValueDomain = (ICodedValueDomain)CurField.Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (UseDescriptions == true && subtype != -99999)
                            {
                                if (Subtypes.SubtypeFieldIndex == j)
                                {
                                    ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype);
                                }
                                else
                                {
                                    Domain = Subtypes.get_Domain(subtype, CurField.Name);
                                    if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue))
                                    {
                                        CodedValueDomain = (ICodedValueDomain)Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (TabRow.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    stepProgressor.Step();
                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                    TabRow = Cursor.NextRow();
                }

                //Hide Columns
                Col = 0;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields in data also
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Autofit
                        ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                        ExcelRange.EntireColumn.AutoFit();

                        //Hide column if invisible in ArcMap
                        if (TableFields.get_FieldInfo(j).Visible == false)
                        {
                            ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                            ExcelRange.EntireColumn.Hidden = true;
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError"));

            }
            finally
            {
                TableProperties = null;
                EnumTableProperties = null;
                TableProperty = null;
                TableCharacteristics = null;
                TabSel = null;
                DisplayTable = null;
                Table = null;
                TabRow = null;
                ObjectClass = null;
                Subtypes = null;
                TableFields = null;

                if (Cursor != null)
                    Marshal.ReleaseComObject(Cursor);
                Cursor = null;
                CurField = null;
                Domain = null;
                CodedValueDomain = null;

                missing = null;
                sheet = null;
                style = null;

            }
        }
        private void ExportLayer(Excel.Workbook ExcelWbk, IMxDocument MxDoc, IFeatureLayer FLayer, ref IProgressDialog2 progressDialog, ref IStepProgressor stepProgressor)
        {
            IFeatureClass FC = null;
            ISubtypes Subtypes = null;

            ITableProperties TableProperties = null;
            IEnumTableProperties EnumTableProperties = null;
            ITableProperty3 TableProperty = null;
            ITableCharacteristics TableCharacteristics = null;
            IFeatureSelection FeatSel = null;
            IDisplayTable DisplayTable = null;
            ITable Table = null;
            ILayerFields LayerFields = null;
            ITableFields TableFields = null;
            ILayer LayerTest = null;

            ICursor Cursor = null;
            IFeatureCursor FCursor = null;
            IField CurField = null;
            IDomain Domain = null;
            ICodedValueDomain CodedValueDomain = null;
            IFeature Feat = null;
            List<IPoint> pGeo = null;

            object missing = null;
            object sheet = null;
            Excel.Worksheet ExcelSheet = null;
            Excel.Range ExcelRange = null;
            Microsoft.Office.Interop.Excel.Style style = null;

            try
            {

                int Col = 0;
                int Row = 0;
                int i;
                int j;
                bool UseDescriptions;
                int subtype;
                string SheetName;

                missing = System.Reflection.Missing.Value;
                sheet = ExcelWbk.Sheets[ExcelWbk.Sheets.Count];

                //Add new Excel worksheet
                ExcelSheet = (Excel.Worksheet)ExcelWbk.Sheets.Add(missing, sheet, missing, missing);
                SheetName = FLayer.Name;
                if (SheetName.Length > 30)
                {
                    SheetName = SheetName.Substring(0, 30);
                }
                ExcelSheet.Name = SheetName;

                //style = ExcelWbk.Styles.Add("Style1");
                //style.NumberFormat = "@";

                LayerTest = (ILayer)FLayer;

                //Get Subtype info
                FC = FLayer.FeatureClass;
                Subtypes = FC as ISubtypes;
                //Determine whether to use descriptions or codes for domains and subtypes
                UseDescriptions = true;
                TableProperties = MxDoc.TableProperties;
                EnumTableProperties = (IEnumTableProperties)TableProperties;
                EnumTableProperties.Reset();
                TableProperty = (ITableProperty3)EnumTableProperties.Next();
                while (TableProperty != null && TableProperty.Layer != null)  //Fixed
                {
                    if (TableProperty.Layer.Equals(LayerTest))
                    {
                        TableCharacteristics = (ITableCharacteristics)TableProperty;
                        UseDescriptions = TableCharacteristics.ShowCodedValueDomainDescriptions;
                    }
                    TableProperty = (ITableProperty3)EnumTableProperties.Next();
                }
                FeatSel = (IFeatureSelection)FLayer;

                DisplayTable = (IDisplayTable)FLayer;
                Table = (ITable)DisplayTable.DisplayTable;

                //Get TableFields so later we can determine whether that field is visible
                LayerFields = (ILayerFields)FLayer;
                TableFields = (ITableFields)FLayer;

                //loop through each field and write column headings
                Row = 1;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Write field alias name as Excel column header
                        ExcelSheet.Cells[Row, Col] = TableFields.get_FieldInfo(j).Alias;
                        if (CurField.Type == esriFieldType.esriFieldTypeString)
                            ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[65535, Col]).EntireColumn.NumberFormat = "@";

                    }
                }
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "X_COORD";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Y_COORD";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Lat";
                Col += 1;
                ExcelSheet.Cells[Row, Col] = "Long";
                IField pFieldTest = FLayer.FeatureClass.Fields.get_Field(FLayer.FeatureClass.Fields.FindField(FLayer.FeatureClass.ShapeFieldName));
                IGeometryDef pGeometryDefTest = null;
                pGeometryDefTest = pFieldTest.GeometryDef;
                bool bZAware = false;
                bool bMAware = false;
                //Determine if M or Z aware
                if (pGeometryDefTest.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    bZAware = pGeometryDefTest.HasZ;
                    bMAware = pGeometryDefTest.HasM;
                }
                if (bZAware)
                {
                    Col += 1;
                    ExcelSheet.Cells[Row, Col] = "Z_COORD";
                }
                pFieldTest = null;
                pGeometryDefTest = null;
                //Get all selected records for this table (use IDisplayTable to get any joined data)
                DisplayTable.DisplaySelectionSet.Search(null, true, out Cursor);
                FCursor = (IFeatureCursor)Cursor;

                //subtype = Subtypes.DefaultSubtypeCode;

                //For each selected record

                Feat = FCursor.NextFeature();
                //  stepProgressor.Step();
                // progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                while (Feat != null)
                {
                    Row += 1;

                    if (Subtypes != null && Subtypes.HasSubtype == true &&
                       (Feat.get_Value(Subtypes.SubtypeFieldIndex) != null))
                    {
                        subtype = Convert.ToInt32(Feat.get_Value(Subtypes.SubtypeFieldIndex));
                    }
                    else
                    {
                        subtype = -99999;
                    }

                    //For each column
                    Col = 0;
                    for (j = 0; j < TableFields.FieldCount; j++)
                    {
                        CurField = TableFields.get_Field(j);

                        //skip blob and geometry fields in data also
                        if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                        {
                            Col += 1;
                            ExcelSheet.Cells[Row, Col] = Feat.get_Value(j);

                            if (UseDescriptions == true && subtype == -99999)
                            {
                                Domain = CurField.Domain;
                                if (Domain != null)
                                {
                                    if (Domain.Type == esriDomainType.esriDTCodedValue)
                                    {
                                        CodedValueDomain = (ICodedValueDomain)CurField.Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (UseDescriptions == true && subtype != -99999)
                            {
                                if (Subtypes.SubtypeFieldIndex == j)
                                {
                                    ExcelSheet.Cells[Row, Col] = Subtypes.get_SubtypeName(subtype);
                                }
                                else
                                {
                                    Domain = Subtypes.get_Domain(subtype, CurField.Name);
                                    if ((Domain != null) && (Domain.Type == esriDomainType.esriDTCodedValue))
                                    {
                                        CodedValueDomain = (ICodedValueDomain)Domain;
                                        for (i = 0; i < CodedValueDomain.CodeCount; i++)
                                        {
                                            if ((CodedValueDomain.get_Value(i)).ToString() == (Feat.get_Value(j)).ToString())
                                            {
                                                //System.Diagnostics.Debug.Print(CodedValueDomain.get_Name(0).ToString());
                                                ExcelSheet.Cells[Row, Col] = CodedValueDomain.get_Name(i);
                                                i = CodedValueDomain.CodeCount;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (Feat.Shape != null)
                    {
                        if (Feat.Shape.IsEmpty == false)
                        {
                            pGeo = Globals.GetGeomCenter(Feat.Shape);
                            if (pGeo != null)
                            {

                                if (pGeo.Count > 0)
                                {
                                    if (pGeo[0].X != null)
                                        ExcelSheet.Cells[Row, Col + 1] = pGeo[0].X;
                                    if (pGeo[0].Y != null)
                                        ExcelSheet.Cells[Row, Col + 2] = pGeo[0].Y;
                                    if (pGeo[0] != null)
                                    {
                                        pGeo[0].Project(srWGS84);

                                        ExcelSheet.Cells[Row, Col + 3] = pGeo[0].Y;
                                        ExcelSheet.Cells[Row, Col + 4] = pGeo[0].X;
                                    }
                                    if (bZAware)
                                    {

                                        ExcelSheet.Cells[Row, Col + 5] = pGeo[0].Z;
                                    }
                                }
                            }
                        }
                    }

                    stepProgressor.Step();
                    progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + stepProgressor.Position + A4LGSharedFunctions.Localizer.GetString("Of") + MxDoc.FocusMap.SelectionCount.ToString() + ".";

                    Feat = FCursor.NextFeature();
                }

                //Hide Columns
                Col = 0;
                for (j = 0; j < TableFields.FieldCount; j++)
                {
                    CurField = TableFields.get_Field(j);

                    //skip blob and geometry fields in data also
                    if ((CurField.Type != esriFieldType.esriFieldTypeBlob) && (CurField.Type != esriFieldType.esriFieldTypeGeometry))
                    {
                        Col += 1;
                        //Autofit
                        ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                        ExcelRange.EntireColumn.AutoFit();

                        //Hide column if invisible in ArcMap
                        if (TableFields.get_FieldInfo(j).Visible == false)
                        {
                            ExcelRange = ExcelSheet.get_Range(ExcelSheet.Cells[1, Col], ExcelSheet.Cells[Row, Col]);
                            ExcelRange.EntireColumn.Hidden = true;
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ExportXLError"));

            }
            finally
            {
                FC = null;
                Subtypes = null;

                TableProperties = null;
                if (EnumTableProperties != null)
                    Marshal.ReleaseComObject(EnumTableProperties);

                EnumTableProperties = null;
                TableProperty = null;
                TableCharacteristics = null;
                FeatSel = null;
                DisplayTable = null;
                Table = null;
                LayerFields = null;
                TableFields = null;
                LayerTest = null;
                if (Cursor != null)
                    Marshal.ReleaseComObject(Cursor);
                Cursor = null;

                if (FCursor != null)
                    Marshal.ReleaseComObject(FCursor);
                FCursor = null;
                CurField = null;
                Domain = null;
                CodedValueDomain = null;
                Feat = null;
                pGeo = null;

                missing = null;
                sheet = null;
                ExcelSheet = null;
                ExcelRange = null;
                style = null;

            }
        }
Beispiel #42
0
        /// <summary>
        /// Adds ArcGIS layer to map
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="strServer"></param>
        /// <param name="strLayerName"></param>
        /// <param name="strSecretName"></param>
        /// <returns></returns>
        private bool addLayerAGS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName)
        {
            IPropertySet2 pProps = null;
            string pServerUrl;
            string strServerObj;

            pServerUrl = GetAGSServiceUrl(strServer);

            // connect to the GIS server
            IAGSServerConnectionFactory pAGSServerConnectionFactory = new AGSServerConnectionFactory();
            pProps = (IPropertySet2)new PropertySet();
            pProps.SetProperty("URL", pServerUrl);

            IAGSServerConnection pAGSConnection = pAGSServerConnectionFactory.Open(pProps, 0);

            //get server objectname from url
            strServerObj = GetServerObjectName(strServer);

            // enumerate over server objects
            IAGSEnumServerObjectName pAGSSObjs = pAGSConnection.ServerObjectNames;
            IAGSServerObjectName pAGSSObj = pAGSSObjs.Next();

            while (pAGSSObj != null)
            {
                if (pAGSSObj.Type == "MapServer" && pAGSSObj.Name == strServerObj)
                {
                    break;
                }
                pAGSSObj = pAGSSObjs.Next();
            }

            IName pName = (IName)pAGSSObj;
            IAGSServerObject pAGSO = (IAGSServerObject)pName.Open();
            IMapServer mapServer = (IMapServer)pAGSO;

            IPropertySet prop = new PropertySetClass();
            prop.SetProperty("URL", pServerUrl);
            prop.SetProperty("Name", pAGSSObj.Name);

            //Create new layer
            IMapServerLayer pMSLayer = (IMapServerLayer)new MapServerLayer();
            pMSLayer.ServerConnect(pAGSSObj, mapServer.DefaultMapName);

            if (!isMapServerAdded(strServer))
            {
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
                IMap ipMap = ipMxDoc.FocusMap;
                ipMap.AddLayer((ILayer)pMSLayer);
                logger.writeLog(StringResources.AddAGSLayer + strSecretName);
            }
            else
            {
                // set visibility
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
            }

            //add to the service list
            string strItem = EncodeServiceList(strServer, strLayerName, strSecretName);

            // m_pLogger.Msg "adding to service list : " & strItem
            colServiceList.Add(strItem);

            //set flag
            logger.writeLog("strServer = " + strServer + " strServer & strLayerName = " + strServer + strLayerName);
            return true;
        }
Beispiel #43
0
        public IElement addTitleToLayout(IMxDocument pMxDoc,double S, double x, double y,  IGraphicsContainer pGc, bool b, string texto)
        {
            ITextElement pTxtElem;
            ITextSymbol pTxtSym = default(ITextSymbol);
            IRgbColor myColor = default(IRgbColor);
            stdole.IFontDisp myFont;
            IElement pElem;
            IEnvelope pEnv;
            IPoint pPoint = default(IPoint);
            try{
                // pGc.Reset()
                //Set the font and color properties
                //for the title
                myFont = (stdole.IFontDisp)new stdole.StdFont();
                myFont.Name = "Times New Roman";
                myFont.Bold = b;
               // myFont.Size = S;
                myColor = new RgbColor();
                myColor.Red = 0;
                myColor.Green = 0;
                myColor.Blue = 0;
                ///''''''''''''''''''''''''''''''
                //Create a text element
                pTxtElem = (ITextElement)new TextElement();

                //Create a text symbol
                pTxtSym = new TextSymbol();
                pTxtSym.Color = myColor;
                pTxtSym.Font = myFont;
                pTxtSym.Size = S;
                //Set symbol property
                pTxtElem.Symbol = pTxtSym;

                //set the text property to be the layer's name (Uppercase)
                pTxtElem.Text = texto;

                //Create an envelope for the TextElements Geometry
                pEnv = (IEnvelope)new Envelope();
                pPoint = new ESRI.ArcGIS.Geometry.Point();

                pPoint.X = x;
                pPoint.Y = y;
                pEnv.LowerLeft = pPoint;
                pPoint.X = 1;
                pPoint.Y = 1;
                pEnv.UpperRight = pPoint;
                //set the text elements geomtery
                pElem = (IElement)pTxtElem;
                pElem.Geometry = pEnv;

                //Add the element to the graphics container
                pGc.AddElement(pElem, 1);
                pMxDoc.ActiveView.Refresh();
                return (pElem);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "clsMapTools.addTitleToLayout");
                MessageBox.Show("Error: " + ex.StackTrace);
                return null ;
            }
        }
        protected override void OnShutdown()
        {
            Uninitialize();

            if (m_docEvents != null)
            {
                m_docEvents.NewDocument -= new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(ArcMap_NewOpenDocument);
                m_docEvents.OpenDocument -= new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(ArcMap_NewOpenDocument);
            }

            m_pApp = null;
            m_pDoc = null;
            m_docEvents = null;
            s_extension = null;

            base.OnShutdown();
        }
Beispiel #45
0
        public void ActivateDocumentEvents()
        {
            this.doc_close = new IDocumentEvents_CloseDocumentEventHandler(StoreTransactionToMap);
            this.new_doc = new IDocumentEvents_NewDocumentEventHandler(LoadTransactionFromMap);
            this.open_doc = new IDocumentEvents_OpenDocumentEventHandler(LoadTransactionFromMap);

            _pMxDoc = this._app.Document as IMxDocument;

            IDocumentEvents_Event ide = _pMxDoc as IDocumentEvents_Event;

            ide.CloseDocument += this.doc_close;
            ide.NewDocument += this.new_doc;
            ide.OpenDocument += this.open_doc;
        }
Beispiel #46
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public List<IElement> discrimaDatosLayer(string n_municipio, string n_plano, string t_plano, IMxDocument pMxDoc, ILayer municipios, ILayer seleccion, ILayer zona, ILayer calles)
        {
            // clsGeoTools arcpy =new clsGeoTools();
            //IElement[] functionReturnValue = null;
            ILayer MANZANAS;
            List<IElement> pElem = new List<IElement>();
            List<IElement> pElemU = new List<IElement>();
            ArrayList nom_plano = null;
            IMap pMap = pMxDoc.FocusMap;
             //  ILayer municipio = default(ILayer);
            ILayer zonasValor = default(ILayer);
            ILayer seleccionZona = default(ILayer);
            ILayer manzana;
            string p;
            int n = 17;
            MANZANAS = B.returnLayerByName(ArcMap.Document, "MANZANAS");
            try {
                nom_plano = (B.returnFieldData( B.returnFeatureLayerByName(ArcMap.Document, "municipio").FeatureClass, "nombre"));
                foreach (string itm in funcAux.StatUnique(nom_plano)){
                    nomPlano = itm;
                    p = funcAux.checaPalabra(nomPlano,n);
                    //MessageBox.Show(p, nomPlano);
                    if (p.Length >n)
                        pElem.Add( addTitleToLayout(pMxDoc, 9/*10*/, 74, 47.2, (IGraphicsContainer)pMxDoc.PageLayout, true, p.ToUpper())) ;
                    else
                        pElem.Add(addTitleToLayout(pMxDoc, 9/*10*/, 74, 48, (IGraphicsContainer)pMxDoc.PageLayout, true, p.ToUpper()));
                    break;
                }

                G.selectLayerByAttribute(seleccion, "municipio = " + n_municipio + " AND n_plano = " + n_plano, true);
                G.copyFeatures(seleccion, globales.gdb + "seleccionZona");
               // G.selectClip(seleccion, municipio, globales.gdb + "seleccionZona");
               /*Inserta el numero del plano*/
                pElem.Add( addTitleToLayout(pMxDoc, 6.0, 74.3, 9, (IGraphicsContainer)pMxDoc.PageLayout, false, n_plano + "   de   " + t_plano));
                seleccionZona = B.returnLayerByName(ArcMap.Document, "seleccionZona");

                G.selectClip(zona, seleccionZona, globales.gdb + "zonasValor");
                //B.limpiarZonasTmp(ArcMap.Document, "municipio");
                zonasValor = B.returnLayerByName(ArcMap.Document, "zonasValor");
                // estilado ZonaValor
                G.applySymbologyFromLayer(zonasValor, zona);
                /*Inserta los valores de las zonas*/
               // addMapSurroundM(pMxDoc, "zonasValor", "clave_zona", "Valor", 72.299, 76.00,ref pElem);
               	pMap.ClearSelection();
                G.selectClip(MANZANAS, zonasValor, globales.gdb + "manzana");
                //G.selectClip(calles, seleccionZona, globales.gdb + "calle");
                manzana = B.returnLayerByName(ArcMap.Document, "manzana");
                G.applySymbologyFromLayer(manzana, MANZANAS);
                pMap.ClearSelection();
                B.limpiarZonasTmp(ArcMap.Document, "seleccionZona");
                /******************************************Genera el macro mapa******************************************************/
                IMapDocument pMapDoc = new MapDocumentClass();
                IMap pMap2 = pMxDoc.Maps.get_Item(1);

                pMxDoc.ActiveView = (IActiveView)pMap2;
                string mun = "municipio";
                ILayer SELECCION = B.returnLayerByName(ArcMap.Document, mun);
                G.selectLayerByAttribute(SELECCION, "municipio = " + n_municipio, true);

                B.zoomToSeleccion(pMxDoc, mun);
                pMap2.MapScale *= (1.12);
                pMap2.ClearSelection();

                pMxDoc.ActiveView.Refresh();
                pMap = pMxDoc.Maps.get_Item(0);
                pMxDoc.ActiveView = (IActiveView)pMap;
                pMxDoc.ActiveView = (IActiveView)pMxDoc.PageLayout;
                /******************************************Fin de el macro mapa******************************************************/
                return pElem;
            } catch (System.Exception ex) {
                MessageBox.Show("Error: " + ex.Message, "clsMapTools.discrimaDatosLayer");
                MessageBox.Show("Error: " + ex.StackTrace);
                return null;
            }
        }
Beispiel #47
0
 public void ToggleActiveView(IMxDocument pMxDoc)
 {
     if (!(pMxDoc.ActiveView is IPageLayout))
         pMxDoc.ActiveView = (IActiveView)pMxDoc.PageLayout;
 }
Beispiel #48
0
 public void zoomToCapaPageLayout(IMxDocument pMxDoc)
 {
     // double escalaD = 0;
        // long escala = 0;
     try{
         IMap pMap = pMxDoc.FocusMap;
         pMap.MapScale *= (1.108);//crea un zoomout de +12%
        /* escalaD = pMap.MapScale;
         escala = funcAux.redondea(Convert.ToInt64(escalaD), 1, 1000);
         pMap.MapScale = escala;*/
     }catch (System.Exception ex){
         MessageBox.Show("Error: " + ex.Message, "zoomToCapaPageLayout");
         MessageBox.Show("Error: " + ex.StackTrace);
     }
 }
        private void Initialize()
        {
            // If the extension hasn't been started yet or it's been turned off, bail
            if (s_extension == null || this.State != ExtensionState.Enabled)
                return;

            m_pApp = ArcMap.Application;
            m_pDoc = ArcMap.Document;

            SF10_clsBase.p_tNAIPF_EssPourc_1 = new SF10_clsBase.tNAIPF_EssPourc[7];
            SF10_clsBase.p_tNAIPF_EssPourc_2 = new SF10_clsBase.tNAIPF_EssPourc[7];

            for (int i = 0; i < 7; i++)
            {
                SF10_clsBase.p_tNAIPF_EssPourc_1[i] = new SF10_clsBase.tNAIPF_EssPourc();
                SF10_clsBase.p_tNAIPF_EssPourc_2[i] = new SF10_clsBase.tNAIPF_EssPourc();
            }

            m_Parametres = SF10_clsParametres.SF10_clsParametresDefData();

            try
            {
                UID editorUid = new UIDClass();
                editorUid.Value = "esriEditor.Editor";
                IEditor m_pEditor = m_pApp.FindExtensionByCLSID(editorUid) as IEditor;

                m_editorEvents = m_pEditor as IEditEvents_Event;
                IEditEvents_OnSelectionChangedEventHandler editEvents_OnSelectionChangedEventHandler = new IEditEvents_OnSelectionChangedEventHandler(this.Editor_OnSelectionChanged);
                m_editorEvents.OnSelectionChanged += editEvents_OnSelectionChangedEventHandler;

                m_activeViewEvents = ArcMap.Document.FocusMap as IActiveViewEvents_Event;
                IActiveViewEvents_AfterDrawEventHandler activeViewEvents_AfterDrawEventHandler = new IActiveViewEvents_AfterDrawEventHandler(this.ActiveView_OnAfterDraw);
                m_activeViewEvents.AfterDraw += activeViewEvents_AfterDrawEventHandler;

                IActiveViewEvents_ViewRefreshedEventHandler activeViewEvents_ViewRefreshedEventHandler = new IActiveViewEvents_ViewRefreshedEventHandler(this.ActiveView_OnViewRefreshed);
                m_activeViewEvents.ViewRefreshed += activeViewEvents_ViewRefreshedEventHandler;

                UID uid = new UIDClass();
                uid.Value = ThisAddIn.IDs.SF10_btnHauteurMin;
                uid.SubType = 0;
                m_pApp.Document.Accelerators.Add(uid, (System.Int32)System.Windows.Forms.Keys.D1, true, false, false);

                uid = new UIDClass();
                uid.Value = ThisAddIn.IDs.SF10_btnHauteurMax;
                uid.SubType = 0;
                m_pApp.Document.Accelerators.Add(uid, (System.Int32)System.Windows.Forms.Keys.D2, true, false, false);
            }
            catch
            {
            }
        }
		public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute attribute)
		{
			// Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
			Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
			try
			{
				// Activator.CreateInstance(t) is expected to error if the evaluator is created in an engine application 
				// which can�t get a reference to the AppRef singleton.  
				// This evaluator won�t work in Engine due to this design limitation.  It is, however,
				// fully functional in ArcMap.
				System.Object obj = Activator.CreateInstance(t);
				IApplication app = obj as IApplication;
				if (app != null && app is IMxApplication)
					m_mxDocument = app.Document as IMxDocument;
			}
			catch (Exception e)
			{
				m_mxDocument = null;
			}

			// Store reference to the network dataset and the network source
			m_networkDataset = networkDataset;
			m_networkSource = source;

			// Create a new Dictionary hashtable for this network source
			m_sourceHashTable = new Dictionary<int, int>();
		}
        public void Activate(int parentHWnd, IMxDocument Document)
        {
            if (m_application == null)
            {
                m_application = ((IDocument)Document).Parent;
                if (cboLayerType.SelectedIndex < 0)
                    cboLayerType.SelectedIndex = 0; //this should refresh the list automatically
                else
                    RefreshList();

                SetUpDocumentEvent(Document as IDocument);
            }
        }
Beispiel #52
0
 public void zoomToPageLayout(IMxDocument pMxDoc)
 {
     double escalaD = 0;
     long escala = 0;
     try{
         IMap pMap = pMxDoc.FocusMap;
         escalaD = pMap.MapScale;
         escala = funcAux.redondea(Convert.ToInt64(escalaD), 1, 1000);
         pMap.MapScale = escala;
     }catch (System.Exception ex) {
         MessageBox.Show("Error: " + ex.Message, "zoomToPageLayout");
         MessageBox.Show("Error: " + ex.StackTrace);
     }
 }
Beispiel #53
0
        private void AddSelection(IMxDocument pMXDoc, IDictionary<int, SelectedObjects> dicClasses)
        {
            IEnumLayer pELayers;
            ILayer pLayer;
            UID pUID;
            IFeatureLayer pFLayer;
            IFeatureClass pFC;
            SelectedObjects pSelObjs;
            IFeatureSelection pFSel;
            IMap pMap;

            try
            {
                pMXDoc = GetDoc();
                pMap = pMXDoc.FocusMap;
                pUID = new UIDClass();
                pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
                pELayers = pMap.get_Layers(pUID, true);
                pLayer = pELayers.Next();
                while (pLayer != null)
                {
                    if (pLayer is IFeatureLayer)
                    {
                        pFLayer = (IFeatureLayer)pLayer;
                        pFC = pFLayer.FeatureClass;
                        if (dicClasses.TryGetValue(pFC.FeatureClassID, out pSelObjs))
                        {
                            if (pSelObjs != null)
                            {
                                try
                                {
                                    pFSel = (IFeatureSelection)pFLayer;
                                    pFSel.SelectionSet = pSelObjs.SelectionSet;
                                }
                                catch (Exception EX2)
                                {
                                    Logger.WriteLine("Error in Selection:" + EX2.Source);
                                }
                            }
                            else
                            {
                                Logger.WriteLine("No Selection Object found");
                            }
                        }
                    }
                    pLayer = pELayers.Next();
                }
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in AddSelection :" + EX.Message + " " + EX.StackTrace);
            }
        }
    /// <summary>
    /// Occurs when this tool is created
    /// </summary>
    /// <param name="hook">Instance of the application</param>
    public override void OnCreate(object hook)
    {
      IApplication application = hook as IApplication;
      m_doc = application.Document as IMxDocument;

      //Disable if it is not ArcMap
      if (hook is IMxApplication)
        base.m_enabled = true;
      else
        base.m_enabled = false;
    }
Beispiel #55
0
        /// <summary>
        /// sets spatial reference for the map using SRS value in wmc
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="sSRS"></param>
        private void SetSpatialReference(IMxDocument ipMxDoc, string sSRS)
        {
            try
            {
                string sSpatRefID;  // Spatial Reference ID

                // get spatial reference factory code from SRS (for example EPSG:NNNN - NNNN is the factory code)
                int iPos;
                sSRS = sSRS.Trim();
                iPos = sSRS.IndexOf(":");
                if (iPos > 0)
                {
                    sSpatRefID = sSRS.Substring(iPos + 1);
                }
                else
                {
                    sSpatRefID = sSRS;
                }
                int wkid = int.Parse(sSpatRefID);
                if (wkid != 0)
                {
                    ISpatialReferenceFactory2 pSpatRefFactory = (ISpatialReferenceFactory2)new SpatialReferenceEnvironment();
                    ISpatialReference pSpatRef = pSpatRefFactory.CreateSpatialReference(wkid);
                    if (pSpatRef != null)
                    {
                        // set spatial reference for the map
                        ipMxDoc.FocusMap.SpatialReference = pSpatRef;
                    }
                    else
                    {
                        MessageBox.Show(StringResources.FailedSpatRef);

                    }
                }
            }
            catch (Exception e)
            {
                logger.writeLog(e.StackTrace);
            }
        }
 void ArcMap_NewDocument()
 {
   m_MxDoc = (IMxDocument)ArcMap.Document;
     SetupActiveViewEvents(m_MxDoc.FocusMap);
 }
Beispiel #57
0
        public void Shutdown()
        {
            util.Logger.Write(this.Name + " shutting down.", util.Logger.LogLevel.Info);

            try
            {
                IDocumentEvents_Event ide = null;
                if (this.MxDocument != null)
                {
                    ide = ((IDocumentEvents_Event)this.MxDocument);
                    ide.CloseDocument -= this.doc_close;
                    ide.NewDocument -= this.new_doc;
                    ide.OpenDocument -= this.open_doc;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }

            util.Utils.Release(_pMxDoc); // TODO: do we pull this out later (May 28-07)
            _pMxDoc = null;

            // TM cleanup
            this._tm = null;

            // QA cleanup
            this._qa.Release();
            this._qa = null;

            this._app = null;
        }
 void Events_OpenDocument()
 {
      m_MxDoc = (IMxDocument)ArcMap.Document;
     SetupActiveViewEvents(m_MxDoc.FocusMap);
 }
Beispiel #59
0
        public void Start()
        {
            try
            {
                //Debug.WriteLine("\t-> 1");

                util.Logger.Write(this.Name + " starting up.", util.Logger.LogLevel.Info);
                util.Logger.Write(this.Name + " version number: " + GetType().Assembly.GetName().Version.ToString());
                util.Logger.LoggingLevel = util.Logger.LogLevel.Debug;

                this._defaults = new util.SystemDefaults();

                //Added to avoid passing isdut.mxd as a command-line argument.
                //this._app.NewDocument(false, this._defaults.get_Default("tm.temp"));

                // event init

                //this.doc_close = new IDocumentEvents_CloseDocumentEventHandler(StoreTransactionToMap);
                //this.new_doc = new IDocumentEvents_NewDocumentEventHandler(LoadTransactionFromMap);
                //this.open_doc = new IDocumentEvents_OpenDocumentEventHandler(LoadTransactionFromMap);

                _pMxDoc = this._app.Document as IMxDocument;

                //IDocumentEvents_Event ide = _pMxDoc as IDocumentEvents_Event;

                //ide.CloseDocument += this.doc_close;
                //ide.NewDocument += this.new_doc;
                //ide.OpenDocument += this.open_doc;

                // TM init
                this._tm = new TransactionManager(this._app, this);

                // QA init
                this._qa = new QAManager(this._app);

                UID pUID;
                pUID = new UIDClass();

                pUID.Value = "esriEditor.Editor";
                IEditor pEditor = (IEditor)_app.FindExtensionByCLSID(pUID);

                //m_OnStartEditing = new IEditEvents_OnStartEditingEventHandler(OnStartEditing_Handler2);
                //add delgates to the appropriate events to enable listening
                //((IEditEvents_Event)pEditor).OnStartEditing += m_OnStartEditing;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);

            }
        }
Beispiel #60
0
        /// <summary>
        /// Sets layer visibility in current map document
        /// </summary>
        /// <param name="ipMxDoc"></param>
        private void SetLayerVisibility(IMxDocument ipMxDoc)
        {
            IMap ipMap = ipMxDoc.FocusMap;

            //get all the layers from the map
            IEnumLayer ipEnumLayer;
            ILayer ipLayer;
            ipEnumLayer = ipMap.get_Layers(null, true);

            //  'is there anything visible???
            if (colVisibleLayers.Count == 0) return;

            string strServer = "";
            string strLayerName = "";
            string strSecretName = "";

            //  'is it in visible layer list?
            foreach (string layer in colVisibleLayers)
            {
                string[] s = DecodeServiceList(layer);
                if (s.Length == 3)
                {
                    strServer = s[0];
                    strLayerName = s[1];
                    strSecretName = s[2];
                }
                else if (s.Length == 2)
                {
                    strServer = s[0];
                    strLayerName = s[1];
                    strSecretName = "";
                }
                else if (s.Length == 1)
                {
                    strServer = "";
                    strLayerName = s[0];
                    strSecretName = "";
                }
                ipEnumLayer.Reset();
                ipLayer = ipEnumLayer.Next();
                do
                {
                    if (ipLayer.Name == strLayerName)
                    {
                        SetLayerVisible(ipLayer, strLayerName, strSecretName);
                        break;
                    }
                    ipLayer = ipEnumLayer.Next();
                } while (ipLayer != null);
            }

            //'update toc
            ipMxDoc.UpdateContents();

            // 'and update the view
            ipMxDoc.ActiveView.Refresh();
        }