//简单渲染专题图 private void button1_Click(object sender, EventArgs e) { //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; simpleFillSymbol.Color = getRGB(255, 0, 0); //创建边线符号 ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; simpleLineSymbol.Color = getRGB(0, 255, 0); ISymbol symbol = simpleLineSymbol as ISymbol; symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; simpleFillSymbol.Outline = simpleLineSymbol; ISimpleRenderer simpleRender = new SimpleRendererClass(); simpleRender.Symbol = simpleFillSymbol as ISymbol; simpleRender.Label = "NAME"; simpleRender.Description = "东丰县行政区域"; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer("东丰县行政区域"); if (geoFeatureLayer != null) { geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer; } this.axMapControl1.Refresh(); }
// Save config and exit. private void okButton_Click(object sender, EventArgs e) { try { ISimpleFillSymbol selectionSymbol = new SimpleFillSymbolClass(); selectionSymbol.Color = selFillColorPaletteButton.Color; selectionSymbol.Color.Transparency = Convert.ToByte(255 - Convert.ToDouble(selTranNumericUpDown.Value) * 2.55); ISimpleLineSymbol selectionOutlineSymbol = new SimpleLineSymbolClass(); selectionOutlineSymbol.Color = selOutlineColorPaletteButton.Color; selectionOutlineSymbol.Width = Convert.ToDouble(selOutlineWidthNumericUpDown.Value); selectionSymbol.Outline = selectionOutlineSymbol; Config.SelectionSmbol = selectionSymbol; ISimpleFillSymbol editSymbol = new SimpleFillSymbolClass(); editSymbol.Color = editFillColorColorPaletteButton.Color; editSymbol.Color.Transparency = Convert.ToByte(255 - Convert.ToDouble(editTranNumericUpDown.Value) * 2.55); ISimpleLineSymbol editOutlineSymbol = new SimpleLineSymbolClass(); editOutlineSymbol.Color = editOutlineColorPaletteButton.Color; editOutlineSymbol.Width = Convert.ToDouble(editOutlineWidthNumericUpDown.Value); editSymbol.Outline = editOutlineSymbol; Config.EditSymbol = editSymbol; Config.CustormEditColor = editCustomCheckBox.Checked; Config.Save(); Editor.Refresh(); Close(); } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } }
public static IRasterRenderer ClassifyRenderer(IRasterLayer raslyr,IRgbColor start_clr,IRgbColor end_clr,int count) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass(); IRasterRenderer rasterRenderer = pRClassRend as IRasterRenderer; IRaster pRaster = raslyr.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if (pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } rasterRenderer.Raster = pRaster; pRClassRend.ClassCount = count; rasterRenderer.Update(); IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass(); colorRamp.Size = count; colorRamp.FromColor = start_clr; colorRamp.ToColor = end_clr; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbolClass(); for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } return rasterRenderer; }
/// <summary> /// 简单渲染 /// </summary> /// <param name="layerName">图层名字</param> /// <param name="FillStyle">FillStyle</param> /// <param name="pColor">FillColor</param> /// <param name="OutLineColor">OutLineColor</param> /// <param name="RenderLabel">样式名称注释</param> /// <param name="Descripition">描述</param> public void createSimpleFillSymbol(string layerName, esriSimpleFillStyle FillStyle, IColor pColor, IColor OutLineColor, string RenderLabel, string Descripition) { //简单填充符号 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); //可以用符号选择器进行 simpleFillSymbol.Style = FillStyle; simpleFillSymbol.Color = pColor; //创建边线符号 ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Color = OutLineColor; ISymbol symbol = simpleLineSymbol as ISymbol; symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; simpleFillSymbol.Outline = simpleLineSymbol; ISimpleRenderer simpleRender = new SimpleRendererClass(); simpleRender.Symbol = simpleFillSymbol as ISymbol; simpleRender.Label = RenderLabel; simpleRender.Description = Descripition; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = getGeoLayer(layerName); if (geoFeatureLayer != null) { geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer; } }
public static IFillSymbol CreateFillSymbol(Color fillColor, esriSimpleFillStyle eFillStyle, ISimpleLineSymbol aOutline) { SimpleFillSymbolClass class2 = new SimpleFillSymbolClass(); class2.Style = eFillStyle; class2.Color = ColorHelper.CreateColor(fillColor); class2.Outline = aOutline; return class2; }
public static ISimpleFillSymbol get_SimplePolygonSymbol(IColor color, esriSimpleFillStyle style, ILineSymbol outline) { ISimpleFillSymbol theReturn = new SimpleFillSymbolClass(); theReturn.Color = color; theReturn.Style = style; theReturn.Outline = outline; return theReturn; }
private static ISimpleFillSymbol CreateSimpleFillSymbol(int red, int green, int blue) { ISimpleFillSymbol sfs = new SimpleFillSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = red; color.Green = green; color.Blue = blue; sfs.Color = color; return sfs; }
/// <summary> /// Get the paint symble of painted pixel. /// </summary> /// <param name="filledColor">Fill color for the symbol</param> /// <returns></returns> public static ISimpleFillSymbol GetPaintSymbol(IColor filledColor) { ISimpleFillSymbol selectionSymbol = new SimpleFillSymbolClass(); selectionSymbol.Color = filledColor; ISimpleLineSymbol selectionOutlineSymbol = new SimpleLineSymbolClass(); selectionOutlineSymbol.Color = new RgbColorClass() { Red = 255, Green = 255, Blue = 0 }; selectionOutlineSymbol.Width = 2; selectionSymbol.Outline = selectionOutlineSymbol; return selectionSymbol; }
// Methods public static IFillSymbol CreateFillSymbol(Color fillColor, Color outlineColor) { SimpleFillSymbolClass class2 = new SimpleFillSymbolClass(); class2.Style = esriSimpleFillStyle.esriSFSSolid; class2.Color = ColorHelper.CreateColor(fillColor); ISimpleLineSymbol symbol = new SimpleLineSymbolClass(); symbol.Style = esriSimpleLineStyle.esriSLSSolid; symbol.Color = ColorHelper.CreateColor(outlineColor); symbol.Width = 1.0; class2.Outline = symbol; return class2; }
public static IFillSymbol CreateFillSymbol(Color fillColor, esriSimpleFillStyle eFillStyle, Color outlineColor, double outlineWidth, esriSimpleLineStyle outlineStyle) { SimpleFillSymbolClass class2 = new SimpleFillSymbolClass(); class2.Style = eFillStyle; class2.Color = ColorHelper.CreateColor(fillColor); ISimpleLineSymbol symbol = new SimpleLineSymbolClass(); symbol.Style = outlineStyle; symbol.Color = ColorHelper.CreateColor(outlineColor); symbol.Width = outlineWidth; class2.Outline = symbol; return class2; }
public ProPortialRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, string pFieldName) { IGeoFeatureLayer pGeo = pFtLayer as IGeoFeatureLayer; IProportionalSymbolRenderer pProRender = new ProportionalSymbolRendererClass(); pProRender.Field = pFieldName; pProRender.ValueUnit = esriUnits.esriUnknownUnits; ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pMarkerSymbol.Size = 2; pMarkerSymbol.Color = GetRGBColor(255, 0, 0); pProRender.MinSymbol = pMarkerSymbol as ISymbol; IDataStatistics pDataStat = new DataStatisticsClass(); IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); pDataStat.Cursor = pFtCursor as ICursor; pDataStat.Field = pFieldName; pProRender.MinDataValue = pDataStat.Statistics.Minimum; pProRender.MaxDataValue = pDataStat.Statistics.Maximum; IFillSymbol pFillS = new SimpleFillSymbolClass(); pFillS.Color = GetRGBColor(239, 228, 190); ILineSymbol pLineS = new SimpleLineSymbolClass(); pLineS.Width = 2; pFillS.Outline = pLineS; ISimpleFillSymbol pSFillS = pFillS as ISimpleFillSymbol; pSFillS.Color = GetRGBColor(100, 100, 253); pProRender.BackgroundSymbol = pFillS; pGeo.Renderer = pProRender as IFeatureRenderer; pMapcontrol.ActiveView.Refresh(); }
public static IElement ConstructMultiPatchElement(IGeometry geometry, IColor color) { ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; IElement element = new MultiPatchElementClass(); element.Geometry = geometry; IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = simpleFillSymbol; return element; }
private void MainForm_Load(object sender, EventArgs e) { m_mapControl = (IMapControl3) axMapControl1.Object; //relative file path to the sample data from EXE location string filePath = @"..\..\..\data\USAMajorHighways"; //Add Lakes layer IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Lakes"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("us_lakes"); #region create a SimplerRenderer IRgbColor color = new RgbColorClass(); color.Red = 190; color.Green = 232; color.Blue = 255; ISimpleFillSymbol sym = new SimpleFillSymbolClass(); sym.Color = color; ISimpleRenderer renderer = new SimpleRendererClass(); renderer.Symbol = sym as ISymbol; #endregion ((IGeoFeatureLayer)featureLayer).Renderer = renderer as IFeatureRenderer; axMapControl1.Map.AddLayer((ILayer)featureLayer); //Add Highways layer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Highways"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("usa_major_highways"); axMapControl1.Map.AddLayer((ILayer)featureLayer); //******** Important ************* //store a reference to this form (Mainform) using the EditHelper class EditHelper.TheMainForm = this; EditHelper.IsEditorFormOpen = false; //add the EditCmd command to the toolbar axEditorToolbar.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem(new EditCmd(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); }
public static void SetLayerColor(IGeoFeatureLayer geolyr, int r, int g, int b) { //ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); //pLineSymbol.Color = CvtRGB(r, g, b); ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = CvtRGB(r, g, b); //pFillSymbol.Outline = pLineSymbol; ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = (ISymbol)pFillSymbol; geolyr.Renderer = pSimpleRenderer as IFeatureRenderer; }
public SimpleRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, String Field) { IGeoFeatureLayer pGeolayer; IActiveView pActiveView; pGeolayer = pFtLayer as IGeoFeatureLayer; pActiveView = pMapcontrol.ActiveView; IFillSymbol pFillSymbol; ILineSymbol pLineSymbol; pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = GetRGBColor(220, 110, 200); pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = GetRGBColor(255, 120, 105); pLineSymbol.Width = 2; pFillSymbol.Outline = pLineSymbol; ISimpleRenderer pSimpleRender;//��ʲô������Ⱦ pSimpleRender = new SimpleRendererClass(); pSimpleRender.Symbol = pFillSymbol as ISymbol ; pSimpleRender.Description = "China"; pSimpleRender.Label = "SimpleRender"; ITransparencyRenderer pTrans; pTrans = pSimpleRender as ITransparencyRenderer; pTrans.TransparencyField = Field; pGeolayer.Renderer = pTrans as IFeatureRenderer; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //����ͼ�����Ⱦ������һ��Ҫ����Ⱦ���������������һЩ��ض�����ɵġ� //����Ҳ��һ������˵�����������С������ɵġ� }
/// <summary> /// 唯一值法渲染器(UniqueValueRender)——根据特征的某不同属性值来绘制该特征的符号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 唯一值法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //定义IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口 IGeoFeatureLayer geoFeatureLayer = getGeoLayer("北部湾"); //使用查询的方式, 获得参与渲染的记录条数 int get_Count = geoFeatureLayer.FeatureClass.FeatureCount(null); //提供操作唯一值的相关成员 IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); //设置渲染的字段个数范围:0~3个 //这里仅设置1个字段 uniqueValueRenderer.FieldCount = 1; //设置渲染字段, 并制定到索引处 //索引从0开始; 设定渲染字段为"地市名" uniqueValueRenderer.set_Field(0, "地市名"); //简单填充符号 ISimpleFillSymbol simpleFillSymbol; //获得指向渲染要素的游标 IFeatureCursor pFtCursor = geoFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature; if (pFtCursor != null) { //定义枚举颜色带, 调用函数, 生成随机颜色带 IEnumColors enumColors = CreateRandomColorRamp(get_Count).Colors; //查找到"地市名"字段的索引(index) int fieldIndex = geoFeatureLayer.FeatureClass.Fields.FindField("地市名"); while ((pFeature = pFtCursor.NextFeature()) != null) { //获取要素值 string nameValue = pFeature.get_Value(fieldIndex).ToString(); //实例化填充符号 //使用填充符号来赋值地图的背景值 simpleFillSymbol = new SimpleFillSymbolClass(); //给要素附上样式 simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //给要素附上颜色 simpleFillSymbol.Color = enumColors.Next() as IColor; //值和符号对应 uniqueValueRenderer.AddValue(nameValue, "地市", simpleFillSymbol as ISymbol); } } //赋值目标图层的渲染器属性 geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }
private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { //创建鹰眼中线框 IEnvelope pEnv = (IEnvelope)e.newEnvelope; IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pEle = pRectangleEle as IElement; pEle.Geometry = pEnv; //设置线框的边线对象,包括颜色和线宽 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; // 产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 2; pOutline.Color = pColor; // 设置颜色属性 pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; // 设置线框填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pEle as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; // 得到鹰眼视图中的图形元素容器 IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; // 在绘制前,清除 axMapControl2 中的任何图形元素 pGra.DeleteAllElements(); // 鹰眼视图中添加线框 pGra.AddElement((IElement)pFillShapeEle, 0); // 刷新鹰眼 pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public AdvanceForm() { InitializeComponent(); simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Width = 4; simpleLineSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 99); simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; simpleMarkerSymbol.Size = 8; simpleMarkerSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 0); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; simpleFillSymbol.Outline = simpleLineSymbol; simpleLineSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 0); }
private IFillSymbol method_7() { ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass { Red = 255, Blue = 255, Green = 255 }; symbol.Color = color; symbol.Outline = null; return(symbol); }
public IFillSymbol GetBackStyle() { ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass { Red = 255, Blue = 255, Green = 255 }; symbol.Color = color; symbol.Outline = null; return(symbol); }
public static IElement ConstructMultiPatchElement(IGeometry geometry, IColor color) { ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; IElement element = new MultiPatchElementClass(); element.Geometry = geometry; IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = simpleFillSymbol; return(element); }
protected override void OnClick() { try { IMxDocument mxDoc = ArcMap.Document; IMap map = mxDoc.FocusMap; IGraphicsContainer graphicsCon = map as IGraphicsContainer; graphicsCon.Reset(); IElement element = graphicsCon.Next(); IRgbColor red = new RgbColor(); red.Blue = 0; red.Green = 0; red.Red = 255; IRgbColor green = new RgbColor(); green.Blue = 0; green.Green = 255; green.Red = 0; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = green; fillSymbol.Outline.Color = red; // This change did not change the outline color in the display (a bug at 10.1) fillSymbol.Outline.Width = 3.0; // // This change did not change the outline width in the display (a bug at 10.1) // For assigning the symbol // -------------------------------------------------------------------------------- (element as IFillShapeElement).Symbol = fillSymbol; // -------------------------------------------------------------------------------- graphicsCon.DeleteAllElements(); (graphicsCon as IActiveView).Refresh(); graphicsCon.AddElement(element, 0); (graphicsCon as IActiveView).Refresh(); } catch (Exception myEx) { System.Diagnostics.Debug.WriteLine(myEx.Message + " " + myEx.Source.ToString()); } ArcMap.Application.CurrentTool = null; }
///<summary>Draw a specified graphic on the map using the supplied colors.</summary> /// ///<param name="map">An IMap interface.</param> ///<param name="geometry">An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon.</param> ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param> ///<param name="outlineRgbColor">An IRgbColor interface. For those geometry's with an outline it will be this color.</param> /// ///<remarks>Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh.</remarks> public void AddGraphicToMap(IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor) { IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast IElement element = null; if ((geometry.GeometryType) == esriGeometryType.esriGeometryPoint) { // Marker symbols ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = (IElement)markerElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolyline) { // Line elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 5; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol; element = (IElement)lineElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolygon) { // Polygon elements ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast } if (!(element == null)) { element.Geometry = geometry; graphicsContainer.AddElement(element, 0); } }
protected override void OnClick() { try { IMxDocument mxDoc = ArcMap.Document; IMap map = mxDoc.FocusMap; IGraphicsContainer graphicsCon = map as IGraphicsContainer; graphicsCon.Reset(); IElement element = graphicsCon.Next(); IRgbColor red = new RgbColor(); red.Blue = 0; red.Green = 0; red.Red = 255; IRgbColor green = new RgbColor(); green.Blue = 0; green.Green = 255; green.Red = 0; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = green; fillSymbol.Outline.Color = red; // This change did not change the outline color in the display (a bug at 10.1) fillSymbol.Outline.Width = 3.0; // // This change did not change the outline width in the display (a bug at 10.1) // For assigning the symbol // -------------------------------------------------------------------------------- (element as IFillShapeElement).Symbol = fillSymbol; // -------------------------------------------------------------------------------- graphicsCon.DeleteAllElements(); (graphicsCon as IActiveView).Refresh(); graphicsCon.AddElement(element, 0); (graphicsCon as IActiveView).Refresh(); } catch (Exception myEx) { System.Diagnostics.Debug.WriteLine(myEx.Message + " " + myEx.Source.ToString()); } ArcMap.Application.CurrentTool = null; }
private void axPageLayoutControl1_OnExtentUpdated(object sender, IPageLayoutControlEvents_OnExtentUpdatedEvent e) { //QI for IEnvelope IEnvelope envelope = (IEnvelope)e.newEnvelope; //Get the IElement interface by finding an element by its name IElement element = m_PageLayoutControl.FindElementByName("ZoomExtent", 1); if (element != null) { //Delete the graphic m_PageLayoutControl.GraphicsContainer.DeleteElement(element); } element = new RectangleElementClass(); //Get the IRGBColor interface IRgbColor color = new RgbColorClass(); //Set the color properties color.RGB = 255; color.Transparency = 255; //Get the ILine symbol interface ILineSymbol outline = new SimpleLineSymbolClass(); //Set the line symbol properties outline.Width = 10; outline.Color = color; //Set the color properties color = new RgbColorClass(); color.RGB = 255; color.Transparency = 0; //Get the IFillSymbol properties IFillSymbol fillSymbol = new SimpleFillSymbolClass(); //Set the fill symbol properties fillSymbol.Color = color; fillSymbol.Outline = outline; //QI for IFillShapeElement interface through the IElement interface IFillShapeElement fillShapeElement = (IFillShapeElement)element; //Set the symbol property fillShapeElement.Symbol = fillSymbol; //Add the element m_PageLayoutControl.AddElement(element, e.newEnvelope, Type.Missing, "ZoomExtent", -1); //Refresh the graphics m_PageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing); }
private List <IElement> CreateElementAois(List <IPolygon> polygons, out IEnvelope encompassingEnvelope) { var rgbColor = new RgbColorClass { Red = 0, Green = 0, Blue = 255, Transparency = 200 }; var geometryBag = new GeometryBagClass(); geometryBag.SpatialReference = ArcMap.Document.FocusMap.SpatialReference; IGeometryCollection geometryCollection = geometryBag; var elements = new List <IElement>(); foreach (var polygon in polygons) { geometryCollection.AddGeometry(polygon); IElement element = null; // Polygon elements ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = rgbColor; lineSymbol.Width = 2.0; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull; simpleFillSymbol.Outline = lineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast element.Geometry = polygon; elements.Add(element); } // Create the polygon that will be the union of the features returned from the search cursor. // The spatial reference of this feature does not need to be set ahead of time. The // ConstructUnion method defines the constructed polygon's spatial reference to be the same as // the input geometry bag. ITopologicalOperator unionedPolygon = new PolygonClass(); unionedPolygon.ConstructUnion(geometryBag); var masterPoly = (IPolygon)unionedPolygon; encompassingEnvelope = masterPoly.Envelope; return(elements); }
//ProportionalSymbolRenderer private void button4_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; IProportionalSymbolRenderer proportionalSymbolRenderer; ITable table; ICursor cursor; IDataStatistics dataStatistics; IStatisticsResults statisticsResult; stdole.IFontDisp fontDisp; geoFeatureLayer = getGeoLayer("Continents"); featureLayer = geoFeatureLayer as IFeatureLayer; table = geoFeatureLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = "sqmi"; statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; fontDisp.Name = "arial"; fontDisp.Size = 20; characterMarkerSymbol.Font = fontDisp; characterMarkerSymbol.CharacterIndex = 90; characterMarkerSymbol.Color = getRGB(255, 0, 0); characterMarkerSymbol.Size = 8; proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; proportionalSymbolRenderer.Field = "sqmi"; proportionalSymbolRenderer.FlanneryCompensation = false; proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 10; proportionalSymbolRenderer.CreateLegendSymbols(); geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } this.axMapControl1.Refresh(); }
public void ProportionalRenderer1(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, int size) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; IProportionalSymbolRenderer proportionalSymbolRenderer; ITable table; ICursor cursor; IDataStatistics dataStatistics; IStatisticsResults statisticsResult; stdole.IFontDisp fontDisp; geoFeatureLayer = featLayer as IGeoFeatureLayer; featureLayer = geoFeatureLayer as IFeatureLayer; table = geoFeatureLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = fieldName; statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = colorRamp.get_Color(0); ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; fontDisp.Name = "arial"; fontDisp.Size = 20; characterMarkerSymbol.Font = fontDisp; characterMarkerSymbol.CharacterIndex = 90; characterMarkerSymbol.Color = colorRamp.get_Color(4); characterMarkerSymbol.Size = size; proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; proportionalSymbolRenderer.Field = fieldName; proportionalSymbolRenderer.FlanneryCompensation = false; proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 10; proportionalSymbolRenderer.CreateLegendSymbols(); geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } }
///<summary>Draw a specified graphic on the map using the supplied colors.</summary> /// ///<param name="map">An IMap interface.</param> ///<param name="geometry">An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon.</param> ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param> ///<param name="outlineRgbColor">An IRgbColor interface. For those geometry's with an outline it will be this color.</param> /// ///<remarks>Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh.</remarks> public void AddGraphicToMap(IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor) { IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast IElement element = null; if ((geometry.GeometryType) == esriGeometryType.esriGeometryPoint) { // Marker symbols ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = (IElement)markerElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolyline) { // Line elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 5; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol; element = (IElement)lineElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolygon) { // Polygon elements ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast } if (!(element == null)) { element.Geometry = geometry; graphicsContainer.AddElement(element, 0); } }
public void AddCallout(IPoint pPoint, string strText) { DF2DApplication app = DF2DApplication.Application; m_ActiveView = app.Current2DMapControl.ActiveView; IGraphicsContainer pGraphicsContainer = m_ActiveView.GraphicsContainer; IPoint pPointText = new PointClass(); pPointText.PutCoords(pPoint.X + 1.5, pPoint.Y + 1.5); ITextElement pTextElement = new TextElementClass(); IFormattedTextSymbol pTextSymbol = new TextSymbolClass(); IElement pElement = pTextElement as IElement; pTextElement.Text = strText; pTextElement.ScaleText = true; pElement.Geometry = pPointText; IRgbColor pRgbColor = GetRGBColor(255, 255, 0); ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass(); pSmplFill.Color = pRgbColor; pSmplFill.Style = esriSimpleFillStyle.esriSFSHollow; IBalloonCallout pBalloonCallout = new BalloonCalloutClass(); pBalloonCallout.Symbol = pSmplFill; pBalloonCallout.Style = esriBalloonCalloutStyle.esriBCSOval; pBalloonCallout.AnchorPoint = pPointText; pBalloonCallout.LeaderTolerance = 5; pRgbColor = GetRGBColor(255, 0, 0); pTextSymbol.Background = pBalloonCallout as ITextBackground; pTextSymbol.Color = pRgbColor; pTextSymbol.Size = (app.Current2DMapControl.MapScale / 100) * 5; //pTextSymbol.Size = 25; pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTextElement.Symbol = pTextSymbol; pGraphicsContainer.AddElement(pElement, 1); }
private void MakeLegend(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv) { UID pID = new UID(); pID.Value = "esriCarto.Legend"; IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null); //根据唯一标示符,创建与之对应MapSurroundFrame IElement pDeletElement = axPageLayoutControl1.FindElementByName("Legend"); //获取PageLayout中的图例元素 if (pDeletElement != null) { pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在图例,删除已经存在的图例 } //设置MapSurroundFrame背景 ISymbolBackground pSymbolBackground = new SymbolBackgroundClass(); IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = m_OperatePageLayout.GetRgbColor(0, 0, 0); pFillSymbol.Color = m_OperatePageLayout.GetRgbColor(240, 240, 240); pFillSymbol.Outline = pLineSymbol; pSymbolBackground.FillSymbol = pFillSymbol; pMapSurroundFrame.Background = pSymbolBackground; //添加图例 IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnv as IGeometry; IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; ILegend pLegend = pMapSurround as ILegend; pLegend.ClearItems(); pLegend.Title = "图例"; for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++) { ILegendItem pLegendItem = new HorizontalLegendItemClass(); pLegendItem.Layer = pActiveView.FocusMap.get_Layer(i);//获取添加图例关联图层 pLegendItem.ShowDescriptions = false; pLegendItem.Columns = 1; pLegendItem.ShowHeading = true; pLegendItem.ShowLabels = true; pLegend.AddItem(pLegendItem);//添加图例内容 } pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public static IRasterRenderer ClassifyRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset pRasterDataset) { try { //create the classify render:创建渲染器 IRasterClassifyColorRampRenderer pClassifyRenderer = new RasterClassifyColorRampRendererClass(); IRasterRenderer pRasterRenderer = (IRasterRenderer)pClassifyRenderer; IRaster pRaster = pRasterDataset.CreateDefaultRaster(); pRasterRenderer.Raster = pRaster; pClassifyRenderer.ClassCount = 10; pRasterRenderer.Update(); //创建颜色 IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 0; pToColor.Green = 255; pToColor.Blue = 255; //set the color ramp for the symbology:生成色带 IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass(); pRamp.Size = 10; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool pBoolColorRamp; pRamp.CreateRamp(out pBoolColorRamp); //create the symbol for the classes.:创建符号 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); for (int i = 0; i < pClassifyRenderer.ClassCount; i++) { pFillSymbol.Color = pRamp.get_Color(i); pClassifyRenderer.set_Symbol(i, (ISymbol)pFillSymbol); pClassifyRenderer.set_Label(i, Convert.ToString(i)); } return(pRasterRenderer); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }
public void Init(int int_1) { if (int_1 == 1) { this.double_0 = 0.1; this.double_1 = 0.1; this.double_2 = 1.0; this.double_3 = 1.0; this.double_4 = 0.1; } ISymbol item = new SimpleMarkerSymbolClass(); (item as ISimpleMarkerSymbol).Style = esriSimpleMarkerStyle.esriSMSCircle; this.lstSymbol.Add(item); this.lstSymHeader.Add("圆retr678978"); item = new SimpleMarkerSymbolClass(); (item as ISimpleMarkerSymbol).Style = esriSimpleMarkerStyle.esriSMSCross; this.lstSymbol.Add(item); this.lstSymHeader.Add("十字形"); item = new SimpleMarkerSymbolClass(); (item as ISimpleMarkerSymbol).Style = esriSimpleMarkerStyle.esriSMSDiamond; this.lstSymbol.Add(item); this.lstSymHeader.Add("菱形"); item = new SimpleLineSymbolClass(); (item as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSDashDot; this.lstSymbol.Add(item); this.lstSymHeader.Add("线"); item = new SimpleLineSymbolClass(); (item as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid; this.lstSymbol.Add(item); this.lstSymHeader.Add("线2"); item = new SimpleLineSymbolClass(); (item as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSDashDot; (item as ISimpleLineSymbol).Width = 3.0; this.lstSymbol.Add(item); this.lstSymHeader.Add("线3"); item = new SimpleFillSymbolClass(); (item as ISimpleFillSymbol).Style = esriSimpleFillStyle.esriSFSBackwardDiagonal; this.lstSymbol.Add(item); this.lstSymHeader.Add("面1"); item = new SimpleFillSymbolClass(); (item as ISimpleFillSymbol).Style = esriSimpleFillStyle.esriSFSHorizontal; this.lstSymbol.Add(item); this.lstSymHeader.Add("面2"); }
//获得三维视图的显示范围,并在二维地图上显示 private void GlobeControl_DisplayEvents_AfterDraw(ISceneViewer pViewer) { IEnvelope m_MapExtent = new EnvelopeClass(); IGlobeViewUtil m_GlobeViewUtil = axGlobeControl1.GlobeCamera as IGlobeViewUtil; m_GlobeViewUtil.QueryVisibleGeographicExtent(m_MapExtent); IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; pGra.DeleteAllElements(); IRectangleElement rec = new RectangleElementClass(); IElement ele = rec as IElement; ele.Geometry = m_MapExtent; IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; ILineSymbol line = new SimpleLineSymbolClass(); line.Color = pColor; line.Width = 2; pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; IFillSymbol fill = new SimpleFillSymbolClass(); fill.Outline = line; fill.Color = pColor; IFillShapeElement pFillElement = ele as IFillShapeElement; pFillElement.Symbol = fill; pGra.AddElement((IElement)pFillElement, 0); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void FlashPolygon(IScreenDisplay pDisplay, IGeometry pGeometry) { ISimpleFillSymbol symbol = new SimpleFillSymbolClass { Outline = null }; IRgbColor color = new RgbColorClass { Green = 128 }; ISymbol sym = (ISymbol)symbol; sym.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pDisplay.SetSymbol(sym); pDisplay.DrawPolygon(pGeometry); Thread.Sleep(300); pDisplay.DrawPolygon(pGeometry); }
public static ISimpleFillSymbol CreateSimpleFillSymbol(IRgbColor fillColor, esriSimpleFillStyle fillStyle, IRgbColor borderColor, esriSimpleLineStyle borderStyle, System.Double borderWidth) { if (fillColor == null || fillStyle == null || borderColor == null || borderStyle == null) { return null; } ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Width = borderWidth; simpleLineSymbol.Color = borderColor; simpleLineSymbol.Style = borderStyle; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Outline = simpleLineSymbol; simpleFillSymbol.Style = fillStyle; simpleFillSymbol.Color = fillColor; return simpleFillSymbol; }
public SearchTool(string layerName, AdvanceForm father, bool Busy = false) { LayerName = layerName; _father = father; BusyFlag = Busy; simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Width = 4; simpleLineSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 99); simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; simpleMarkerSymbol.Size = 8; simpleMarkerSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 0); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; simpleFillSymbol.Outline = simpleLineSymbol; simpleLineSymbol.Color = DisplayExtensions.GetRGBColor(255, 0, 0); }
public static void funColorForRaster_Classify(IRasterLayer pRasterLayer, int ClassNum) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass(); IRasterRenderer pRRend = pRClassRend as IRasterRenderer; IRaster pRaster = pRasterLayer.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if (pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } pRRend.Raster = pRaster; pRClassRend.ClassCount = ClassNum; pRRend.Update(); IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 0;//绿 pFromColor.Green = 255; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 255;//红 pToColor.Green = 0; pToColor.Blue = 0; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass(); colorRamp.Size = ClassNum; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbolClass(); for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, (i + 1).ToString()); } pRasterLayer.Renderer = pRRend; MainFrom.m_mapControl.AddLayer(pRasterLayer); }
/// <summary> /// Gets the element. /// </summary> /// <param name="pGeo">The p geo.</param> /// <param name="strElementName">Name of the STR element.</param> /// <returns></returns> /// 函数需要改进 private static IElement GetElement(IGeometry pGeo, string strElementName) { IElement ipElement = null; if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { ILineElement ipLineElement = new LineElementClass(); RgbColor ipColor = new RgbColor(); ipElement = (IElement)ipLineElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 0.5; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipLineElement.Symbol = ipLineSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { RgbColor ipColor = new RgbColor(); IPolygonElement ipPolygonElement = new PolygonElementClass(); ipElement = (IElement)ipPolygonElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 1.0; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipFillSymbol.Outline = ipLineSymbol; IFillShapeElement pFillElement = (IFillShapeElement)ipPolygonElement; ipFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pFillElement.Symbol = ipFillSymbol; } if (ipElement != null) { ((IElementProperties)ipElement).Name = strElementName; } return(ipElement); }
public ChartRender(AxMapControl pMapcontrol, IFeatureLayer pFtLayer, string pFieldName) { IGeoFeatureLayer pGeoFeaturelayer = pFtLayer as IGeoFeatureLayer; IChartRenderer pChart = new ChartRendererClass(); IDataStatistics pDataStat = new DataStatisticsClass(); IFeatureCursor pFtCursor = pFtLayer.FeatureClass.Search(null, false); pDataStat.Cursor = pFtCursor as ICursor; pDataStat.Field = pFieldName; double pMax = pDataStat.Statistics.Maximum; IRendererFields pRenderFields = pChart as IRendererFields; pRenderFields.AddField(pFieldName,pFieldName); IBarChartSymbol pBarChart = new BarChartSymbolClass(); pBarChart.Width = 5; IMarkerSymbol pMarkerSymbol = pBarChart as IMarkerSymbol; pMarkerSymbol.Size = 12; IChartSymbol pChartSym = pBarChart as IChartSymbol; pChartSym.MaxValue = pMax; ISymbolArray pSymbolArr = pBarChart as ISymbolArray; IFillSymbol pFillSy = new SimpleFillSymbolClass(); pFillSy.Color = GetRgb(220, 0, 0); pSymbolArr.AddSymbol(pFillSy as ISymbol); pGeoFeaturelayer.Renderer = pChart as IFeatureRenderer; pMapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelope; IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 3; pOutline.Color = pColor; //设置颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); IPoint ll, Ur; ll = axMapControl1.Extent.LowerLeft; Ur = axMapControl1.Extent.LowerRight; toolStripStatusLabel1.Text = "(" + Convert.ToString(ll.X) + "," + Convert.ToString(ll.Y) + ")"; }
private void button2_Click(object sender, System.EventArgs e) { //Create a new ClassBreaksRenderer and set properties m_classBreaksRenderer = new ClassBreaksRenderer(); m_classBreaksRenderer.Field = comboBox1.SelectedItem.ToString(); m_classBreaksRenderer.BreakCount = Convert.ToInt32(textBox1.Text); m_classBreaksRenderer.MinimumBreak = Convert.ToDouble(textBox2.Text); //Calculate the class interval by a simple mean value double interval = (Convert.ToDouble(textBox3.Text) - m_classBreaksRenderer.MinimumBreak) / m_classBreaksRenderer.BreakCount; //Get the color ramp IColorRamp colorRamp = (IColorRamp)m_styleGalleryItem.Item; //Set the size of the color ramp and recreate it colorRamp.Size = Convert.ToInt32(textBox1.Text); bool createRamp; colorRamp.CreateRamp(out createRamp); //Get the enumeration of colors from the color ramp IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); double currentBreak = m_classBreaksRenderer.MinimumBreak; ISimpleFillSymbol simpleFillSymbol; //Loop through each class break for (int i = 0; i <= m_classBreaksRenderer.BreakCount - 1; i++) { //Set class break m_classBreaksRenderer.set_Break(i, currentBreak); //Create simple fill symbol and set color simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); //Add symbol to renderer m_classBreaksRenderer.set_Symbol(i, (ISymbol)simpleFillSymbol); currentBreak += interval; } //Hide the form this.Hide(); }
private static ISymbol GetSymbol(esriGeometryType featureGeometryType, RgbColor color, IObjectFactory objFactory = null) { if (featureGeometryType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol simplePolygonSymbol = new SimpleFillSymbolClass(); simplePolygonSymbol.Color = color; ISimpleLineSymbol outlineSymbol = new SimpleLineSymbolClass(); var outLine = color; color.Transparency = 255; outlineSymbol.Color = outLine; outlineSymbol.Width = 1; simplePolygonSymbol.Outline = outlineSymbol; return(simplePolygonSymbol as ISymbol); } if (featureGeometryType == esriGeometryType.esriGeometryPolyline) { ISimpleLineSymbol simplePolylineSymbol = new SimpleLineSymbolClass(); simplePolylineSymbol.Color = color; simplePolylineSymbol.Width = 4; return(simplePolylineSymbol as ISymbol); } if (featureGeometryType == esriGeometryType.esriGeometryPoint) { Type factoryType = Type.GetTypeFromProgID("esriDisplay.SimpleMarkerSymbol"); string typeFactoryID = factoryType.GUID.ToString("B"); ISimpleMarkerSymbol pointMarkerSymbol = (ISimpleMarkerSymbol)objFactory.Create(typeFactoryID); pointMarkerSymbol.Color = color; pointMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pointMarkerSymbol.Size = 30; return(pointMarkerSymbol as ISymbol); } ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = color; return(simpleMarkerSymbol as ISymbol); }
public static void ProportionalRenderer(IFeatureLayer featLayer, string fieldName, IColor pColor, double count) { IProportionalSymbolRenderer psrender = new ProportionalSymbolRendererClass(); psrender.Field = fieldName; psrender.ValueUnit = esriUnits.esriUnknownUnits; psrender.ValueRepresentation = esriValueRepresentations.esriValueRepUnknown; //选择渲染的样式,与颜色 minsymbol为比填内容,否则没有效果 ISimpleMarkerSymbol markersym = new SimpleMarkerSymbol(); markersym.Size = count; markersym.Style = esriSimpleMarkerStyle.esriSMSCircle; markersym.Color = pColor; psrender.MinSymbol = markersym as ISymbol; //IFeatureLayer featLayer = featLayer; IGeoFeatureLayer geofeat = featLayer as IGeoFeatureLayer; ICursor cursor = ((ITable)featLayer).Search(null, true); IDataStatistics datastat = new DataStatisticsClass(); datastat.Cursor = cursor; datastat.Field = fieldName;//千万不能忽视 IStatisticsResults statisticsResult; try { statisticsResult = datastat.Statistics; psrender.MinDataValue = statisticsResult.Minimum + 0.1; psrender.MaxDataValue = statisticsResult.Maximum; ////设置background的样式 IFillSymbol fillsym = new SimpleFillSymbolClass(); fillsym.Color = getcolor(201, 201, 251); ILineSymbol linesym = new SimpleLineSymbolClass(); linesym.Width = 1; fillsym.Outline = linesym; psrender.BackgroundSymbol = fillsym; psrender.LegendSymbolCount = 6; //legend的数量 psrender.CreateLegendSymbols(); //创建TOC的legend geofeat.Renderer = (IFeatureRenderer)psrender; } catch { XtraMessageBox.Show("错误,选择的属性不是数值型!"); } }
/// <summary> /// Gets the drawing symbol of selected pixel. (temporary function) /// </summary> /// <returns></returns> public static ISimpleFillSymbol GetSelectionSymbol() { ISimpleFillSymbol selectionSymbol = new SimpleFillSymbolClass(); selectionSymbol.Color = new RgbColorClass() { NullColor = true, Transparency = 0 }; ISimpleLineSymbol selectionOutlineSymbol = new SimpleLineSymbolClass(); selectionOutlineSymbol.Color = new RgbColorClass() { Red = 0, Green = 255, Blue = 255 }; selectionOutlineSymbol.Width = 2; selectionSymbol.Outline = selectionOutlineSymbol; return(selectionSymbol); }
private IElement GetElement(IGeometry geometry, esriSimpleFillStyle simpleFillStyle) { IElement element; IPolygonElement polygonElement = new PolygonElementClass(); element = polygonElement as IElement; IFillShapeElement fillShapeElement = polygonElement as IFillShapeElement; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = simpleFillStyle; simpleFillSymbol.Color = ColorSelection.GetColor(); element.Geometry = geometry; fillShapeElement.Symbol = simpleFillSymbol; return element; }
public static void uniqueRender(IFeatureLayer featLayer, string fieldName) { IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer; IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器 //设置渲染字段对象 pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号 pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol; pUniqueValueRenderer.UseDefaultSymbol = false; int n = pFeatureClass.FeatureCount(null); for (int i = 0; i < n; i++) { IFeature pFeature = pFeatureCursor.NextFeature(); string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", null); } IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = pUniqueValueRenderer.ValueCount; bool b = true; colorRamp.CreateRamp(out b); //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { pUniqueValueRenderer.set_Symbol(xv, getISymbolByGeomType(featLayer, colorRamp.get_Color(i * (colorRamp.Size - 1) / (pUniqueValueRenderer.ValueCount - 1)))); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; }
//主视图范围发生变化 private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { //得到新范围 IEnvelope pEnv = (IEnvelope)e.newEnvelope; //实例化 IGraphicsContainer pGra = eagleEyeMapControl.Map as IGraphicsContainer; //实例化 IActiveView pAv = pGra as IActiveView; //QI 活动视图 //重新绘制前,清除之前绘制的图形元素 pGra.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pEle = pRectangleEle as IElement; pEle.Geometry = pEnv;//设置元素的几何形体对象属性 //设置鹰眼中矩形框的颜色 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255;//不透明 //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 2; pOutline.Color = pColor; //设置填充对象的颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; //设置填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapEle = pEle as IFillShapeElement; pFillShapEle.Symbol = pFillSymbol; pGra.AddElement((IElement)pFillShapEle, 0); //将元素放入Map对象中 //活动视图局部刷新以重绘地图 pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //刷新图形元素 }
private void btnOK_Click(object sender, EventArgs e) { //Create a new simple fill symbol IGeoFeatureLayer geoFeatureLayer = m_featureLayer as IGeoFeatureLayer; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; //Create a new simple line symbol for outline ISimpleLineSymbol Outline = new SimpleLineSymbolClass(); //Change the width of outline Outline.Width = int.Parse(tbOutlineWidth.Text); //Change the fill color IRgbColor rgbColorFill = new RgbColorClass(); rgbColorFill.Red = int.Parse(tbRedFill.Text); rgbColorFill.Blue = int.Parse(tbBlueFill.Text); rgbColorFill.Green = int.Parse(tbGreenFill.Text); simpleFillSymbol.Color = rgbColorFill; //Change the color of outline IRgbColor rgbColorOutline = new RgbColorClass(); rgbColorOutline.Red = int.Parse(tbRedOutline.Text); rgbColorOutline.Blue = int.Parse(tbBlueOutline.Text); rgbColorOutline.Green = int.Parse(tbGreenOutline.Text); Outline.Color = rgbColorOutline; //Change the properties of polygon's outline simpleFillSymbol.Outline = Outline; //Change the properties of polygon ISimpleRenderer simpleRenderer = new SimpleRendererClass(); simpleRenderer.Symbol = simpleFillSymbol as ISymbol; geoFeatureLayer.Renderer = simpleRenderer as IFeatureRenderer; m_fraMain.RefreshMap(); m_fraMain.RefreshTOCControl(); this.Close(); }
/// <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); }
private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { //得到新范围 IEnvelope pEnvelop = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer = Global.eagleeye.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; //在绘制前。清除axMapControl2 中的任何图形元素 pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelop; //设置鹰眼中的红线框 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1; pOutline.Color = pColor; //设置颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; //设置填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
//Ϊդ��ͼ�����ݽ��з�����ɫ public static IRasterLayer GetRLayerClassifyColor(IRaster pRaster, double dMaxDis) { IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass(); IRasterRenderer pRasRen = pClassRen as RasterClassifyColorRampRendererClass; //Set raster for the render and update pRasRen.Raster = pRaster; pClassRen.ClassCount = 10; pRasRen.Update(); //Create a color ramp to use //���������յ���ɫ IColor pFromColor = new RgbColorClass(); IRgbColor pRgbColor = pFromColor as IRgbColor; pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; IColor pToColor = new RgbColorClass(); pRgbColor = pToColor as IRgbColor; pRgbColor.Red = 0; pRgbColor.Green = 255; pRgbColor.Blue = 0; //������ɫ�ּ� IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass(); pRamp.Size = 10; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool ok = true; pRamp.CreateRamp(out ok); //Create symbol for the classes IFillSymbol pFSymbol = new SimpleFillSymbolClass(); double LabelValue = Convert.ToDouble(dMaxDis / 6); for (int i = 0; i <= pClassRen.ClassCount - 1; i++) { pFSymbol.Color = pRamp.get_Color(i); pClassRen.set_Symbol(i, pFSymbol as ISymbol); double h1 = LabelValue * i; double h2 = LabelValue * (i + 1); pClassRen.set_Label(i, h1.ToString() + "��" + h2.ToString()); } //Update the renderer and plug into layer pRasRen.Update(); IRasterLayer pRLayer = new RasterLayerClass(); pRLayer.CreateFromRaster(pRaster); pRLayer.Renderer = pClassRen as IRasterRenderer; return pRLayer; }
private void CreateOverviewSymbol() { IRgbColor iRgb = new RgbColorClass(); iRgb.RGB = 255; ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Color = iRgb; pOutline.Width = 2.3; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Outline = pOutline; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; oFillobject = pSimpleFillSymbol; }
/// <summary> /// draw footprints on the map /// </summary> /// <param name="record">Record for which the footprint needs to be drwan</param> /// <param name="refreshview">Indicates if the view is refreshed or not after the element is drawn</param> /// <param name="deleteelements">Indicates if the element can be deleted or not</param> private void drawfootprint(CswRecord record, bool refreshview, bool deleteelements) { //create the triangle outline symbol ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; lineSymbol.Width = 2.0; //create the triangle's fill symbol ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Outline = (ILineSymbol)lineSymbol; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; IMxDocument mxDoc; mxDoc = (IMxDocument)m_application.Document; //the original projection system ISpatialReference spatialReference; IGeographicCoordinateSystem geographicCoordinateSystem; SpatialReferenceEnvironmentClass spatialReferenceEnviorment = new SpatialReferenceEnvironmentClass(); geographicCoordinateSystem = spatialReferenceEnviorment.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); spatialReference = (ISpatialReference)geographicCoordinateSystem; //set the geometry of the element IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.SpatialReference = spatialReference; point.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Miny); IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass(); point1.SpatialReference = spatialReference; point1.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Maxy); IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass(); point2.SpatialReference = spatialReference; point2.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Maxy); IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass(); point3.SpatialReference = spatialReference; point3.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Miny); IPointCollection pointCollection; pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass(); object x = Type.Missing; object y = Type.Missing; pointCollection.AddPoint(point, ref x, ref y); pointCollection.AddPoint(point1, ref x, ref y); pointCollection.AddPoint(point2, ref x, ref y); pointCollection.AddPoint(point3, ref x, ref y); PolygonElementClass element = new PolygonElementClass(); element.Symbol = simpleFillSymbol; element.SpatialReference = spatialReference; element.Geometry.SpatialReference = spatialReference; element.Geometry = (IGeometry)pointCollection; element.Geometry.Project(mxDoc.ActiveView.Extent.SpatialReference); //add the graphics element to the map IGraphicsContainer graphicsContainer; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; if (deleteelements) { graphicsContainer.DeleteAllElements(); } graphicsContainer.AddElement(element, 0); if (refreshview) { mxDoc.ActiveView.Extent = element.Geometry.Envelope; mxDoc.ActiveView.Refresh(); } }
//Ϊդ��ͼ�����ݽ���Ψһֵ��ɫ public static IRasterLayer GetRLayerUniqueColor(IRaster pRaster, double dMaxDis) { try { IRasterBandCollection pBandCol = pRaster as IRasterBandCollection; IRasterBand pBand = pBandCol.Item(0) as IRasterBand; bool ExistTable; ITable pTable = null; pBand.HasTable(out ExistTable); if (ExistTable == false) { pTable = pBand.AttributeTable as ITable; } int iNumOfValues = pTable.RowCount(null); string sFieldName = "Value"; int iFieldIndex = pTable.FindField(sFieldName); IRandomColorRamp pRamp = new RandomColorRampClass(); pRamp.Size = iNumOfValues; pRamp.Seed = 100; bool a = true; pRamp.CreateRamp(out a); IFillSymbol pFSymbol = new SimpleFillSymbolClass(); IRasterUniqueValueRenderer pUVRen = new RasterUniqueValueRendererClass(); IRasterRenderer pRasRen = pUVRen as IRasterRenderer; pRasRen.Raster = pRaster; pRasRen.Update(); pUVRen.HeadingCount = 1; pUVRen.set_Heading(0, "�ȼ�"); pUVRen.set_ClassCount(0, iNumOfValues); pUVRen.Field = sFieldName; //��ʼѭ��������ɫ double LabelValue; double s = Convert.ToDouble(dMaxDis / 5); IRgbColor pRGBColor = new RgbColorClass(); for (int i = 0; i < iNumOfValues - 1; i++) { IColor pColor = pRamp.get_Color(i); IRow pRow = pTable.GetRow(i); string sLabel = ""; LabelValue = Convert.ToDouble(pRow.get_Value(iFieldIndex)); if (LabelValue >= 0 || LabelValue <= s) { sLabel = "0" + "��" + s.ToString(); pRGBColor.Red = 0; pRGBColor.Green = 112; pRGBColor.Blue = 255; pColor = pRGBColor as IColor; } double h1 = s * 2; if (LabelValue >= s || LabelValue <= s * 2) { sLabel = s.ToString() + "��" + h1.ToString(); pRGBColor.Red = 0; pRGBColor.Green = 112; pRGBColor.Blue = 255; pColor = pRGBColor as IColor; } double h2 = s * 3; if (LabelValue >= s * 2 || LabelValue <= s * 3) { sLabel = h1.ToString() + "��" + h2.ToString(); pRGBColor.Red = 0; pRGBColor.Green = 112; pRGBColor.Blue = 255; pColor = pRGBColor as IColor; } double h3 = s * 4; if (LabelValue >= s * 3 || LabelValue <= s * 4) { sLabel = h2.ToString() + "��" + h3.ToString(); pRGBColor.Red = 0; pRGBColor.Green = 112; pRGBColor.Blue = 255; pColor = pRGBColor as IColor; } double h4 = s * 5; if (LabelValue >= s * 4 || LabelValue <= s * 5) { sLabel = h3.ToString() + "��" + h4.ToString(); pRGBColor.Red = 0; pRGBColor.Green = 112; pRGBColor.Blue = 255; pColor = pRGBColor as IColor; } pUVRen.AddValue(0, i, LabelValue); pUVRen.set_Label(0, i, sLabel); pFSymbol.Color = pColor; pUVRen.set_Symbol(0, i, pFSymbol as ISymbol); } pRasRen.Update(); IRasterLayer pRLayer = new RasterLayerClass(); pRLayer.CreateFromRaster(pRaster); pRLayer.Renderer = pUVRen as IRasterRenderer; return pRLayer; } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } }
private ISpatialFilter GenerateSpatialFilter() { frmPromptQuerying frmPrompt = new frmPromptQuerying(4);//��ʾ����������ͼ���� Ϊ�����쳣ʱ�ܽ�����ʾ���ڹرգ����Է���try���� try { frmPrompt.Show(); System.Windows.Forms.Application.DoEvents();//'ת�ÿ���Ȩ��û����һ��Ļ���ʾ���ڲ���������ʾ //����Ҫ�����spatialfilter //��ù���spatialfilter.geometry������feature //IMap pMap; //����QI��IEnumLayer //IEnumLayer pEnumLayer; //����������Ϊ��ѡ���layers //ILayer pLayer; IFeatureLayer pFeatureLayer = null; IGeometry pGeometry = null; IEnumFeature pEnumFeature = null; //�����зֱ�����ʹ�úͲ�ʹ�� IFeatureCursor pFeatureCursor = null; //�Ѿ�ѡ���Ԫ�����ɡ�ɸѡͼ�Ρ������ IFeatureClass pFeatureClass; IFeature pFeature; string strLayerName = comboBoxConditionLayer.Text; if (checkBoxUseSelectedOnly.Checked == false) //����û��Լ�ѡ������ͼ�㡱,��������ѡ�е�Ԫ�� { pFeatureLayer = GetLayerbyName(strLayerName) as IFeatureLayer; //���layer����������spatialfilter.geometry�� //���Ǹ�������ͼ�㡱 //���ﲻ��featureselection�����enumfeature,�Ӷ����������geometry�ϲ�������ȡfeaturecursor������Ϊ //��featureselection�Ļ�����ô��ϲ�������feature��һ�������ôд��featureselection=mainaxmapcontrol.map.featureselection //������ָ��featureselection��map�����һ���㣡���������featureselection=pfeaturelayer.featureselection�� //Ȼ��enumfeature=featureselection����ʱenumfeature����null�����е�pfeaturelayer�Ѿ���map���һ��ָ���IJ��ˣ� //�����featureselection=mainaxmapcontrol.map.featureselection���ͻ������⣺Ҳ��map�����Ѿ��б�ѡ�е�Ԫ���ˣ�����ʱ�����ַ��� //��õ�enumfeatureֻ������Щ�Ѿ�ѡ�е�Ԫ�أ�����Ӧ����������Ӧ�û�õ���ָ��Ϊ������ͼ�㡱������feature������ֻ����featurecursor //�����featureselection�Ļ���Ҫ��ôд�� //IFeatureSelection pFeatureSelection = MainaxMapControl.get_Layer(strLayerName) as IFeatureSelection; //pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);//��ʹ���ѱ�ѡ�е�Ԫ��ʱ������仰Խ��ȥ //IEnumFeature pEnumFeature = MainaxMapControl.Map.FeatureSelection as IEnumFeature; pFeatureClass = pFeatureLayer.FeatureClass; pFeatureCursor = pFeatureClass.Search(null, true); pFeature = pFeatureCursor.NextFeature(); } else //���ʹ�õ�ͼ����ѡ�е�Ԫ����Ϊ��ɸѡͼ�㡱 { pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature; pFeature = pEnumFeature.Next(); } pGeometry = pFeature.Shape; ITopologicalOperator pTopologicalOperator; //�ϲ������Ե���ɸ�ӡ���geometry while (pFeature != null) { //�����һ���ǹؼ����������յ�pgeometry���Ի���������geometry //��ΪTopologicalOperator�������һ��shape��һ��geometry�����Խ����������������ĺϲ�. //ֻ����shapecopy���ܹ���ȷ����shape�Ļ����ļ��ͳ����Ϊ��������ⵢ����һ���ڣ����� //����һ��˼·Ҳ���ԡ������˼·����ѭ���ϲ�����geometry����һ��˼·����ѭ���õ�����ÿ�� //geometryȥɸѡͼ�����featuresȻ��ϲ���� pTopologicalOperator = pFeature.ShapeCopy as ITopologicalOperator; //if (checkBoxBuffer.Checked == true) //{ // double ddistance = Convert.ToDouble(textBoxBuffer.Text); // pGeometry = pTopologicalOperator.Buffer(ddistance); // //pTopologicalOperator.Simplify(); //ʹ���˹�ϵ�����ȷ //} pGeometry = pTopologicalOperator.Union(pGeometry as IGeometry); if (checkBoxUseSelectedOnly.Checked == false)//�õ���featurecursor pFeature = pFeatureCursor.NextFeature(); else pFeature = pEnumFeature.Next(); } //pFeatureSelection.Clear();//������������������geometry��������featureselection�Ļ�����Ҳ��һ��ؼ��� //�������յ���ʾҲ�������featureselection��ʾ���� //���ɻ����������������ѭ��֮��ִ�У������Ӹ���Ч�ʣ����Ҹ������׳��� if (checkBoxBuffer.Checked == true) { double ddistance = Convert.ToDouble(textBoxBuffer.Text); pTopologicalOperator = pGeometry as ITopologicalOperator; pGeometry = pTopologicalOperator.Buffer(ddistance); pTopologicalOperator.Simplify(); //ʹ���˹�ϵ�����ȷ //MainAxMapControl.FlashShape(pGeometry, 2, 500, null);//��˸����֤��������ȷ��� } frmPrompt.WindowState = FormWindowState.Minimized; frmPrompt.Dispose(); System.Windows.Forms.Application.DoEvents(); object m_fillsymbol; //�����drawshape�IJ���������object�� IRgbColor pRgb = new RgbColorClass(); // ��ȡIRGBColor�ӿ� pRgb.Red = 255; // ������ɫ���� ILineSymbol outline = new SimpleLineSymbolClass(); // ��ȡILine���Žӿ� outline.Width = 5; outline.Color = pRgb; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();// ��ȡIFillSymbol�ӿ� simpleFillSymbol.Outline = outline; simpleFillSymbol.Color = pRgb; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal; m_fillsymbol = simpleFillSymbol; //MainAxMapControl.DrawShape(pGeometry, ref m_fillsymbol); MainAxMapControl.FlashShape(pGeometry, 3, 500, m_fillsymbol);//��˸�����û�֪����ǰ��"����ͼ��"����״ ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeometry; pSpatialFilter.SpatialRel = pSpatialRel; //���Ǹ�ȫ�ֱ��� if (checkBoxUseSelectedOnly.Checked == true) pSpatialFilter.GeometryField = "Shape"; //��ʹ����ѡ�е�Ԫ����Ϊ��ɸѡͼ�㡱ʱ�� //�����������ȥ���geometryfield����Ϊpfeaturelayer(����ͼ��)Ϊ�� else pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName; return pSpatialFilter; } catch (Exception ex) { MessageBox.Show("���ɡ�����ͼ�㡱����!���� | " + ex.Message); frmPrompt.Dispose(); return null;//��������spatialfitler } }
/// <summary> /// 简单面 /// </summary> /// <param name="color"></param> /// <param name="style"></param> /// <param name="outLineSymbol"></param> /// <returns></returns> private IFillSymbol DefineFillSymbol(IColor color, esriSimpleFillStyle style, ILineSymbol outLineSymbol) { ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; //定义面符号颜色 simpleFillSymbol.Style = style; //定义面符号样式 simpleFillSymbol.Outline = outLineSymbol; //定义面符号边线 IFillSymbol fillSymbol = (IFillSymbol)simpleFillSymbol; return fillSymbol; }
private void setColor(IGeoFeatureLayer IGFL) { int classCount = 10; ITableHistogram tableHistogram; IBasicHistogram basicHistogram; ITable table; IGeoFeatureLayer geoFeatureLayer; geoFeatureLayer = IGFL; ILayer layer = geoFeatureLayer as ILayer; table = layer as ITable; tableHistogram = new BasicTableHistogramClass(); tableHistogram.Table = table; tableHistogram.Field = "HighTemperature"; basicHistogram = tableHistogram as IBasicHistogram; object values; object frequencys; basicHistogram.GetHistogram(out values, out frequencys); IClassifyGEN classifyGEN = new QuantileClass(); classifyGEN.Classify(values, frequencys, ref classCount); double[] classes; classes = classifyGEN.ClassBreaks as double[]; IEnumColors enumColors = CreateAlgorithmicColorRamp(classes.Length).Colors; IColor color; IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass(); classBreaksRenderer.Field = "HighTemperature"; classBreaksRenderer.BreakCount = classCount + 1; classBreaksRenderer.SortClassesAscending = true; ISimpleFillSymbol simpleFillSymbol; for (int i = 0; i < classes.Length; i++) { color = enumColors.Next(); simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classBreaksRenderer.set_Symbol(i, simpleFillSymbol as ISymbol); classBreaksRenderer.set_Break(i, classes[i]); } if (geoFeatureLayer != null) geoFeatureLayer.Renderer = classBreaksRenderer as IFeatureRenderer; axMapControl1.ActiveView.Refresh(); }
private void 添加面形地物ToolStripMenuItem_Click(object sender, EventArgs e) { //创建要素类 #region 创建新的内存工作空间 IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //创建要素类 oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "PolygonLayer"; oFeatureLayer.FeatureClass = oFeatureClass; //创建唯一值符号化对象 IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //半透明颜色 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pFillSym.Color = pColor; pURender.AddValue("1", "", pFillSym as ISymbol); pFillSym = new SimpleFillSymbolClass(); pFillSym.Style = esriSimpleFillStyle.esriSFSSolid; //唯一值符号化内存图层 (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //透明度 pLyrEffect.Transparency = 0; this.axMapControl1.AddLayer(oFeatureLayer, axMapControl1.LayerCount); insertPolygon = true; }
public override void RefreshFeedBack() { try { if (TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry == null) return; //屏幕绘制graphic表达此刻的Geometry IElement ipElement = null; if(_subType == 1) { ipElement = new LineElementClass(); ipElement.Geometry = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry; } else if(_subType == 2) { ipElement = new PolygonElementClass(); ipElement.Geometry = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry; ipElement.Geometry.SpatialReference = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry.SpatialReference; //绘制Geometry时使用空心红框,以方便查看叠盖关系 ISimpleFillSymbol iSymbol = new SimpleFillSymbolClass(); ISimpleLineSymbol iOutlineSymbol = new SimpleLineSymbolClass(); IColor irgbColor = new RgbColorClass(); (irgbColor as IRgbColor).Red = 255; (irgbColor as IRgbColor).Blue = 0; (irgbColor as IRgbColor).Green = 0; iOutlineSymbol.Color = irgbColor; iSymbol.Style = esriSimpleFillStyle.esriSFSHollow; iSymbol.Outline = iOutlineSymbol; (ipElement as IFillShapeElement).Symbol = iSymbol; } (myHook.FocusMap as IGraphicsContainer).AddElement(ipElement, 0); (myHook.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, ipElement, TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry.Envelope); InfoUserStatusbar.InfoTip = "草图绘制完成!"; } catch (System.Exception e) { throw new ApplicationException(String.Format("把草图更新到Map出错!\n{0}", e.Message)); InfoUserStatusbar.InfoTip = "草图绘制失败!"; } finally { if (myHook.Hook is IMapControl3) { TheReferenceInstances.TheAxMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; (myHook.Hook as IMapControl3).CurrentTool = null; } else if (myHook.Hook is IPageLayoutControl2) { (myHook.Hook as IPageLayoutControl2).CurrentTool = null; } m_cursor = Cursors.Default; } }