/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { if (m_hookHelper.Hook == null) { return; } List <IGeometry> vTemp = GetDataGeometry(m_hookHelper.FocusMap); if (vTemp == null) { return; } ESRI.ArcGIS.Geometry.IGeometry pGeometry = GetUnion(vTemp); if (pGeometry == null) { return; } ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; GeoPageLayout gpl = new GeoPageLayout(pMap, pGeometry); gpl.typePageLayout = 2; gpl.MapOut(); gpl = null; }
//根据层名,得到层的索引 public System.Int32 GetIndexNumberFromLayerName(ESRI.ArcGIS.Carto.IActiveView activeView, System.String layerName) { if (activeView == null || layerName == null) { return(-1); } ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; // Get the number of layers int numberOfLayers = map.LayerCount; // Loop through the layers and get the correct layer index for (System.Int32 i = 0; i < numberOfLayers; i++) { if (layerName == map.get_Layer(i).Name) { // Layer was found return(i); } //map.get_Layer(i).Visible = false; } // No layer was found return(-1); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper.Hook == null) { return; } IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2; ESRI.ArcGIS.Geometry.IGeometry pGeometry = pMapCtl.TrackPolygon(); if (pGeometry == null) { return; } if (pGeometry.GeometryType != esriGeometryType.esriGeometryPolygon) { return; } ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; IGraphicsContainer pGra = pMap as IGraphicsContainer; GeoPageLayout gpl = new GeoPageLayout(pMap, pGeometry); gpl.typePageLayout = 2; gpl.MapOut(); gpl = null; }
// ArcGIS Snippet Title: // Add Legend // // Long Description: // Add a Legend to the Page Layout from the Map. // // Add the following references to the project: // ESRI.ArcGIS.Carto // ESRI.ArcGIS.Geometry // ESRI.ArcGIS.System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView) // ArcGIS Engine // ArcGIS Server // // Applicable ArcGIS Product Versions: // 9.2 // 9.3 // 9.3.1 // 10.0 // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Method. // ///<summary>Add a Legend to the Page Layout from the Map.</summary> /// ///<param name="pageLayout">An IPageLayout interface.</param> ///<param name="map">An IMap interface.</param> ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param> ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param> ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param> /// ///<remarks></remarks> public void AddLegend(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map, System.Double posX, System.Double posY, System.Double legW) { if (pageLayout == null || map == null) { return; } ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast ESRI.ArcGIS.Carto.IMapFrame mapFrame = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.Legend"; ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast //Get aspect ratio ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast System.Double w = 0; System.Double h = 0; querySize.QuerySize(ref w, ref h); System.Double aspectRatio = w / h; ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio)); ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast element.Geometry = envelope; graphicsContainer.AddElement(element, 0); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper.Hook == null) { return; } IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2; ESRI.ArcGIS.Geometry.IEnvelope pGeometry = pMapCtl.TrackRectangle(); if (pGeometry == null) { return; } ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; //更改获取面积的方法,20111123 double area = GetArea(pGeometry, pMap); double dArea = SysCommon.ModSysSetting.GetExportAreaOfUser(Plugin.ModuleCommon.TmpWorkSpace, m_pAppForm.ConnUser); if (dArea >= 0 && area > dArea) { MessageBox.Show("超过提取最大面积", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } drawgeometryXOR(pGeometry as IGeometry); frm = new frmExport(pMap, pGeometry); frm.WriteLog = WriteLog; //ygc 2012-9-12 是否写日志 frm.m_area = area; //ZQ 2011 1126 modify SysCommon.ScreenDraw.list.Add(ToolEvnelopeExportAfterDraw); frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.ShowDialog(); }
// ArcGIS Snippet Title: // Loop Through Layers of Specific UID // // Long Description: // Stub code to loop through layers in a map where a specific UID is supplied. // // Add the following references to the project: // ESRI.ArcGIS.Carto // ESRI.ArcGIS.System // System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView) // ArcGIS Engine // ArcGIS Server // // Applicable ArcGIS Product Versions: // 9.2 // 9.3 // 9.3.1 // 10.0 // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Method. // ///<summary>Stub code to loop through layers in a map where a specific UID is supplied.</summary> /// ///<param name="map">An IMap interface in which the layers reside.</param> ///<param name="layerCLSID">A System.String that is the layer GUID type. For example: "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" is the IGeoFeatureLayer.</param> /// ///<remarks>In order of the code to be useful the user needs to write their own code to use the layer in the TODO section. /// /// The different layer GUID's and Interface's are: /// "{AD88322D-533D-4E36-A5C9-1B109AF7A346}" = IACFeatureLayer /// "{74E45211-DFE6-11D3-9FF7-00C04F6BC6A5}" = IACLayer /// "{495C0E2C-D51D-4ED4-9FC1-FA04AB93568D}" = IACImageLayer /// "{65BD02AC-1CAD-462A-A524-3F17E9D85432}" = IACAcetateLayer /// "{4AEDC069-B599-424B-A374-49602ABAD308}" = IAnnotationLayer /// "{DBCA59AC-6771-4408-8F48-C7D53389440C}" = IAnnotationSublayer /// "{E299ADBC-A5C3-11D2-9B10-00C04FA33299}" = ICadLayer /// "{7F1AB670-5CA9-44D1-B42D-12AA868FC757}" = ICadastralFabricLayer /// "{BA119BC4-939A-11D2-A2F4-080009B6F22B}" = ICompositeLayer /// "{9646BB82-9512-11D2-A2F6-080009B6F22B}" = ICompositeGraphicsLayer /// "{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E}" = ICoverageAnnotationLayer /// "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" = IDataLayer /// "{0737082E-958E-11D4-80ED-00C04F601565}" = IDimensionLayer /// "{48E56B3F-EC3A-11D2-9F5C-00C04F6BC6A5}" = IFDOGraphicsLayer /// "{40A9E885-5533-11D0-98BE-00805F7CED21}" = IFeatureLayer /// "{605BC37A-15E9-40A0-90FB-DE4CC376838C}" = IGdbRasterCatalogLayer /// "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" = IGeoFeatureLayer /// "{34B2EF81-F4AC-11D1-A245-080009B6F22B}" = IGraphicsLayer /// "{EDAD6644-1810-11D1-86AE-0000F8751720}" = IGroupLayer /// "{D090AA89-C2F1-11D3-9FEF-00C04F6BC6A5}" = IIMSSubLayer /// "{DC8505FF-D521-11D3-9FF4-00C04F6BC6A5}" = IIMAMapLayer /// "{34C20002-4D3C-11D0-92D8-00805F7C28B0}" = ILayer /// "{E9B56157-7EB7-4DB3-9958-AFBF3B5E1470}" = IMapServerLayer /// "{B059B902-5C7A-4287-982E-EF0BC77C6AAB}" = IMapServerSublayer /// "{82870538-E09E-42C0-9228-CBCB244B91BA}" = INetworkLayer /// "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}" = IRasterLayer /// "{AF9930F0-F61E-11D3-8D6C-00C04F5B87B2}" = IRasterCatalogLayer /// "{FCEFF094-8E6A-4972-9BB4-429C71B07289}" = ITemporaryLayer /// "{5A0F220D-614F-4C72-AFF2-7EA0BE2C8513}" = ITerrainLayer /// "{FE308F36-BDCA-11D1-A523-0000F8774F0F}" = ITinLayer /// "{FB6337E3-610A-4BC2-9142-760D954C22EB}" = ITopologyLayer /// "{005F592A-327B-44A4-AEEB-409D2F866F47}" = IWMSLayer /// "{D43D9A73-FF6C-4A19-B36A-D7ECBE61962A}" = IWMSGroupLayer /// "{8C19B114-1168-41A3-9E14-FC30CA5A4E9D}" = IWMSMapLayer ///</remarks> public void LoopThroughLayersOfSpecificUID(ESRI.ArcGIS.Carto.IMap map, System.String layerCLSID) { if (map == null || layerCLSID == null) { return; } ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = layerCLSID; // Example: "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" = IGeoFeatureLayer try { ESRI.ArcGIS.Carto.IEnumLayer enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)(uid)), true); // Explicit Cast enumLayer.Reset(); ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next(); cboLayers.Items.Clear(); lstLayers.Clear(); while (!(layer == null)) { IFeatureLayer featureLayer = (IFeatureLayer)layer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { cboLayers.Items.Add(layer.Name); lstLayers.Add(layer); } layer = enumLayer.Next(); } if (cboLayers.Items.Count > 0) { cboLayers.SelectedIndex = 0; } } catch (System.Exception ex) { //System.Windows.Forms.MessageBox.Show("No layers of type: " + uid.Value.ToString); } }
//====================================================================================================== #region 判断要素是否在同一图层以及图层的编辑状态 //=================================================================================================== //陈胜鹏 2009-08-19 添加 /// <summary> /// 从图面上获取选中要素所在数据集的工作空间,判断是否开启编辑 /// </summary> /// <param name="pMap">当前加载了数据的地图对象</param> /// <returns></returns> private bool GetDatasetEditState(ESRI.ArcGIS.Carto.IMap pMap) { int pSameLyr = 0; //记录要素是否为同层 ILayer pLayer = null; //判断选择的要素是否处于同一个图层 for (int i = 0; i < pMap.LayerCount; i++) { IFeatureLayer pFeatLyr = null; IFeatureSelection pFeatSel = null; pLayer = pMap.get_Layer(i); if (pLayer is IGroupLayer) { if (pLayer.Name == "示意图") { continue; } ICompositeLayer pComLayer = pLayer as ICompositeLayer; for (int j = 0; j < pComLayer.Count; j++) { ILayer mLayer = pComLayer.get_Layer(j); pFeatLyr = mLayer as IFeatureLayer; if (pFeatLyr != null) { pFeatSel = pFeatLyr as IFeatureSelection; if (pFeatSel.SelectionSet.Count > 0) { pSameLyr = pSameLyr + 1; m_MergeLayer = pFeatLyr;//当只有一个图层被选中时,pFeatLyr就是要进行融合的目标图层 } } } } pFeatLyr = pLayer as IFeatureLayer; if (pFeatLyr != null) { pFeatSel = pFeatLyr as IFeatureSelection; if (pFeatSel.SelectionSet.Count > 0) { pSameLyr = pSameLyr + 1; m_MergeLayer = pFeatLyr;//当只有一个图层被选中时,pFeatLyr就是要进行融合的目标图层 } } } //如果选择的要素所在的层数不是1,即要素不在同一个层 if (pSameLyr != 1) { return(false); } //一系列的QI后获得IWorkspaceEdit接口对象pWSE IFeatureClass pFeatCls = m_MergeLayer.FeatureClass as IFeatureClass; IDataset pDS = pFeatCls as IDataset; IWorkspace pWs = pDS.Workspace as IWorkspace; IWorkspaceEdit pWSE = pWs as IWorkspaceEdit; return(pWSE.IsBeingEdited()); //返回编辑状态 }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper.Hook == null) { return; } IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2; ESRI.ArcGIS.Geometry.IGeometry pGeometry = pMapCtl.TrackRectangle(); if (pGeometry == null) { return; } if (pGeometry.GeometryType != esriGeometryType.esriGeometryEnvelope) { return; } if (pGeometry.Envelope.Width < 0) { return; } //pLCCtl.Page.FormID = esriPageFormID.esriPageFormA4; //IMapFrame pMapFrame = (IMapFrame)pLCCtl.GraphicsContainer.FindFrame(pLCCtl.ActiveView.FocusMap); //IElement pMapEle = pMapFrame as IElement; //pMapEle.Geometry = pExtent as IGeometry; //pLCCtl.ZoomToWholePage(); //FrmScale pfrmScale = new FrmScale(); //if (pfrmScale.ShowDialog() != DialogResult.OK) // return; //createPageLayout_Rectangle(pfrmScale.ScaleSet); if (this.WriteLog) { Plugin.LogTable.Writelog("矩形范围制图");//xisheng 日志记录07.08 } drawgeometryXOR(pGeometry as IEnvelope, m_pScreenDisplay); ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; SysCommon.CProgress pgss = new SysCommon.CProgress("正在加载制图界面,请稍候..."); pgss.EnableCancel = false; pgss.ShowDescription = false; pgss.FakeProgress = true; pgss.TopMost = true; pgss.ShowProgress(); Application.DoEvents(); frm = new FrmPageLayout(m_hookHelper.FocusMap, pGeometry); frm.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志 frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.typeZHT = 2; frm.Show(); pgss.Close(); pMapCtl.CurrentTool = null; Application.DoEvents(); }
public bool ConvertLayerToKML(string kmzOutputPath, string tmpShapefilePath, ESRI.ArcGIS.Carto.IMap map, GraphicTypes graphicType) { try { string kmzName = System.IO.Path.GetFileName(kmzOutputPath); IGeoProcessor2 gp = new GeoProcessorClass(); gp.OverwriteOutput = true; IGeoFeatureLayer geoLayer = null; IVariantArray parameters = new VarArrayClass(); parameters.Add(tmpShapefilePath); parameters.Add(kmzName); gp.Execute("MakeFeatureLayer_management", parameters, null); string layerFileName = getLayerFileFromGraphicType(graphicType); if (!string.IsNullOrEmpty(layerFileName)) { IVariantArray parametersASM = new VarArrayClass(); parametersASM.Add(kmzName); parametersASM.Add(layerFileName); gp.Execute("ApplySymbologyFromLayer_management", parametersASM, null); } IVariantArray parameters1 = new VarArrayClass(); // assign parameters parameters1.Add(kmzName); parameters1.Add(kmzOutputPath); gp.Execute("LayerToKML_conversion", parameters1, null); // Remove the temporary layer from the TOC for (int i = 0; i < map.LayerCount; i++) { ILayer layer = map.get_Layer(i); if ((layer.Name == "featureLayer") || (layer.Name == kmzName)) { map.DeleteLayer(layer); break; } } if (geoLayer != null) { map.DeleteLayer(geoLayer); } return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(false); } }
private void AddItemsOnStartup(ESRI.ArcGIS.Carto.IActiveView activeView) { ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; var numberOfLayers = map.LayerCount; for (var i = 0; i < numberOfLayers; i++) { ArcMapItemAdded(map.Layer[i]); } }
private void RemoveActiveViewEvents(ESRI.ArcGIS.Carto.IMap map) { //parameter check if (map == null) { return; } ESRI.ArcGIS.Carto.IActiveViewEvents_Event activeViewEvents = map as ESRI.ArcGIS.Carto.IActiveViewEvents_Event; // Remove AfterDraw Event Handler activeViewEvents.AfterDraw -= m_ActiveViewEventsAfterDraw; }
/// <summary> /// Wiring active event after draw and selection change events /// </summary> /// <param name="map"></param> private void SetupActiveViewEvents(ESRI.ArcGIS.Carto.IMap map) { if (map == null) { return; } ESRI.ArcGIS.Carto.IActiveViewEvents_Event activeViewEvents = map as ESRI.ArcGIS.Carto.IActiveViewEvents_Event; // Create an instance of the delegate, add it to AfterDraw event m_ActiveViewEventsAfterDraw = new ESRI.ArcGIS.Carto.IActiveViewEvents_AfterDrawEventHandler(OnActiveViewEventsAfterDraw); activeViewEvents.AfterDraw += m_ActiveViewEventsAfterDraw; activeViewEvents.SelectionChanged += new IActiveViewEvents_SelectionChangedEventHandler(activeViewEvents_SelectionChanged); }
// ArcGIS Snippet Title: // Get Map from ArcMap // // Add the following references to the project: // ESRI.ArcGIS.ArcMapUI // ESRI.ArcGIS.Carto // ESRI.ArcGIS.Framework // ESRI.ArcGIS.System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Method. // // Use the following XML documentation comments to use this snippet: /// <summary>Get Map from ArcMap.</summary> /// /// <param name="application">An IApplication interface that is the ArcMap application.</param> /// /// <returns>An IMap interface.</returns> /// /// <remarks></remarks> public static ESRI.ArcGIS.Carto.IMap GetMap(ESRI.ArcGIS.Framework.IApplication application) { if (application == null) { return(null); } ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ((ESRI.ArcGIS.ArcMapUI.IMxDocument)(application.Document)); // Explicit Cast ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView; ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; return(map); }
private void SaveMXD(string sName, ESRI.ArcGIS.Carto.IMap map) { try { _pMapDocument.Save(true, false); } catch { _pMapDocument.Save(false, false); } _pMapDocument.Close(); }
//20110921 XISHENG 将导入txt范围的改成导入MDB,shp public override void OnClick() { if (_AppHk == null) { return; } if (this.WriteLog) { Plugin.LogTable.Writelog(base._Caption);//xisheng 日志记录 } OpenFileDialog dlg = new OpenFileDialog(); //dlg.Filter = "个人数据库(*.mdb)|*.mdb|shp数据|*.shp|文本文件|*.txt"; //dlg.Filter = "个人数据库(*.mdb)|*.mdb|shp数据|*.shp|文本文件|*.txt"; dlg.Filter = "shp数据|*.shp|个人数据库(*.mdb)|*.mdb|文件数据库(*.gdb)|gdb"; if (dlg.ShowDialog() == DialogResult.Cancel) { return; } IPolygon pGon = new PolygonClass(); pGon = SysCommon.ModPublicFun.GetPolyGonFromFile(dlg.FileName); if (pGon == null) { return; } ESRI.ArcGIS.Carto.IMap pMap = _AppHk.MapControl.ActiveView.FocusMap; IArea pArea = pGon as IArea; double area = pArea.Area; GetArea(ref area, pMap); double dArea = SysCommon.ModSysSetting.GetExportAreaOfUser(Plugin.ModuleCommon.TmpWorkSpace, m_pAppForm.ConnUser); if (dArea >= 0 && area > dArea) { MessageBox.Show("超过提取最大面积", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } drawgeometryXOR(pGon, m_pScreenDisplay); ///ZQ 20111027 add 判断数据字典是否初始化 if (SysCommon.ModField._DicFieldName.Count == 0) { SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表"); } frm = new GeoDataExport.frmExport(pMap, pGon as ESRI.ArcGIS.Geometry.IGeometry); frm.WriteLog = this.WriteLog; //ygc 2012-9-11 新增是否写日志 frm.m_area = area; frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.ShowDialog(); }
/// <summary> /// 根据图层索引获得图层 /// </summary> /// <param name="activeView">当前视图窗口对象</param> /// <param name="layerIndex">图层序号</param> /// <returns></returns> public ESRI.ArcGIS.Carto.IFeatureLayer GetFeatureLayerFromLayerIndexNumber(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 layerIndex) { if (activeView == null || layerIndex < 0) { return(null); } ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; if (layerIndex < map.LayerCount && map.get_Layer(layerIndex) is ESRI.ArcGIS.Carto.IFeatureLayer) { return((ESRI.ArcGIS.Carto.IFeatureLayer)activeView.FocusMap.get_Layer(layerIndex)); // Explicit Cast } else { return(null); } }
public override void OnClick() { DrawTypeConstant nDrawType = DrawTypeConstant.CommonPolygon; this.m_blCanEdit = true; this.m_pMap = this.m_pHookHelper.FocusMap; if (this.m_pMap == null) { return; } this.m_pMap.ClearSelection(); this.m_pActiveView = this.m_pMap as IActiveView; m_pActiveView.ScreenDisplay.Invalidate(m_pActiveView.Extent.Envelope, true, -1); m_pActiveView.ScreenDisplay.UpdateWindow(); try { m_pActiveViewEvent = (IActiveViewEvents_Event)m_pMap; m_pActiveViewEvent.AfterDraw += new IActiveViewEvents_AfterDrawEventHandler(m_pActiveViewEvent_AfterDraw); } catch (Exception ex) { } if (this.m_clsEditorMain == null) { return; } //this.m_blCanEdit = m_pOperateWorkSpace.InitOperater(nDrawType, ref m_pMap, m_clsEditorMain); if (this.m_blCanEdit == false) { return; } this.m_blCanEdit = m_pDrawLineTrack.InitTrack(nDrawType, ref m_pMap, m_clsEditorMain); if (this.m_blCanEdit == false) { System.Windows.Forms.MessageBox.Show("反馈环境初始化失败!", "系统提示", MessageBoxButtons.OK); return; } isInSubCommand = false; SetNextStep("0"); }
public void AddGraphicToMap(ESRI.ArcGIS.Carto.IMap map, ESRI.ArcGIS.Geometry.IGeometry geometry, ESRI.ArcGIS.Display.IRgbColor rgbColor, ESRI.ArcGIS.Display.IRgbColor outlineRgbColor) { ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)map; // Explicit Cast ESRI.ArcGIS.Carto.IElement element = null; if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { // Marker symbols ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbol(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = frmOptions.sizeOfPoints; simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle; ESRI.ArcGIS.Carto.IMarkerElement markerElement = (IMarkerElement) new ESRI.ArcGIS.Carto.MarkerElement(); markerElement.Symbol = simpleMarkerSymbol; element = (ESRI.ArcGIS.Carto.IElement)markerElement; // Explicit Cast } else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) { // Line elements ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = frmOptions.sizeOfLines; ESRI.ArcGIS.Carto.ILineElement lineElement = (ILineElement) new ESRI.ArcGIS.Carto.LineElement(); lineElement.Symbol = simpleLineSymbol; element = (ESRI.ArcGIS.Carto.IElement)lineElement; // Explicit Cast } else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) { // Polygon elements ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSForwardDiagonal; ESRI.ArcGIS.Carto.IFillShapeElement fillShapeElement = (IFillShapeElement) new ESRI.ArcGIS.Carto.PolygonElement(); fillShapeElement.Symbol = simpleFillSymbol; element = (ESRI.ArcGIS.Carto.IElement)fillShapeElement; // Explicit Cast } if (!(element == null)) { element.Geometry = geometry; graphicsContainer.AddElement(element, 0); } }
/// <summary> /// 根据图层索引获得图层 /// </summary> /// <param name="activeView">当前视图窗口对象</param> /// <param name="layerIndex">图层序号</param> /// <returns></returns> public ESRI.ArcGIS.Carto.IFeatureLayer GetFeatureLayerFromLayerName(ESRI.ArcGIS.Carto.IActiveView activeView, System.String name) { if (activeView == null || name == "") { return(null); } IFeatureLayer fealyr = null; ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; for (int i = 0; i < map.LayerCount; i++) { ICompositeLayer lyrs = map.get_Layer(i) as ICompositeLayer; if (lyrs == null) { continue; } for (int j = 0; j < lyrs.Count; j++) { ILayer lyr = lyrs.get_Layer(j); ICompositeLayer compositrlyr = lyr as ICompositeLayer; if (compositrlyr != null) { for (int k = 0; k < compositrlyr.Count; k++) { ILayer lyr1 = compositrlyr.get_Layer(k); if (lyr1.Name == name) { fealyr = lyr1 as IFeatureLayer; break; } } } else { if (lyr.Name == name) { fealyr = lyr as IFeatureLayer; break; } } } } return(fealyr); }
/// <summary> /// Add the feature layer to the map /// </summary> /// <param name="fc">IFeatureClass</param> private void AddFeatureLayerToMap(IFeatureClass fc) { IFeatureLayer outputFeatureLayer = new FeatureLayerClass(); outputFeatureLayer.FeatureClass = fc; IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer; if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) { IFeatureRenderer pFeatureRender; pFeatureRender = (IFeatureRenderer) new SimpleRenderer(); ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = 3.0; ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pSimpleMarkerSymbol; geoLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else if (geoLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline) { IFeatureRenderer pFeatureRender; pFeatureRender = (IFeatureRenderer) new SimpleRenderer(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pSimpleFillSymbol.Outline.Width = 0.4; ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pSimpleFillSymbol; geoLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } geoLayer.Name = fc.AliasName; ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap; map.AddLayer((ILayer)outputFeatureLayer); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper.Hook == null) { return; } pMapCtl = m_hookHelper.Hook as IMapControl2; ESRI.ArcGIS.Geometry.IGeometry pGeometry = pMapCtl.TrackPolygon(); if (pGeometry == null) { return; } if (pGeometry.GeometryType != esriGeometryType.esriGeometryPolygon) { return; } if (this.WriteLog) { Plugin.LogTable.Writelog("多边形范围制图");//xisheng 日志记录07.08 } drawgeometryXOR(pGeometry as IPolygon, m_pScreenDisplay); ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; SysCommon.CProgress pgss = new SysCommon.CProgress("正在加载制图界面,请稍候..."); pgss.EnableCancel = false; pgss.ShowDescription = false; pgss.FakeProgress = true; pgss.TopMost = true; pgss.ShowProgress(); Application.DoEvents(); frm = new FrmPageLayout(m_hookHelper.FocusMap, pGeometry); frm.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志 frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.typeZHT = 2; frm.Show(); pgss.Close(); pMapCtl.CurrentTool = null; Application.DoEvents(); }
//类的方法 public ImportPolygonQueryToolClass(Form mainFrm, ESRI.ArcGIS.Carto.IMap pMap) { m_mainFrm = mainFrm; base.m_category = "GeoCommon"; base.m_caption = "ImportPolygonQuery"; base.m_message = "导入范围查询"; base.m_toolTip = "导入范围查询"; base.m_name = base.m_category + "_" + base.m_caption; // m_pActiveView = pMap as IActiveView; ////m_pActiveViewEvents = m_pActiveView as IActiveViewEvents_Event;IActiveView //m_pScreenDisplay = m_pActiveView.ScreenDisplay; //try //{ // m_pActiveViewEvents.AfterDraw += new IActiveViewEvents_AfterDrawEventHandler(m_pActiveViewEvents_AfterDraw); //} //catch //{ //} }
public bool ConvertLayerToKML(string kmzOutputPath, string tmpShapefilePath, ESRI.ArcGIS.Carto.IMap map) { try { string kmzName = System.IO.Path.GetFileName(kmzOutputPath); string folderName = System.IO.Path.GetDirectoryName(kmzOutputPath); IGeoProcessor2 gp = new GeoProcessorClass(); IVariantArray parameters = new VarArrayClass(); parameters.Add(tmpShapefilePath); parameters.Add(kmzName); gp.Execute("MakeFeatureLayer_management", parameters, null); IVariantArray parameters1 = new VarArrayClass(); // assign parameters parameters1.Add(kmzName); parameters1.Add(kmzOutputPath); gp.Execute("LayerToKML_conversion", parameters1, null); // Remove the temporary layer from the TOC for (int i = 0; i < map.LayerCount; i++) { ILayer layer = map.get_Layer(i); if (layer.Name == "featureLayer") { map.DeleteLayer(layer); break; } } return(true); } catch (Exception ex) { return(false); } }
private ILayer getLayerByName(string name) { UID pid = new UID(); pid.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.ActiveView.FocusMap; IEnumLayer layers = map.get_Layers(pid, true); ILayer curLayer = layers.Next(); while (curLayer != null) { //System.Windows.Forms.MessageBox.Show("curLayer name is " + curLayer.Name); if (curLayer.Name == name) { return(curLayer); } curLayer = layers.Next(); } return(null); }
/// <summary> /// makes sure that everything necessary to run the NPS tools are loaded and in place /// </summary> public void Init() { m_IsInitialized = false; m_InitErrorMessage = ""; //make sure we have an application object if (m_Application == null) m_InitErrorMessage = "Could not get a hold of the ArcMap instance."; //the toolbar can only work with the specified mxd file if (string.IsNullOrEmpty(m_InitErrorMessage)) if (m_Application.Document.Title != "NPS_Transect_Tool_DOTNET.mxd" && m_Application.Document.Title != "NPS_Transect_Tool_DOTNET") m_InitErrorMessage = "This is not the NPS_Transect_Tool_DOTNET.mxd MXD file.(current file name:" + m_Application.Document.Title + ")"; //get global editor if (string.IsNullOrEmpty(m_InitErrorMessage)) InitEditor(ref m_InitErrorMessage); //wire up handlers to editor events if (string.IsNullOrEmpty(m_InitErrorMessage)) WireEditEvents(m_Editor); //get the currently open map if (string.IsNullOrEmpty(m_InitErrorMessage)) m_Map = m_MxDoc.FocusMap; //set global path to dll if (string.IsNullOrEmpty(m_InitErrorMessage)) InitDLLPath(ref m_InitErrorMessage); //set globals from XML data if (string.IsNullOrEmpty(m_InitErrorMessage)) InitXMLConfig(m_DLLPath, ref m_InitErrorMessage); //set global layer names if (string.IsNullOrEmpty(m_InitErrorMessage)) InitLayers(ref m_InitErrorMessage); //get database/workspace if (string.IsNullOrEmpty(m_InitErrorMessage)) InitDatabase(m_Map, ref m_InitErrorMessage); //if there was an error during initialization, set global init state to false and log if (string.IsNullOrEmpty(m_InitErrorMessage)) m_IsInitialized = true; }
/// <summary> /// uninitialize the nps global instance /// </summary> public void UnInit() { m_IsInitialized = false; Util.SaveConfigSettings(); UnwireEditEvents(m_Editor); m_DLLPath = null; m_Map = null; m_XMLConfig = null; m_XMLConfigFilePath = null; m_Workspace = null; m_DatabasePath = null; m_DLLPath = null; m_Editor = null; m_ProgramaticFeatureEdit = false; m_InitErrorMessage = null; m_LYR_HORIZON = m_LYR_ANIMALS = m_LYR_TRACKLOG = m_LYR_GPSPOINTLOG = m_LYR_RANDOMPOINTS = m_LYR_GENERATED_TRANSECTS = m_LYR_FLAT_AREAS = m_LYR_EXCLUDED_AREAS = m_LYR_SURVEY_BOUNDARY = null; }
public bool ConvertLayerToKML(IFeatureClass fc, string kmzOutputPath, string tmpShapefilePath, ESRI.ArcGIS.Carto.IMap map) { try { string kmzName = System.IO.Path.GetFileName(kmzOutputPath); string folderName = System.IO.Path.GetDirectoryName(kmzOutputPath); var fcName = System.IO.Path.GetFileNameWithoutExtension(kmzName); IFeatureLayer fLayer = new FeatureLayer(); fLayer.FeatureClass = fc; var geoLayer = (fLayer as IGeoFeatureLayer); if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = CoordinateConversionLibrary.Constants.SymbolSize; pSimpleMarkerSymbol.Color = new RgbColorClass() { Red = 255 }; ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pSimpleMarkerSymbol; geoLayer.Name = fcName; geoLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } var featureLayer = geoLayer as FeatureLayer; map.AddLayer(geoLayer); // Initialize the geoprocessor. IGeoProcessor2 gp = new GeoProcessorClass(); IVariantArray parameters = new VarArrayClass(); parameters.Add(featureLayer.Name); parameters.Add(folderName + "\\" + kmzName); var result = gp.Execute(CoordinateConversionLibrary.Constants.LayerToKMLGPTool, parameters, null); // Remove the temporary layer from the TOC for (int i = 0; i < map.LayerCount; i++) { ILayer layer = map.get_Layer(i); if (layer.Name == fcName) { map.DeleteLayer(layer); break; } } return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(false); }
private void buttonOK_Click(object sender, EventArgs e) { this.Visible = false; if (_axmapcontrol != null) { try { IEnvelope penvelope = new EnvelopeClass(); penvelope.XMin = Convert.ToDouble(textBoxWest.Text); penvelope.XMax = Convert.ToDouble(textBoxEast.Text); penvelope.YMax = Convert.ToDouble(textBoxNorth.Text); penvelope.YMin = Convert.ToDouble(textBoxSouth.Text); IPoint pmiddle = new PointClass(); pmiddle.PutCoords((penvelope.XMax + penvelope.XMin) / 2, (penvelope.YMax + penvelope.YMin) / 2);//中心点 IGeometry pGeometry = penvelope as IGeometry; /*-----xisheng 20110802------*/ ISpatialReference earthref = null; ISpatialReference flatref = null; ISpatialReferenceFactory2 pSpatRefFac = new SpatialReferenceEnvironmentClass(); earthref = pSpatRefFac.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); if (_axmapcontrol.MapUnits == esriUnits.esriMeters) { flatref = _axmapcontrol.Map.SpatialReference; pGeometry.SpatialReference = flatref;//yjl20110812 modify //pGeometry.Project(flatref); } /*-----xisheng 20110802------*/ if (pGeometry == null) { return; } if (pGeometry.GeometryType != esriGeometryType.esriGeometryEnvelope) { return; } if (pGeometry.Envelope.Width < 0) { return; } if (this.WriteLog) { Plugin.LogTable.Writelog("坐标范围制图"); } drawgeometryXOR(pGeometry as IEnvelope, _axmapcontrol.ActiveView.ScreenDisplay); ESRI.ArcGIS.Carto.IMap pMap = _axmapcontrol.Map; SysCommon.CProgress pgss = new SysCommon.CProgress("正在加载制图界面,请稍候..."); pgss.EnableCancel = false; pgss.ShowDescription = false; pgss.FakeProgress = true; pgss.TopMost = true; pgss.ShowProgress(); Application.DoEvents(); frm = new FrmPageLayout(pMap, pGeometry); frm.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志 frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.typeZHT = 2; frm.Show(); pgss.Close(); _axmapcontrol.CurrentTool = null; Application.DoEvents(); } catch (Exception ex) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "错误:" + ex.Message); } } }
//创建柱状专题图 public void CreateBarRenderer(int layerID, string[] fields) { // 得到地图服务下的ArcObjects map对象 ESRI.ArcGIS.Server.IServerContext pServerContext = GetServerContext(); ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)pServerContext.ServerObject; ESRI.ArcGIS.Carto.IMapServerObjects2 mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects2)mapServer; string mapName = mapServer.DefaultMapName; ESRI.ArcGIS.Carto.IMap aoMap = mapServerObjects.get_Map(mapName); ESRI.ArcGIS.Carto.ILayer pLayer = aoMap.get_Layer(layerID);//得到图层 ESRI.ArcGIS.Carto.IGeoFeatureLayer pGeoLayer = pLayer as IGeoFeatureLayer; //设置专题图元素的属性名称列表 IChartRenderer pChartRender = pServerContext.CreateObject("esriCarto.ChartRenderer") as IChartRenderer; IRendererFields pRenderFields = pChartRender as IRendererFields; foreach (string var in fields) { pRenderFields.AddField(var, var); } //实例化图表对象并取得元素指定属性的最大值 IBarChartSymbol pBarChartSymbol = pServerContext.CreateObject("esriDisplay.BarChartSymbol") as IBarChartSymbol; IChartSymbol pChartSymbol = pBarChartSymbol as IChartSymbol; pChartSymbol.MaxValue = GetStaMaxMin(fields, pGeoLayer)[0]; pBarChartSymbol.Width = 8; IMarkerSymbol pMarkerSymbol = pBarChartSymbol as IMarkerSymbol; pMarkerSymbol.Size = 50; //设置柱状图每列填充效果 ISymbolArray pSymbolArray = pBarChartSymbol as ISymbolArray; Random ranColor = new Random(); for (int i = 0; i < fields.Length; i++) { IFillSymbol pFillSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as IFillSymbol; pFillSymbol.Color = GetRGB(ranColor.Next(255), ranColor.Next(255), ranColor.Next(255), pServerContext); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); } //设置地图图层背景 ESRI.ArcGIS.Display.ISimpleFillSymbol pFSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol; pFSymbol.Color = GetRGB(239, 228, 249, pServerContext); pChartRender.BaseSymbol = pFSymbol as ISymbol; //应用柱状专题到指定图层 pChartRender.ChartSymbol = pBarChartSymbol as IChartSymbol; pChartRender.Label = "Test"; pChartRender.UseOverposter = false; pChartRender.CreateLegend(); pGeoLayer.Renderer = pChartRender as IFeatureRenderer; //刷新地图显示图表及图例 mapServerObjects.RefreshServerObjects(); Map1.RefreshResource("MapResourceItem0"); Toc1.BuddyControl = "Map1"; //Toc1.Refresh(); Map1.Refresh(); pServerContext.ReleaseContext(); }
//创建饼状专题图 public static void CreatePieTheme(System.Web.UI.Page page, int nLayerID, string[] fields) { if (page == null) { return; } // 得到地图服务下的ArcObjects map对象 ESRI.ArcGIS.Server.IServerContext pServerContext = GetServerContext(page); ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)pServerContext.ServerObject; ESRI.ArcGIS.Carto.IMapServerObjects2 mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects2)mapServer; string mapName = mapServer.DefaultMapName; ESRI.ArcGIS.Carto.IMap aoMap = mapServerObjects.get_Map(mapName); ESRI.ArcGIS.Carto.ILayer pLayer = aoMap.get_Layer(nLayerID);//得到图层 ESRI.ArcGIS.Carto.IGeoFeatureLayer pGeoLayer = pLayer as IGeoFeatureLayer; //设置专题图的属性列表 ESRI.ArcGIS.Carto.IChartRenderer pCharRenderer = pServerContext.CreateObject("esriCarto.ChartRenderer") as IChartRenderer; ESRI.ArcGIS.Carto.IRendererFields pRenderFields = pCharRenderer as IRendererFields; foreach (string var in fields) { pRenderFields.AddField(var, var); } //实例化图表对象并取得元素指定属性的最大值 ESRI.ArcGIS.Display.IPieChartSymbol pPieSym = pServerContext.CreateObject("esriDisplay.PieChartSymbol") as ESRI.ArcGIS.Display.IPieChartSymbol; ESRI.ArcGIS.Display.IChartSymbol pCharSym = pPieSym as ESRI.ArcGIS.Display.IChartSymbol; pPieSym.Clockwise = true; pPieSym.UseOutline = true; pCharSym.MaxValue = GetStaMaxMin(fields, pGeoLayer)[0]; //设置饼图外围线 ISimpleLineSymbol pOutLine = pServerContext.CreateObject("esriDisplay.SimpleLineSymbol") as ISimpleLineSymbol; pOutLine.Color = GetRGB(255, 0, 128, pServerContext); pOutLine.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid; pOutLine.Width = 1; pPieSym.Outline = pOutLine; IMarkerSymbol pMarkSym = pPieSym as IMarkerSymbol; pMarkSym.Size = 5; //设置饼状图填充效果 ESRI.ArcGIS.Display.ISymbolArray pSymArr = pPieSym as ISymbolArray; ISimpleFillSymbol pSimFillSym = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol; pSimFillSym.Color = GetRGB(128, 128, 128, pServerContext); pSimFillSym.Outline = pOutLine; Random randColor = new Random(); for (int i = 0; i < fields.Length; i++) { IFillSymbol pFillSym = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as IFillSymbol; pFillSym.Color = GetRGB(randColor.Next(255), randColor.Next(255), randColor.Next(255), pServerContext); pSymArr.AddSymbol((ISymbol)pFillSym); } //设置地图图层背景 pSimFillSym = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol; pSimFillSym.Color = GetRGB(255, 128, 255, pServerContext); pCharRenderer.BaseSymbol = pSimFillSym as ISymbol; //设置饼状图表属性 IPieChartRenderer pPieChartRenderer = pCharRenderer as IPieChartRenderer; pPieChartRenderer.MinValue = 0.1; pPieChartRenderer.MinSize = 1; pPieChartRenderer.FlanneryCompensation = false; pPieChartRenderer.ProportionalBySum = true; pPieChartRenderer.ProportionalField = fields[0]; pCharRenderer.ChartSymbol = pPieSym as IChartSymbol; pCharRenderer.Label = "面积"; //应用饼状专题到指定图层 pCharRenderer.UseOverposter = false; pCharRenderer.CreateLegend(); pGeoLayer.Renderer = pCharRenderer as IFeatureRenderer; //刷新地图显示图表及图例 mapServerObjects.RefreshServerObjects(); // Map1.RefreshResource("MapResourceItem0"); pServerContext.ReleaseContext(); }
/// <summary> /// Where all of the work is done. Override from TabBaseViewModel /// </summary> internal override void CreateMapElement() { try { IsRunning = true; if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName)) { return; } //base.CreateMapElement(); var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); if (surface == null) { return; } // Determine if selected surface is projected or geographic ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); var geoDataset = surfaceLayer as IGeoDataset; SelectedSurfaceSpatialRef = geoDataset.SpatialReference; if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem) { MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption); return; } if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode) { MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption); return; } using (ComReleaser oComReleaser = new ComReleaser()) { // Create feature workspace IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace"); StartEditOperation((IWorkspace)workspace); // Create feature class IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString()); double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType); double finalSurfaceOffset = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType); double conversionFactor = GetConversionFactor(SelectedSurfaceSpatialRef); double convertedMinDistance = MinDistance * conversionFactor; double convertedMaxDistance = MaxDistance * conversionFactor; double finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType); double finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType); double finalLeftHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType); double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType); double finalBottomVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType); double finalTopVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType); // Out radius geometries List <IGeometry> radius2GeomList = new List <IGeometry>(); List <IGeometry> radius1_2GeomList = new List <IGeometry>(); List <IGeometry> donutGeomList = new List <IGeometry>(); foreach (var observerPoint in ObserverAddInPoints) { // Create buffer geometries for final Min/Max distance ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator; IGeometry geom = topologicalOperator.Buffer(finalMaxDistance); radius2GeomList.Add(geom); radius1_2GeomList.Add(geom); if (finalMinDistance > 0) { IGeometry geom2 = topologicalOperator.Buffer(finalMinDistance); ITopologicalOperator eraseTopo = geom as ITopologicalOperator; IGeometry erasedGeom = eraseTopo.Difference(geom2); donutGeomList.Add(erasedGeom); } else { radius1_2GeomList.Add(geom); } double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset; //create a new point feature IFeature ipFeature = pointFc.CreateFeature(); // Set the field values for the feature SetFieldValues(finalObserverOffset, finalSurfaceOffset, finalMinDistance, finalMaxDistance, finalLeftHorizontalFOV, finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature); if (double.IsNaN(z1)) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); return; } //Create shape IPoint point = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true }; ipFeature.Shape = point; ipFeature.Store(); } IFeatureClassDescriptor fd = new FeatureClassDescriptorClass(); fd.Create(pointFc, null, "OBJECTID"); StopEditOperation((IWorkspace)workspace); try { ILayer layer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); string layerPath = GetLayerPath(layer); IFeatureLayer ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = pointFc; IDataset ipDataset = (IDataset)pointFc; string outputFcName = ipDataset.BrowseName + "_output"; string strPath = ipDataset.Workspace.PathName + "\\" + ipDataset.BrowseName; string outPath = ipDataset.Workspace.PathName + "\\" + outputFcName; IVariantArray parameters = new VarArrayClass(); parameters.Add(layerPath); parameters.Add(strPath); parameters.Add(outPath); esriLicenseStatus status = GetSpatialAnalystLicense(); if (status == esriLicenseStatus.esriLicenseUnavailable || status == esriLicenseStatus.esriLicenseFailure || status == esriLicenseStatus.esriLicenseNotInitialized || status == esriLicenseStatus.esriLicenseNotLicensed || status == esriLicenseStatus.esriLicenseUnavailable) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); return; } IGeoProcessor2 gp = new GeoProcessorClass(); gp.AddOutputsToMap = false; // Add a mask to buffer the output to selected distance SetGPMask(workspace, radius2GeomList, gp, "radiusMask"); object oResult = gp.Execute("Visibility_sa", parameters, null); IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult; ComReleaser.ReleaseCOMObject(gp); gp = null; GC.Collect(); // Add buffer geometries to the map foreach (IGeometry geom in radius1_2GeomList) { var color = new RgbColorClass() { Blue = 255 } as IColor; AddGraphicToMap(geom, color, true); } IRasterLayer outputRasterLayer = new RasterLayerClass(); outputRasterLayer.CreateFromFilePath(outPath); string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, donutGeomList); IFeatureClass finalFc = workspace.OpenFeatureClass(fcName); IFeatureLayer outputFeatureLayer = new FeatureLayerClass(); outputFeatureLayer.FeatureClass = finalFc; //Add it to a map if the layer is valid. if (outputFeatureLayer != null) { // set the renderer IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc); IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer; geoLayer.Renderer = featRend; geoLayer.Name = "RLOS_Visibility_" + RunCount.ToString(); // Set the layer transparency IDisplayFilterManager filterManager = (IDisplayFilterManager)outputFeatureLayer; ITransparencyDisplayFilter filter = new TransparencyDisplayFilter(); filter.Transparency = 80; filterManager.DisplayFilter = filter; ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap; map.AddLayer((ILayer)outputFeatureLayer); IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope; ZoomToExtent(envelope); } RunCount += 1; } catch (Exception ex) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); } //Reset(true); } } catch (Exception ex) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); } finally { IsRunning = false; } }
public void execute() { // check if the status is ready (all the attributes have been set and parent is known // execute and return the features and set them to _features // compare the features with what is expected in parent. If it matches, transfer the values to the parent and set the paramNode to be complete. ESRI.ArcGIS.Carto.IMap map = null; ESRI.ArcGIS.Carto.IMapDocument tempDoc = new ESRI.ArcGIS.Carto.MapDocument(); string filePath = this.sourceName; ESRI.ArcGIS.Carto.IMapDocument mapDoc = new ESRI.ArcGIS.Carto.MapDocument(); if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath)) { mapDoc.Open(filePath, string.Empty); // set the first map as the active view map = mapDoc.get_Map(0); for (int i = 0; i < map.LayerCount; i++) { IFeatureLayer layer = map.get_Layer(i) as IFeatureLayer; Console.WriteLine("layer=====" + layer.Name); if (layer.Name == this.sourceLayer) { layer.Selectable = true; IQueryFilter queryFilter = new QueryFilterClass(); // queryFilter.WhereClause = this.query; queryFilter.WhereClause = "ZONE_ = 'A'"; IFeatureSelection pFeatureSelection = layer as IFeatureSelection; pFeatureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); //pFeatureSelection.SelectionSet. if (pFeatureSelection.SelectionSet.Count == 0) { Console.WriteLine("No features found for" + this.query); } else { //for (int j = 0; j < pFeatureSelection.SelectionSet.Count; j++) //{ // IFeature f = (pFeatureSelection as IFeatureLayer).FeatureClass.GetFeature(j); // this.parent.Values.Add(f); //} IFeatureClass featureClass = layer.FeatureClass; //use an IEnumIDs to read the SelectionSet IDs IEnumIDs enumIDs = pFeatureSelection.SelectionSet.IDs; int fieldIndex1 = featureClass.FindField("SHAPE_Length"); int fieldIndex2 = featureClass.FindField("SHAPE_Area"); string s = "{0}ID \t\tSHAPE_Length \t\tSHAPE_Area"; IFeature feature; IDataset dataset = (IDataset)featureClass; int iD = enumIDs.Next(); while (iD != -1) //-1 is reutned after the last valid ID has been reached { feature = featureClass.GetFeature(iD); s += "{0}" + iD + ":\t\t" + feature.get_Value(fieldIndex1) + "\t\t" + feature.get_Value(fieldIndex2); iD = enumIDs.Next(); } //report some information about the selection // we need to store this result back to the VALUES of the Parent's node, which is a ParamNode. Console.WriteLine("A SelectionSet containing: {1} Rows {0}has been created using the query: {2} {0}this selection set was created on the feature class: {3}{0}" + s + "{0}", Environment.NewLine, pFeatureSelection.SelectionSet.Count, queryFilter.WhereClause, dataset.Name); } } } } }