单值专题图(有颜色带)
2010-09-25 23:56
267 查看
1 首先制作用户控件,命名为ComboBoxEx.cs,代码如下:
2 在窗体显示颜色带,有到四个方法,代码如下:
3同过颜色带设置单值专题图,代码如下:
using System; using System.Windows.Forms; using System.Drawing; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Output; namespace DXGXGIS.MainGIS { public class ComboBoxEx : ComboBox { public ComboBoxEx() { DrawMode = DrawMode.OwnerDrawFixed; DropDownStyle = ComboBoxStyle.DropDownList; } protected override void OnDrawItem(DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); try { //显示图片 Image image = (Image)Items[e.Index]; System.Drawing.Rectangle rect = e.Bounds; e.Graphics.DrawImage(image, rect); } catch { if (e.Index != -1) { //不是图片则显示字符 e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); } } finally { base.OnDrawItem(e); } } } }
2 在窗体显示颜色带,有到四个方法,代码如下:
private void InitialCombobox(ComboBoxEx pStyleCombox) { try { isStyle = true; this.cboStyle.Visible = true; this.uiGroupBox3.Visible = true; IStyleGallery pStyleGallery; IStyleGalleryStorage pStyleStorage; IEnumStyleGalleryItem enumStyleGalleryItem; IStyleGalleryItem styleItem; IStyleGalleryClass pStyleGalleryClass = new ColorRampStyleGalleryClassClass(); pStyleGallery = new ServerStyleGalleryClass(); pStyleStorage = pStyleGallery as IStyleGalleryStorage; string stylePath = Application.StartupPath + @"/ESRI.ServerStyle"; pStyleStorage.AddFile(stylePath); enumStyleGalleryItem = pStyleGallery.get_Items("Color Ramps", "ESRI.ServerStyle", ""); enumStyleGalleryItem.Reset(); styleItem = enumStyleGalleryItem.Next(); while (styleItem != null) { Bitmap bitmap = PreviewSymbol(pStyleGalleryClass, styleItem.Item, pStyleCombox.Width, pStyleCombox.Height); pStyleCombox.Items.Add(bitmap); styleGalleryItem.Add(styleItem); styleItem = enumStyleGalleryItem.Next(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(enumStyleGalleryItem); } catch (Exception ee) { //MessageBox.Show(ee.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.cboStyle.Visible = false; this.uiGroupBox3.Visible = false; isStyle = false; } } //Symbol转换为Bitmap; private Bitmap PreviewSymbol(IStyleGalleryClass pStyleGalleryClass, object galleryItem, int imgWidth, int imgHeight) { Bitmap bitmap = new Bitmap(imgWidth, imgHeight); Graphics graphics = Graphics.FromImage(bitmap); tagRECT rect = new tagRECT(); rect.right = bitmap.Width; rect.bottom = bitmap.Height; System.IntPtr hdc = graphics.GetHdc(); pStyleGalleryClass.Preview(galleryItem, hdc.ToInt32(), ref rect); graphics.ReleaseHdc(hdc); graphics.Dispose(); return bitmap; } /// <summary> /// 实现将Symbol转换为Bitmap /// </summary> /// <param name="Symbol">符号对象</param> /// <param name="Width">宽度值</param> /// <param name="Height">高度值</param> /// <returns>图像对象</returns> public static Bitmap PreviewItem(ISymbol Symbol, int Width, int Height) { Bitmap bitmap = new Bitmap(Width, Height); Graphics mGraphics = Graphics.FromImage(bitmap); double dpi = mGraphics.DpiY; IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(0, 0, bitmap.Width, bitmap.Height); tagRECT myRect = new tagRECT(); myRect.bottom = bitmap.Height; myRect.left = 0; myRect.right = bitmap.Width; myRect.top = 0; IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass(); pDisplayTransformation.VisibleBounds = pEnvelope; pDisplayTransformation.Bounds = pEnvelope; pDisplayTransformation.set_DeviceFrame(ref myRect); pDisplayTransformation.Resolution = dpi; IntPtr pIntPtr = mGraphics.GetHdc(); int hDC = pIntPtr.ToInt32(); Symbol.SetupDC(hDC, pDisplayTransformation); IGeometry pGeometry = GetSymbolGeometry(Symbol, pEnvelope); Symbol.Draw(pGeometry); Symbol.ResetDC(); mGraphics.ReleaseHdc(pIntPtr); mGraphics.Dispose(); return bitmap; } /// <summary> /// 根据符号类型得到相应的几何形体 /// </summary> /// <param name="Symbol">符号对象</param> /// <param name="Envelop">矩形对象</param> /// <returns>几何形体对象</returns> private static IGeometry GetSymbolGeometry(ISymbol Symbol, IEnvelope Envelop) { IGeometry pGeometry = null; if (Symbol is IMarkerSymbol) { IArea pArea = Envelop as IArea; pGeometry = pArea.Centroid; } else if (Symbol is ILineSymbol) { IPolyline pPolyline = new PolylineClass(); IPoint pFromPoint = new PointClass(); pFromPoint.PutCoords(Envelop.XMin, (Envelop.YMax + Envelop.YMin)/2); IPoint pToPoint = new PointClass(); pToPoint.PutCoords(Envelop.XMax, (Envelop.YMax + Envelop.YMin)/2); pPolyline.FromPoint = pFromPoint; pPolyline.ToPoint = pToPoint; pGeometry = pPolyline; } else if (Symbol is IFillSymbol) { pGeometry = Envelop; } else if (Symbol is ITextSymbol) { IArea pArea = Envelop as IArea; pGeometry = pArea.Centroid; } return pGeometry; }
3同过颜色带设置单值专题图,代码如下:
this.lstViewShow.Items.Clear(); imagelist.Images.Clear(); ITable pTable; int fieldNumber; string strFieldName = this.cboField.Text; ILayer pLayer = pFLayer as ILayer; pTable = (ITable)pLayer; fieldNumber = pTable.FindField(strFieldName); if (fieldNumber == -1) { MessageBox.Show("没有查找到结果,请选择别的字段查询!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strFieldName); object codeValue; bool ok; IColorRamp colorRamp = (IColorRamp)styleGalleryItem[this.cboStyle.SelectedIndex].Item; colorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = colorRamp.Colors; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(strFieldName); ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); IMarkerSymbol pMarkerSymbol; ILineSymbol pLineSymbol; IFillSymbol pFillSymbol; IColor pNextUniqueColor = null; ArrayList count = new ArrayList(); List<Bitmap> symbol = new List<Bitmap>(); int unqueValueCount = 0; if (pNextRow != null) { int fieldIndex = pNextRow.Fields.FindField(strFieldName); do { codeValue = pNextRow.get_Value(fieldIndex); pNextUniqueColor = pEnumRamp.Next(); if (pNextUniqueColor == null) { pEnumRamp.Reset(); pNextUniqueColor = pEnumRamp.Next(); } switch (pFLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Color = pNextUniqueColor; pMarkerSymbol.Size = Convert.ToInt32(this.cboSize.Text); pUniqueValueRenderer.AddValue(codeValue.ToString(), this.cboField.Text, (ISymbol)pMarkerSymbol); break; case esriGeometryType.esriGeometryPolyline: pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = pNextUniqueColor; pLineSymbol.Width = Convert.ToInt32(this.cboSize.Text); pUniqueValueRenderer.AddValue(codeValue.ToString(), this.cboField.Text, (ISymbol)pLineSymbol); break; case esriGeometryType.esriGeometryPolygon: pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; pUniqueValueRenderer.AddValue(codeValue.ToString(), this.cboField.Text, (ISymbol)pFillSymbol); break; } pNextRow = pCursor.NextRow(); } while (pNextRow != null); } unqueValueCount = pUniqueValueRenderer.ValueCount; if (unqueValueCount > 500) { unqueValueCount = 500; MessageBox.Show("为不影响执行效率,查询值只显示前500条!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } for (int j = 0; j < unqueValueCount; j++) { count.Add(pUniqueValueRenderer.get_Value(j).ToString()); string xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { switch (pFLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: IMarkerSymbol pNextSymbol1 = (IMarkerSymbol)pUniqueValueRenderer.get_Symbol(xv); symbol.Add(PreviewItem((ISymbol)pNextSymbol1, 20, 20)); break; case esriGeometryType.esriGeometryPolyline: ILineSymbol pNextSymbol2 = (ILineSymbol)pUniqueValueRenderer.get_Symbol(xv); symbol.Add(PreviewItem((ISymbol)pNextSymbol2, 80, 20)); break; case esriGeometryType.esriGeometryPolygon: IFillSymbol pNextSymbol3 = (IFillSymbol)pUniqueValueRenderer.get_Symbol(xv); symbol.Add(PreviewItem((ISymbol)pNextSymbol3, 20, 20)); break; } } imagelist.Images.Add(symbol[j]); lstViewShow.SmallImageList = imagelist; ListViewItem lvi = new ListViewItem(new string[] { "", count[j].ToString(), count[j].ToString() }); lvi.ImageIndex = j; lstViewShow.Items.Add(lvi); } IGeoFeatureLayer m_pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; m_pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; mainfrm.axTOCControl.SetBuddyControl(mainfrm.axMapControl.Object); mainfrm.axTOCControl.Refresh(); mainfrm.axMapControl.ActiveView.Refresh(); symbol.Clear();
相关文章推荐
- 【图像算法】彩色图像分割专题一:颜色空间1(原理)
- 【图像算法】彩色图像分割专题一:颜色空间2(部分结果)
- 【图像算法】彩色图像分割专题一:颜色空间3(部分源码)
- [kuangbin带你飞]专题七 线段树 F - Count the Colors(颜色覆盖)
- [转] AE之分级颜色专题图渲染
- 【图像算法】彩色图像分割专题六:一种基于颜色直方图的图像分割
- 色彩专题(PS的颜色理论)
- 【图像算法】彩色图像分割专题一:颜色空间1(原理)
- 通用对话框专题之颜色对话框
- [原创]微软BI专题-一种动态显示Matrix中Total背景颜色的方法
- IP地址专题九:子网掩码及其应用
- javascript专题(一): form的target属性
- 【OpenCV入门教程之五】 分离颜色通道&多通道图像混合
- UITextField的placeholder文字的位置,颜色等的自定义设置
- 触发按钮改变panel面板上的小圆圈颜色
- 设置placeholder的字体颜色
- PNG格式小图标的CSS任意颜色赋色技术
- HTML入门笔记25-HTML改变背景颜色
- 微信小程序 后台返回的状态是数值,前端展示文字和不同颜色的简便方法