예제 #1
0
        /// <summary>
        /// 查找地图(map)
        /// </summary>
        /// <param name="maps"></param>
        /// <param name="mapName">地图名称</param>
        /// <returns></returns>
        public static IMap GetMapFromMaps(this IMaps maps, string mapName)
        {
            IMap map = null;

            for (int i = 0; i < maps.Count; i++)
            {
                if (maps.get_Item(i).Name == mapName)
                {
                    map = maps.get_Item(i);
                    break;
                }
            }
            return(map);
        }
        private void ProcessMaps()
        {
            IMaps Maps = ArcMap.Document.Maps;

            // get the Maps
            long lNbMaps = Maps.Count;
            int  i       = 0;

            for (i = 0; i < lNbMaps; i++)
            {
                IMap Map = Maps.get_Item(i);
                if (Map == null)
                {
                    continue;
                }

                // browse its layers for a schematic layer
                IEnumLayer Layers = Map.get_Layers(null, false);
                ILayer     Layer  = null;

                Layers.Reset();
                while ((Layer = Layers.Next()) != null)
                {
                    ISchematicLayer schLayer = (ISchematicLayer)Layer;
                    Updatecontainers(schLayer);
                }
            }
        }
        /// <summary>
        /// Gets all maps and layers that are contained in a given <see cref="IMaps"/> object.
        /// </summary>
        /// <returns>
        ///		An array of <see cref="TableOfContentsItem"/>s representing all of the maps and layers in <paramref name="maps"/>.
        ///		If <paramref name="maps"/> is <see langword="null"/> or does not contain any maps or layers, an empty array will
        ///		be returned.
        ///	</returns>
        public static TableOfContentsItem[] GetAllTableOfContentsItems(IMaps maps)
        {
            ArrayList list = new ArrayList();

            if (maps != null)
            {
                // Loop through all maps.
                for (int mapIdx = 0; mapIdx < maps.Count; mapIdx++)
                {
                    IMap currentMap = maps.get_Item(mapIdx);
                    list.Add(new TableOfContentsItem(currentMap));

                    // Create a list of all layers.
                    ArrayList layersInMap = new ArrayList();
                    for (int layerIdx = 0; layerIdx < currentMap.LayerCount; layerIdx++)
                    {
                        ILayer currentLayer = currentMap.get_Layer(layerIdx);
                        layersInMap.AddRange(GetAllLayers(currentLayer));
                    }

                    foreach (ILayer currentLayer in layersInMap)
                    {
                        list.Add(new TableOfContentsItem(currentLayer));
                    }
                }
            }

            return((TableOfContentsItem[])list.ToArray(typeof(TableOfContentsItem)));
        }
예제 #4
0
        //Gets the spatial reference details of a given data frame. Returns a dictionary with the "type", "datum" & "projection".
        //these keys return empty if the dataframe doesn't exist, therefore test "type" != string.empty; on the other end

        public static Dictionary <string, string> getDataFrameSpatialReference(IMxDocument pMxDoc, string pDataFrameName)
        {
            IMap   pMap;
            IMap   pDataFrame = null;
            IMaps  pMaps      = pMxDoc.Maps;
            string type       = string.Empty;
            string datum      = string.Empty;
            string projection = string.Empty;
            Dictionary <string, string> dict = new Dictionary <string, string>();

            try
            {
                //Search through the dataframes in the document
                for (int i = 0; i <= pMaps.Count - 1; i++)
                {
                    pMap = pMaps.get_Item(i);
                    if (pMap.Name == pDataFrameName)
                    {
                        //assign pDataFrame map where the passed dataframe name exists
                        pDataFrame = pMap;
                        //Determine which ISpatialReference type the map frame is & assign type, datum & projection
                        //variables accordingly
                        ISpatialReference spatialRef = pDataFrame.SpatialReference;
                        if (spatialRef is IGeographicCoordinateSystem)
                        {
                            type = "Geographic";
                            IGeographicCoordinateSystem geoCoord = spatialRef as IGeographicCoordinateSystem;
                            datum = geoCoord.Datum.Name.Remove(0, 2);
                            datum = datum.Replace("_", " ");
                        }
                        else if (spatialRef is IProjectedCoordinateSystem)
                        {
                            type = "Projected";
                            IProjectedCoordinateSystem prjCoord = spatialRef as IProjectedCoordinateSystem;
                            projection = prjCoord.Name;
                            projection = projection.Replace("_", " ");
                            datum      = prjCoord.GeographicCoordinateSystem.Name.Remove(0, 4);
                            datum      = datum.Replace("_", " ");
                        }
                        else
                        {
                            type = "Unknown";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            //write out the variables to the dictionary, if no frame was found they will be each string.empty.
            dict.Add("type", type);
            dict.Add("datum", datum);
            dict.Add("projection", projection);
            //Return the dictionary
            return(dict);
        }
        private void RefreshList()
        {
            tvwLayer.Nodes.Clear();
            UID layerFilter = null;

            if (cboLayerType.SelectedItem.Equals("Feature Layers"))
            {
                layerFilter       = new UIDClass();
                layerFilter.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //typeof(IFeatureLayer).GUID.ToString("B");
            }
            else if (cboLayerType.SelectedItem.Equals("Raster Layers"))
            {
                layerFilter       = new UIDClass();
                layerFilter.Value = typeof(IRasterLayer).GUID.ToString("B");
            }
            else if (cboLayerType.SelectedItem.Equals("Data Layers"))
            {
                layerFilter       = new UIDClass();
                layerFilter.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"; //typeof(IDataLayer).GUID.ToString("B");
            }

            IMxDocument document = (IMxDocument)m_application.Document;
            IMaps       maps     = document.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                IMap     map     = maps.get_Item(i);
                TreeNode mapNode = tvwLayer.Nodes.Add(map.Name);
                mapNode.Tag = map;
                if (map.LayerCount > 0)
                {
                    IEnumLayer layers = map.get_Layers(layerFilter, true);
                    layers.Reset();
                    ILayer lyr;
                    while ((lyr = layers.Next()) != null)
                    {
                        TreeNode lyrNode = mapNode.Nodes.Add(lyr.Name);
                        lyrNode.Tag = lyr;
                    }

                    mapNode.ExpandAll();
                }
            }
        }
예제 #6
0
        // Returns IMap object of the map frame with the specified name in the method call
        public static IMap getMapFrame(IMxDocument pMxDoc, string pMapFrameName)
        {
            IMap  pSelectedMap = null;
            IMap  pMap;
            IMaps pMaps = pMxDoc.Maps;

            // Get the data frame
            //Search through the dataframes in the document
            for (int i = 0; i <= pMaps.Count - 1; i++)
            {
                pMap = pMaps.get_Item(i);
                if (pMap.Name == pMapFrameName)
                {
                    //assign pDataFrame map where the passed dataframe name exists
                    pSelectedMap = pMap;
                }
            }

            return(pSelectedMap);
        }
예제 #7
0
        public void AddNewMaps(IMaps newMaps)
        {
            if (newMaps == null)
            {
                throw new Exception("ControlsSynchronizer::ReplaceMap:\r\nNew map for replacement is not initialized!");
            }

            if (m_pageLayoutControl == null || m_mapControl == null)
            {
                throw new Exception("ControlsSynchronizer::ReplaceMap:\r\nEither MapControl or PageLayoutControl are not initialized!");
            }

            bool bIsMapActive = m_IsMapCtrlactive;

            //call replace map on the PageLayout in order to replace the focus map
            //we must call ActivatePageLayout, since it is the control we call 'ReplaceMaps'
            this.ActivatePageLayout();
            m_pageLayoutControl.PageLayout.ReplaceMaps(newMaps);;
            IMap map = newMaps.get_Item(0);

            //assign the new map to the MapControl
            m_mapControl.Map = map;

            //reset the active tools
            //m_pageLayoutActiveTool = null;
            //m_mapActiveTool = null;

            //make sure that the last active control is activated
            if (bIsMapActive)
            {
                this.ActivateMap();
                m_mapControl.ActiveView.Refresh();
            }
            else
            {
                this.ActivatePageLayout();
                m_pageLayoutControl.ActiveView.Refresh();
            }
        }
예제 #8
0
        // Determines if a given map frame exists given a name and IMxDocument reference.
        // Boolean returns true if it exists.
        public static Boolean detectMapFrame(IMxDocument pMxDoc, string pFrameName)
        {
            IMap    pMap;
            IMaps   pMaps          = pMxDoc.Maps;
            Boolean mapFrameExists = false;

            try
            {
                for (int i = 0; i <= pMaps.Count - 1; i++)
                {
                    pMap = pMaps.get_Item(i);
                    if (pMap.Name == pFrameName)
                    {
                        mapFrameExists = true;
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            return(mapFrameExists);
        }
예제 #9
0
        // Exports a given page layout or map frame to a variety of image formats, returns the image file path
        public static string exportImage(IMxDocument pMxDoc, string exportType, string dpi, string pathDocumentName, string mapFrameName)
        {
            // Define the activeView as either the page layout or the map frame
            // If the mapFrameName variable is null then the activeView is the page, otherwise it is set to the map frame name specified
            IMap        pMap;
            IActiveView pActiveView = null;
            IMaps       pMaps       = pMxDoc.Maps;
            // Also construct output filename depending on the activeView / mapFrame input
            string pathFileName = string.Empty;

            if (mapFrameName == null)
            {
                pActiveView  = pMxDoc.ActiveView;
                pathFileName = @pathDocumentName + "-" + dpi.ToString() + "dpi." + exportType;
            }
            else if (mapFrameName != null && PageLayoutProperties.detectMapFrame(pMxDoc, mapFrameName))
            {
                for (int i = 0; i <= pMaps.Count - 1; i++)
                {
                    pMap = pMaps.get_Item(i);
                    if (pMap.Name == mapFrameName)
                    {
                        pActiveView = pMap as IActiveView;
                    }
                }
                pathFileName = @pathDocumentName + "-mapframe-" + dpi.ToString() + "dpi." + exportType;
            }
            else
            {
                return(null);
            }

            //Declare the export variable and set the file and path from the parameters
            IExport docExport;

            //parameter check
            if (pActiveView == null)
            {
                return(null);
            }
            // The Export*Class() type initializes a new export class of the desired type.
            if (exportType == "pdf")
            {
                docExport = new ExportPDFClass();
            }
            else if (exportType == "eps")
            {
                docExport = new ExportPSClass();
            }
            else if (exportType == "ai")
            {
                docExport = new ExportAIClass();
            }
            else if (exportType == "bmp")
            {
                docExport = new ExportBMPClass();
            }
            else if (exportType == "tiff")
            {
                docExport = new ExportTIFFClass();
            }
            else if (exportType == "svg")
            {
                docExport = new ExportSVGClass();
            }
            else if (exportType == "png")
            {
                docExport = new ExportPNGClass();
            }
            else if (exportType == "gif")
            {
                docExport = new ExportGIFClass();
            }
            else if (exportType == "emf")
            {
                docExport = new ExportEMFClass();
            }
            else if (exportType == "jpeg")
            {
                IExportJPEG m_export;
                docExport = new ExportJPEGClass();
                if (docExport is IExportJPEG)
                {
                    m_export = (IExportJPEG)docExport;
                    m_export.ProgressiveMode = false;   //hardcoded progressive mode value here
                    m_export.Quality         = 80;      //hardcoded quality value here
                    docExport = (IExport)m_export;
                }
            }
            else
            {
                return(pathFileName);
            }

            docExport.ExportFileName = pathFileName;

            // Because we are exporting to a resolution that differs from screen
            // resolution, we should assign the two values to variables for use
            // in our sizing calculations
            System.Int32 screenResolution = 96;
            System.Int32 outputResolution = Convert.ToInt32(dpi);

            docExport.Resolution = outputResolution;

            // If input type is map frame calculate the export rectangle

            tagRECT exportRECT; // This is a structure

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = pActiveView.ExportFrame.right * (outputResolution / screenResolution);
            exportRECT.bottom = pActiveView.ExportFrame.bottom * (outputResolution / screenResolution);


            // Set up the PixelBounds envelope to match the exportRECT
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            docExport.PixelBounds = envelope;

            try
            {
                System.Int32 hDC = docExport.StartExporting();
                pActiveView.Output(hDC, (System.Int16)docExport.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                docExport.FinishExporting();
                docExport.Cleanup();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error writing to file, probably a file permissions error.  Check the exception message below for details.");
                Debug.WriteLine(e.Message);
            }

            //Return the path of the file
            return(pathFileName);
        }
예제 #10
0
        /// <summary>
        /// Determines whether at least one of the layers in all the maps is an HLU layer.
        /// Called by OnOpenDocument when ArcGIS determines that a document has just been opened.
        /// </summary>
        /// <param name="maps">The maps collection (i.e. active views) of the open document.</param>
        /// <returns></returns>
        public bool IsHluWorkspace(IMaps maps)
        {
            try
            {
                IMap map = null;

                UID uid = new UIDClass();
                uid.Value = typeof(IFeatureLayer).GUID.ToString("B");

                for (int i = 0; i < maps.Count; i++)
                {
                    map = maps.get_Item(i);
                    IEnumLayer layers = map.get_Layers(uid, true);
                    ILayer layer = layers.Next();
                    while (layer != null)
                    {
                        IFeatureLayer featureLayer = layer as IFeatureLayer;
                        if (IsHluLayer(featureLayer))
                        {
                            _hluView = map as IActiveView;
                            return true;
                        }
                        layer = layers.Next();
                    }
                }
            }
            catch { }

            return false;
        }