public bool SwitchPasture(string strName) { m_activePasture = GetPastureByName(strName); if (m_activePasture.strPasture == string.Empty) return false; // m_pastureMap = new Map(); m_pastureMap.Name = m_activePasture.strPasture; IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(m_activePasture.strDataDir,0); DirectoryInfo pastureDir = new DirectoryInfo(m_activePasture.strDataDir); FileInfo[] files = pastureDir.GetFiles("*.shp"); foreach (FileInfo file in files) { IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = file.Name; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass(file.Name); m_pastureMap.AddLayer(featureLayer); } ////////////////////////////////////////////////////////////////////////// if (m_activePasture.strRasLyr != string.Empty) { IWorkspaceFactory rasWksFactory = new RasterWorkspaceFactory(); IRasterWorkspace rasWks = rasWksFactory.OpenFromFile(m_activePasture.strDataDir, 0) as IRasterWorkspace; IRasterDataset rasDataset = rasWks.OpenRasterDataset(m_activePasture.strRasLyr); IRasterLayer rasLyr = new RasterLayerClass(); rasLyr.CreateFromDataset(rasDataset); LayerHelper.SetLayerColor(rasLyr); if (m_adminMap.LayerCount == 3) { m_adminMap.AddLayer(rasLyr); m_adminMap.MoveLayer(rasLyr,3); } else if(m_adminMap.LayerCount == 4) { ILayer lyr = m_adminMap.get_Layer(3); if (null != lyr) m_adminMap.DeleteLayer(lyr); m_adminMap.AddLayer(rasLyr); m_adminMap.MoveLayer(rasLyr,3); } } ////////////////////////////////////////////////////////////////////////// Queue<TreeNode> vistor_queue = new Queue<TreeNode>(); vistor_queue.Enqueue(m_tree.Nodes[0]); while (vistor_queue.Count > 0) { TreeNode node = vistor_queue.Dequeue(); if (node.Text == strName) node.ForeColor = Color.BlueViolet; else node.ForeColor = Color.Black; TreeNode child = node.FirstNode; while (null != child) { vistor_queue.Enqueue(child); child = child.NextNode; } return true; } return false; }
protected void OpenPastureMapDoc(Pasture pasture) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(pasture.strMapDoc) && !mapDoc.get_IsPasswordProtected(pasture.strMapDoc)) { mapDoc.Open(pasture.strMapDoc, string.Empty); // set the first map as the active view m_pastureMap = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)m_pastureMap); mapDoc.Close(); } }
public void RefreshPasture() { DirectoryInfo pastureDir = new DirectoryInfo(m_pastureDir); DirectoryInfo[] familyDirs = pastureDir.GetDirectories(); string strRootNode = @"所有牧草"; m_tree.BeginUpdate(); m_tree.Nodes.Clear(); TreeNode rootnode = new TreeNode(strRootNode); m_tree.Nodes.Add(rootnode); foreach (DirectoryInfo fdir in familyDirs) { DirectoryInfo[] pdirs = fdir.GetDirectories(); GrassFamily family = new GrassFamily(); family.strFamily = fdir.Name; family.pastures = new List<Pasture>(); TreeNode familynode = rootnode.Nodes.Add(family.strFamily); foreach (DirectoryInfo dir in pdirs) { Pasture pasture = new Pasture(); pasture.strPasture = dir.Name; pasture.strDataDir = dir.FullName; pasture.strMapDoc = string.Empty; pasture.strRasLyr = string.Empty; FileInfo[] mxdfiles = dir.GetFiles("*.mxd"); if (mxdfiles.Length == 1) { FileInfo mxdfile = mxdfiles[0]; pasture.strMapDoc = mxdfile.FullName; } FileInfo[] rasfiles = dir.GetFiles("*.aux"); if (rasfiles.Length == 1) { FileInfo rasfile = rasfiles[0]; pasture.strRasLyr = rasfile.Name; pasture.strRasLyr = pasture.strRasLyr.Substring(0, pasture.strRasLyr.Length - 4); } family.pastures.Add(pasture); familynode.Nodes.Add(pasture.strPasture); } m_grassFamilys.Add(family); } m_tree.EndUpdate(); // //m_activePasture = m_grassFamilys[0].pastures[0]; }