1 / 48

Symbolizing elements and layers( I)

Symbolizing elements and layers( I). Lesson overview. 总体介绍符号化对象( symbology objects) 符号对象 Symbol objects 颜色对象 Color objects 颜色梯度对象 Color ramps 为地图添加一个简单的图形( graphics) 使用特征渲染对象修改图层显示方式( FeatureRenderers) 使用图层文件 (*.lyr) 来管理图层的符号化. Symbol 类的子类. *.

ciel
Télécharger la présentation

Symbolizing elements and layers( I)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Symbolizing elements and layers(I)

  2. Lesson overview • 总体介绍符号化对象(symbology objects) • 符号对象Symbol objects • 颜色对象Color objects • 颜色梯度对象Color ramps • 为地图添加一个简单的图形(graphics) • 使用特征渲染对象修改图层显示方式(FeatureRenderers) • 使用图层文件(*.lyr)来管理图层的符号化

  3. Symbol类的子类 * * Several additional types of symbols are listed on the Display OMD, including TextSymbols

  4. 使用color对象 • 以下五种可创建的对象 • RgbColor(红、绿、蓝) • CmykColor(青、洋红、黄、黑) • HsvColor(色调、饱和度、值) • HlsColor(色调、亮度、饱和度) • GrayColor(灰度) • 用来定义颜色对象的属性 • Red, Green, Blue values (0–255) • 灰度 (0=white – 255=black) • Cyan, Magenta, Yellow, Black • 使用Color对象来访问一个Symbol对象的Color属性

  5. 颜色梯度对象ColorRamps • 四种可以创建的对象 • Algorithmic ColorRamp(算法颜色梯度) • Random ColorRamp(随机颜色梯度) • Preset ColorRamp(预定义颜色梯度) • MultiPart ColorRamp(多部分的颜色梯度)

  6. 创建一个新的 Randomcolorramp对象 Public Function GetRandomRamp (NumColors As Integer) As IEnumColors Dim pRandomColorRamp As IColorRamp Set pRandomColorRamp = New RandomColorRamp pRandomColorRamp.Size = NumColors ' *Passed into the function Dim blnOK As Boolean pRandomColorRamp.CreateRamp blnOK '* Make it so! If Not blnOK Then Exit Function '* Exit if there was an error Set GetRandomRamp = pRandomColorRamp '*Pass back the ramp End Function RandomColorRamp.CreateRamp方法返回的是IEnumColors对象。是一个枚举对象。

  7. 创建简单的图形元素( graphic elements) • 有一些可以创建的对象 • 图形元素的种类 • Line, polygon, marker • Text and pictures • 框架元素(FrameElements ) • 在PageLayout上使用 • Map frames • North arrows, legends, scale bars • Table frames

  8. 例子: 创建一个新的图形元素并设置它的符号 Dim pMarkerElem As IMarkerElement Set pMarkerElem = New MarkerElement ‘创建一个新的元素 Dim pMarkerSym As ISimpleMarkerSymbol Set pMarkerSym = New SimpleMarkerSymbol ‘创建新符号 pMarkerSym.Style = esriSMSCircle ‘指定符号的风格 Dim pColor As IRgbColor Set pColor = New RgbColor ‘创建一个新颜色 pColor.RGB = RGB(255,0,0) ‘设置成红色 pMarkerSym.Color = pColor ‘把颜色赋给符号 pMarkerElem.Symbol = pMarkerSym ‘ 把符号赋给元素

  9. 定义一个元素的位置 • 使用IElement 的 Geometry属性 • 被所有Element的子类所支持 • 在地图(Map)或布局 (layout page)上定位 • 定位可以指定为 point, line, envelope等 Dim pElem As IElement Set pElem = pMarkerElem 'QI Dim pPoint As IPoint Set pPoint = New Point pPoint.PutCoords 65.751, -7.534 pElem.Geometry = pPoint 沿线标注文本类型的Element的定位就可以是Line对象

  10. 把一个元素添加到 map (或者 layout) • 使用 IGraphicsContainer :: AddElement • 指定添加的元素和它的序号 • 0号的序号是第一个(最顶部)的元素,序号从顶到底逐渐增加 Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument pMxDoc.ActiveView.GraphicsContainer.AddElement pElem, 0 ‘或者使用以下语句 Dim pGContainer As IGraphicsContainer Set pGContainer = pMxDoc.FocusMap ‘QI pGContainer.AddElement pElem, 0 '0=top element pMxDoc.ActiveView.Refresh 通过刷新屏幕来显示新添加的元素

  11. FeatureRenderers对象 • Renderers 方法定义了 layer 对象是怎么显示的 其它的Renderers对象可以用来显示 RasterLayers 和 TinLayers

  12. USA 简单渲染SimpleRenderer • 默认的使用简单的符号来渲染显示要素 • 属性 • Symbol: 颜色和风格 • Label: 在 legend中显示的字符串 • 在修来了图层的渲染方式之后需要执行刷新操作 ‘设置一个要素类图层的渲染对象 Set pFLayer.Renderer = pRender ‘刷新显示 pMxDoc.ActiveView.Refresh ‘刷新内容表(TOC)显示新的图标 pMxDoc.UpdateContents

  13. 唯一值渲染UniqueValueRenderer • 根据不同的唯一值用一个符号来显示要素 • 属性 • Field(s): 提供唯一分类值的字段 • Value(s):特征的唯一分类值 • ValueCount: 需要显示的唯一分类值的数目

  14. 例子: 创建一个 唯一值专题图为每个州赋一个符号 • Private Sub ApplyUniqueRenderer(SomeLayer As IGeoFeatureLayer) • Dim pUVRenderer As IUniqueValueRenderer • Set pUVRenderer = New UniqueValueRenderer • Dim pColorEnum As IEnumColors • Set pColorEnum = MakeRandomRamp(50) • pUVRenderer.FieldCount = 1 • pUVRenderer.Field(0) = "STATE_NAME" • Dim pFClass As IFeatureClass • Set pFClass = SomeLayer.FeatureClass • Dim pFCursor As IFeatureCursor • Set pFCursor = pFClass.Search(Nothing, False) • Dim pFeature As IFeature, pSym As ISimpleFillSymbol • Set pFeature = pFCursor.NextFeature • Do Until pFeature Is Nothing • Set pSym = New SimpleFillSymbol • pSym.Color = pColorEnum.Next • pUVRenderer.AddValue _ • pFeature.Value(pFClass.FindField("STATE_NAME")), "States", pSym • Set pFeature = pFCursor.NextFeature • Loop • Set SomeLayer.Renderer = pUVRenderer • m_pMxDoc.UpdateContents • m_pMxDoc.ActiveView.Refresh • End Sub

  15. 分类端点渲染ClassBreaksRenderer • 根据数字字段的值分组,每一个分组使用一个符号 • 属性 • Breaks: 分组的分界点 • Field: 提供属性分组的数字型字段 • BreakCount: 所有分组的数目 • 分类的方法 • 使用列表在OMD图表中适当的 Classify对象

  16. 把图层文件保存到磁盘上 • 可以把图层 保存成图层文件(*.lyr) • 图层文件保存了Layer对象的以下信息 • Layer的数据源的路径 • 符号化的方法 • Label 的方式 • 所定义的查询 • 等等

  17. Example: 在ArcMap中保存一个图层文件 Public Sub SaveFirstLayer() Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument ‘创建一个新的 GxLayer对象 Dim pGxLayer As IGxLayer Set pGxLayer = New GxLayer ‘是一个Coclass可以使用New创建 ‘通过QI取得IGFile接口 Dim pGxFile As IGxFile Set pGxFile = pGxLayer ‘定义文件路径 pGxFile.Path = "C:\Data\Shelbyville.lyr" ‘连接一个Layer对象 Set pGxLayer.Layer = pMxDoc.FocusMap.Layer(0) ‘保存文件 pGxFile.Save ‘完成! End Sub

  18. Using tools(II)

  19. Lesson overview • Tool 工具的事件 • 使用IDisplayTransformation转换屏幕坐标到地图坐标 • 使用IGraphicsContainer来管理图形元素 • 怎么刷新显示

  20. Tool 工具事件 • Tools 工具拥有一些事件过程 • 用于用户交互的事件 • Mouse events: MouseUp, MouseMove, MouseDown, DblClick • Keyboard events: KeyUp, KeyDown • 用于定义工具行为的事件 • Enabled • CursorID • ToolTip • Message Built-In Cursors

  21. 怎么在事件中使用X和Y • 相关的鼠标事件 • MouseUp, MouseDown, MouseMove • 返回的是屏幕单位(pixels) Private Sub UIToolControl1_MouseDown(ByVal button As Long, _ ByVal shift As Long, ByVal x As Long, ByVal y As Long) MsgBox "X = " & x MsgBox "Y = " & y End Sub

  22. Display transformation • 在地图单位和屏幕单位之间转换所用到的方法 • ToMapPoint: 转换一个屏幕坐标点 (pixels)到一个地图坐标点 • FromMapPoint: 转换一个地图坐标点到屏幕坐标点 • 使用鼠标输入 • 捕获鼠标点击的象素值 • 使用地图点

  23. 转换屏幕坐标系到地图单位 • 使用 IDisplayTransformation的ToMapPoint方法 • 返回一个地图单位的点 Dim pMxApp As IMxApplication Set pMxApp = Application Dim pPnt As IPoint Set pPnt = pMxApp.Display.DisplayTransformation.ToMapPoint(x, y) MsgBox "Longitude = " & pPnt.x MsgBox "Latitude = " & pPnt.y

  24. Example: Rubberbanding • 在模块层定义变量 • 在 tool’s Select 事件中初始化 • 在 tool’s MouseDown 事件中输入以下代码 • 把返回值保存在一个对象中 Private m_pRubberBand As IRubberBand Set m_pRubberBand = New RubberLine 'or RubberPolygon or RubberEnvelope Dim pLine As IPolyline Dim pSymbol As ISymbol Set pSymbol = New SimpleLineSymbol Dim pMxApp As IMxApplication Set pMxApp = Application Dim pDisplay As IScreenDisplay Set pDisplay = pMxApp.Display Set pLine = m_pRubberBand.TrackNew(pDisplay, pSymbol)

  25. IGraphicsContainer对象 • 有 Map 和 PageLayout支持 • 也可以使用 IActiveView 的 GraphicsContainer属性来获得 • 用来管理图形元素 • AddElement, AddElements, • DeleteElement, DeleteAllElements • 用来修改图形元素的显示顺序 • BringToFront, BringForward • SendToBack, SendBackward • PutElementOrder

  26. 管理图形元素 'Remove all elements from the Map –or- Layout Set pMxDoc = ThisDocument pMxDoc.ActiveView.GraphicsContainer.DeleteAllElements pMxDoc.ActiveView.Refresh 'Add an element to the Layout Set pMxDoc = ThisDocument Dim pGC As IGraphicsContainer Set pGC = pMxDoc.PageLayout pGC.AddElement pElemArea, 0 pMxDoc.ActiveView.Refresh 'Send selected graphics to the back on Layout Dim pGCSelect As IGraphicsContainerSelect Set pGCSelect = pGC ‘QI pGC.SendToBack pGCSelect.SelectedElements pMxDoc.ActiveView.Refresh

  27. 如何刷新显示 • 使用IActiveView的Refresh方法 • 刷新所有的显示 (但是不刷新TOC表) • 使用IScreenDisplay的Invalidate的方法 • 只刷新指定的范围 (envelope) • 使用IMxDocument的UpdateContents方法 • 通报该文档对象包含的内容发生了变化 • 刷行了内容表对象(TOC)

  28. 部分刷新显示 • 也许你只需要刷新部分的显示区域 • 被新图形元素覆盖的区域 • 比直接刷新整个文档的效率高 • 使用IActiveView的PartialRefresh方法 • 用于 Layout 视图或者 Data view • 指定什么需要刷新 (e.g., graphics) • 指定哪里需要刷新 (an envelope)

  29. Data management(III)

  30. Lesson overview • 转换数据类型 • 使用游标来编辑数据 • Update • Insert • 在现有的Dataset中添加字段

  31. 数据处理对象 • FeatureDataConverter, ExportOperation对象 • 提供以下格式的转换功能 coverage, shapefile, and geodatabase • ObjectLoader对象 • 追加数据到现有的 feature class 或 table • Related objects对象 • FieldChecker: 使用字段名来定位问题 • EnumInvalidObject: 枚举在转换或者追加过程中无效的要素(feature)

  32. 转换要素类feature classes • 使用IFeatureDataConverter的ConvertFeatureClass方法 • 转换输入的要素类到一个新的输出要素类 • 所需要的参数 • Input and output FeatureClassNames • Output FeatureDatasetName • A QueryFilter • Many Others … 'Create a new FeatureDataConverter object Dim pFDConvert As IFeatureDataConverter Set pFDConvert = New FeatureDataConverter

  33. Exercise 14A overview • Convert an ArcInfo coverage to a Personal Geodatabase • IFeatureDataConversion :: ConvertFeatureClass • 在第五天代码阅读时提供

  34. 使用游标来编辑数据 • Update和 Insert类型的游标 • 比使用 ITable::CreateRow, ITable::Store等方法更快 • 在大数据库的情况下更有效 • Use to add, delete, or modify rows or features • ICursor::InsertRow (IFeatureCursor::InsertFeature) • ICursor::DeleteRow (IFeatureCursor::DeleteFeature) • ICursor::UpdateRow (IFeatureCursor::UpdateFeature)

  35. 编辑游标 • 游标返回的类型决定于所使用的方法 • Update cursor • Update method • Use to update or delete records in the database • Insert cursor • Insert method • Use to insert new records into the database Dim pCursor As IFeatureCursor Set pCursor = pFClass.Update(pQFilter, False) Dim pCursor As IFeatureCursor Set pCursor = pFClass.Insert(True)

  36. 例子: 使用Updata游标更新编辑错误的属性 Dim pQFilt As IQueryFilter Set pQFilt = New QueryFilter pQFilt.WhereClause = "StateName = ‘newmexico’" Dim pUpCursor As IFeatureCursor Set pUpCursor = pFClass.Update(pQFilt, False)'Only "newmexico" Dim pFeature As IFeature Set pFeature = pUpCursor.NextFeature Do Until pFeature Is Nothing pFeature.Value(3) = “New Mexico” ‘改正错误 pUpCursor.UpdateFeature pFeature ‘提交记录 Set pFeature = pUpCursor.NextFeature 'Move to the next Loop MsgBox "Features have been updated"

  37. 添加一个字段 • 使用Itable的AddField 方法为现有的dataset对象添加一个字段 • 不需要把Field加入到Fields对象中 • 使用一个Update游标来计算并为字段的赋值 Dim pAverageFld As IFieldEdit Set pAverageFld = New Field With pAverageFld .Name = "Average" .Type = esriFieldTypeInteger .AliasName = "Average Income" .Length = 16 End With pTable.AddField pAverageFld

  38. Working with layout elements(IIII)

  39. Lesson overview • 增加框架元素到PageLayout • 使用 graphics container • 符号化回顾 • Symbols • Colors • Elements • 打印和输出布局

  40. 对象模型图 ArcMap OMD

  41. 回顾: Elements • 有一些可以创建的对象 • 图形元素包含 • Line, polygon, marker • Text and pictures • 框架元素 • 在 PageLayout上 • Map frames • North arrows, legends, scale bars • Table frames

  42. 框架元素FrameElements • 属于 PageLayout 的附属 • MapSurroundFrame elements • MapSurrounds对象的容器 (e.g., Scalebars) • 内容时动态更新的 MapSurroundFrame MapSurround

  43. 例子: 在布局上引用MapFrames对象 Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pGC As IGraphicsContainer’枚举对象 Set pGC = pMxDoc.PageLayout pGC.Reset ‘移动到最前面 Dim pElem As IElement Set pElem = pGC.Next ‘取得第一个条目 Do Until pElem Is Nothing If (TypeOf pElem Is IMapFrame) Then ‘有多种类型 Dim pMapEnvelope As IEnvelope Dim intW As Integer, intH As Integer Set pMapEnvelope = pElem.Geometry.Envelope intW = pMapEnvelope.Width intH = pMapEnvelope.Height MsgBox "Map Frame = " & intW & " by " & intH End If Set pElem = pGC.Next ‘取得下一个条目 Loop

  44. 打印一个a layout • 多样的输出子类 • EmfPrinter (增强的 meta-file) • PsPrinter (支持打印机脚本) • ArcPressPrinter • Paper class • 用来管理打印纸张设置 • 发送到打印机或者是文件

  45. 输出 layout对象 • 多样化的输出格式 • Adobe Acrobat (*.pdf) • JPEG • ArcPress • 使用的IActiveView方法StartExporting • 输出聚焦的Map或PageLayout

  46. 例子: 把Layout输出到一个Jpg文件 • Private Sub Export(aLayout As IActiveView, aPath As String, DPI As Integer) • Dim rectOut As tagRECT • rectOut = aLayout.exportFrame • Dim pExporter As IExporter • Set pExporter = New JpegExporter • Dim pEnv As IEnvelope • Set pEnv = New Envelope • pEnv.PutCoords rectOut.Left, rectOut.Top, rectOut.Right, rectOut.bottom • pExporter.ExportFileName = aPath • pExporter.PixelBounds = pEnv • pExporter.Resolution = DPI

  47. 例子: 把Layout输出到一个Jpg文件 • 'Recalc the export frame to handle the increased number of pixels • Set pEnv = pExporter.PixelBounds • Dim xMin As Double, yMin As Double, xMax As Double, yMax As Double • pEnv.QueryCoords xMin, yMin, xMax, yMax • rectOut.Left = xMin • rectOut.Top = yMin • rectOut.Right = xMax • rectOut.bottom = yMax • Dim hDc As Long • hDc = pExporter.StartExporting • aLayout.Output hDc, DPI, rectOut, Nothing, Nothing • pExporter.FinishExporting • MsgBox "Export complete!", vbInformation • End Sub

  48. 考试题目 1、建立一个UIButtonControl,单击该按钮,加载磁盘上C:\USA\States.shp的 ShapeFile文件到ArcMap的地图中。 2、建立一个UIToolControl,使用该工具时,可以点选其中一个多边形对象,并把选择中记录的序号为6的字段值显示出来。 3、最后的结果是:

More Related