Upload
ciel
View
123
Download
0
Embed Size (px)
DESCRIPTION
Symbolizing elements and layers( I). Lesson overview. 总体介绍符号化对象( symbology objects) 符号对象 Symbol objects 颜色对象 Color objects 颜色梯度对象 Color ramps 为地图添加一个简单的图形( graphics) 使用特征渲染对象修改图层显示方式( FeatureRenderers) 使用图层文件 (*.lyr) 来管理图层的符号化. Symbol 类的子类. *. - PowerPoint PPT Presentation
Citation preview
Copyright © 2001, 2002 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA
Symbolizing elements and layers (I)
12-2Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Lesson overview 总体介绍符号化对象( symbology objects )
符号对象 Symbol objects 颜色对象 Color objects 颜色梯度对象 Color ramps
为地图添加一个简单的图形( graphics )
使用特征渲染对象修改图层显示方式( FeatureRenderers )
使用图层文件 (*.lyr) 来管理图层的符号化
12-3Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Symbol 类的子类ISym bol
M arkerSym bol FillSym bolLineSym bol
Sym bol
Sim pleM arkerSym bol
CharacterM arkerSym bol
P ictureM arkerSym bol
Sim pleLineSym bol
PictureLineSym bol
HashLineSym bol
Sim pleFillSym bol
LineFillSym bol
M arkerFillSym bol
* Several additional types of symbols are listed on the Display OMD, including TextSymbols
*
12-4Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
以下五种可创建的对象 RgbColor (红、绿、蓝) CmykColor (青、洋红、黄、黑) HsvColor (色调、饱和度、值) HlsColor (色调、亮度、饱和度) GrayColor (灰度)
用来定义颜色对象的属性 Red, Green, Blue values (0–255) 灰度 (0=white – 255=black) Cyan, Magenta, Yellow, Black
使用 Color 对象来访问一个 Symbol 对象的 Color 属性
使用 color 对象IColo r Color
GrayColor
RgbColor
Cm ykColor
HlsColor
HsvColor
12-5Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
颜色梯度对象 ColorRamps 四种可以创建的对象
Algorithmic ColorRamp (算法颜色梯度) Random ColorRamp (随机颜色梯度) Preset ColorRamp (预定义颜色梯度) MultiPart ColorRamp (多部分的颜色梯度)
IColorR am p ColorRam p
Algorithm icColorRam p
M ultiPartColorRam p
PresetColorRam p
Random ColorRam p
12-6Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
创建一个新的 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 对象。是一个枚举对象。
12-7Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
创建简单的图形元素 ( graphic elements) 有一些可以创建的对象 图形元素的种类
Line, polygon, marker Text and pictures
框架元素( FrameElements ) 在 PageLayout 上使用 Map frames North arrows, legends, scale bars Table frames
Elem entIE lem ent Geom etry
GraphicElem entFram eElem ent
Bm pPictureElem ent
TextE lem ent
M arkerElem ent
LineElem ent
12-8Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
例子 : 创建一个新的图形元素并设置它的符号Dim pMarkerElem As IMarkerElementSet pMarkerElem = New MarkerElement ‘ 创建一个新的元素Dim pMarkerSym As ISimpleMarkerSymbolSet pMarkerSym = New SimpleMarkerSymbol ‘ 创建新符号pMarkerSym.Style = esriSMSCircle ‘ 指定符号的风格Dim pColor As IRgbColorSet pColor = New RgbColor ‘ 创建一个新颜色pColor.RGB = RGB(255,0,0) ‘ 设置成红色pMarkerSym.Color = pColor ‘ 把颜色赋给符号pMarkerElem.Symbol = pMarkerSym ‘ 把符号赋给元素
12-9Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
定义一个元素的位置 使用 IElement 的 Geometry 属性
被所有 Element 的子类所支持 在地图( Map )或布局 (layout page) 上定位 定位可以指定为 point, line, envelope 等Dim pElem As IElementSet pElem = pMarkerElem 'QI
Dim pPoint As IPointSet pPoint = New PointpPoint.PutCoords 65.751, -7.534
pElem.Geometry = pPoint
沿线标注文本类型的 Element 的定位就可以是 Line 对象
12-10Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
把一个元素添加到 map ( 或者 layout) 使用 IGraphicsContainer :: AddElement
指定添加的元素和它的序号 0 号的序号是第一个(最顶部)的元素,序号从顶到底逐渐增加Dim pMxDoc As IMxDocumentSet pMxDoc = ThisDocumentpMxDoc.ActiveView.GraphicsContainer.AddElement pElem, 0 ‘或者使用以下语句Dim pGContainer As IGraphicsContainerSet pGContainer = pMxDoc.FocusMap ‘QIpGContainer.AddElement pElem, 0 '0=top element
pMxDoc.ActiveView.Refresh
通过刷新屏幕来显示新添加的元素
12-12Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
FeatureRenderers 对象 Renderers 方法定义了 layer 对象是怎么显示的
FeatureRendererIFeatureRenderer
DotDensityRenderer
S im pleRenderer
ScaleDependentRenderer
FeatureLayer
ClassBreaksRenderer
ChartRenderer
UniqueValueRenderer
其它的 Renderers 对象可以用来显示 RasterLayers 和 TinLayers
12-13Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
简单渲染 SimpleRenderer 默认的使用简单的符号来渲染显示要素
属性 Symbol: 颜色和风格 Label: 在 legend 中显示的字符串
在修来了图层的渲染方式之后需要执行刷新操作
USA
‘ 设置一个要素类图层的渲染对象Set pFLayer.Renderer = pRender‘刷新显示pMxDoc.ActiveView.Refresh‘刷新内容表 (TOC) 显示新的图标pMxDoc.UpdateContents
12-14Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
根据不同的唯一值用一个符号来显示要素
属性 Field(s): 提供唯一分类值的字段 Value(s): 特征的唯一分类值 ValueCount: 需要显示的唯一分类值的数目
唯一值渲染 UniqueValueRenderer
12-15Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
例子 : 创建一个 唯一值专题图为每个州赋一个符号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.RefreshEnd Sub
12-16Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
根据数字字段的值分组,每一个分组使用一个符号
属性 Breaks: 分组的分界点 Field: 提供属性分组的数字型字段 BreakCount: 所有分组的数目
分类的方法 使用列表在 OMD 图表中适当的 Classify 对象
分类端点渲染 ClassBreaksRenderer
12-17Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
把图层文件保存到磁盘上 可以把图层 保存成图层文件 (*.lyr) 图层文件保存了 Layer 对象的以下信息
Layer 的数据源的路径 符号化的方法 Label 的方式 所定义的查询 等等
12-18Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
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
Copyright © 2001, 2002 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA
Using tools(II)
12-20Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Lesson overview Tool 工具的事件 使用 IDisplayTransformation 转换屏幕坐标到地图坐标 使用 IGraphicsContainer 来管理图形元素 怎么刷新显示
12-21Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Tool 工具事件 Tools 工具拥有一些事件过程 用于用户交互的事件
Mouse events: MouseUp, MouseMove, MouseDown, DblClick Keyboard events: KeyUp, KeyDown
用于定义工具行为的事件 Enabled CursorID ToolTip Message
Built-In Cursors
12-22Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
怎么在事件中使用 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
12-23Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Display transformation 在地图单位和屏幕单位之间转换所用到的方法
ToMapPoint: 转换一个屏幕坐标点 (pixels) 到一个地图坐标点 FromMapPoint: 转换一个地图坐标点到屏幕坐标点
使用鼠标输入 捕获鼠标点击的象素值 使用地图点
12-24Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
转换屏幕坐标系到地图单位 使用 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
12-25Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
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)
12-26Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
IGraphicsContainer 对象 有 Map 和 PageLayout 支持
也可以使用 IActiveView 的 GraphicsContainer 属性来获得
PageLayout
MxDocument
Map*
IGraphicsContainer
IGraphicsContainer
用来修改图形元素的显示顺序BringToFront, BringForwardSendToBack, SendBackwardPutElementOrder
用来管理图形元素AddElement, AddElements, DeleteElement, DeleteAllElements
12-27Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
管理图形元素'Remove all elements from the Map –or- LayoutSet pMxDoc = ThisDocumentpMxDoc.ActiveView.GraphicsContainer.DeleteAllElementspMxDoc.ActiveView.Refresh
'Add an element to the LayoutSet pMxDoc = ThisDocumentDim pGC As IGraphicsContainerSet pGC = pMxDoc.PageLayoutpGC.AddElement pElemArea, 0pMxDoc.ActiveView.Refresh
'Send selected graphics to the back on LayoutDim pGCSelect As IGraphicsContainerSelectSet pGCSelect = pGC ‘QIpGC.SendToBack pGCSelect.SelectedElementspMxDoc.ActiveView.Refresh
12-28Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
如何刷新显示 使用 IActiveView 的 Refresh 方法
刷新所有的显示 ( 但是不刷新 TOC 表 )
使用 IScreenDisplay 的 Invalidate 的方法 只刷新指定的范围 (envelope)
使用 IMxDocument 的 UpdateContents 方法 通报该文档对象包含的内容发生了变化 刷行了内容表对象( TOC )
12-29Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
部分刷新显示 也许你只需要刷新部分的显示区域
被新图形元素覆盖的区域比直接刷新整个文档的效率高
使用 IActiveView 的 PartialRefresh 方法 用于 Layout 视图或者 Data view 指定什么需要刷新 (e.g., graphics) 指定哪里需要刷新 (an envelope)
Copyright © 2001, 2002 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA
Data management(III)
12-31Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Lesson overview 转换数据类型 使用游标来编辑数据
Update Insert
在现有的 Dataset 中添加字段
12-32Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
数据处理对象 FeatureDataConverter, ExportOperation 对象
提供以下格式的转换功能 coverage, shapefile, and geodatabase
ObjectLoader 对象追加数据到现有的 feature class 或 table
Related objects 对象 FieldChecker: 使用字段名来定位问题 EnumInvalidObject: 枚举在转换或者追加过程中无效的要素
( feature )
12-33Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
转换要素类 feature classes 使用 IFeatureDataConverter 的 ConvertFeatureClass 方法
转换输入的要素类到一个新的输出要素类 所需要的参数
Input and output FeatureClassNames Output FeatureDatasetName A QueryFilter Many Others … 'Create a new FeatureDataConverter object
Dim pFDConvert As IFeatureDataConverterSet pFDConvert = New FeatureDataConverter
12-34Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Exercise 14A overview Convert an ArcInfo coverage to a Personal Geodatabase
IFeatureDataConversion :: ConvertFeatureClass
在第五天代码阅读时提供
12-35Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
使用游标来编辑数据 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)
12-36Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
编辑游标游标返回的类型决定于所使用的方法 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)
12-37Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Dim pQFilt As IQueryFilterSet pQFilt = New QueryFilterpQFilt.WhereClause = "StateName = ‘newmexico’"
Dim pUpCursor As IFeatureCursorSet pUpCursor = pFClass.Update(pQFilt, False)'Only "newmexico"
Dim pFeature As IFeatureSet pFeature = pUpCursor.NextFeatureDo Until pFeature Is Nothing pFeature.Value(3) = “New Mexico” ‘ 改正错误 pUpCursor.UpdateFeature pFeature ‘ 提交记录 Set pFeature = pUpCursor.NextFeature 'Move to the nextLoop
MsgBox "Features have been updated"
例子 : 使用 Updata游标更新编辑错误的属性
12-38Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
添加一个字段 使用 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
Copyright © 2001, 2002 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA
Working with layout elements ( IIII )
12-40Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
Lesson overview 增加框架元素到 PageLayout 使用 graphics container 符号化回顾
Symbols Colors Elements
打印和输出布局
12-41Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
对象模型图
GraphicElem ent Fram eElem ent
*PageLayoutElem ent
M ap
*M apSurround
M xDocum ent
*
Geom etry
LineElem ent
M arkerElem ent
TextE lem ent
M apSurroundFram e
TableFram e
ScaleBar
Legend
M apFram e
ArcMap OMD
12-42Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
回顾 : Elements 有一些可以创建的对象 图形元素包含
Line, polygon, marker Text and pictures
框架元素 在 PageLayout 上 Map frames North arrows, legends, scale bars Table frames
Elem entIE lem ent Geom etry
GraphicE lem entFram eElem ent
Bm pPictureElem ent
TextElem ent
M arkerElem ent
LineElem ent
12-43Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
框架元素 FrameElements 属于 PageLayout 的附属 MapSurroundFrame elements
MapSurrounds 对象的容器 (e.g., Scalebars) 内容时动态更新的
IE lem ent
GraphicElem ent Fram eElem ent
TextE lem ent M apFram e
M apSurroundFram e
*PageLayoutElem ent
M ap
*M apSurround
ScaleBar
MapSurroundFrame
MapSurround
12-44Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
例子 : 在布局上引用 MapFrames 对象Dim pMxDoc As IMxDocumentSet pMxDoc = ThisDocumentDim pGC As IGraphicsContainer’ 枚举对象Set pGC = pMxDoc.PageLayoutpGC.Reset ‘移动到最前面Dim pElem As IElementSet 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.WidthintH = pMapEnvelope.Height
MsgBox "Map Frame = " & intW & " by " & intH End If
Set pElem = pGC.Next ‘ 取得下一个条目Loop
12-45Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
打印一个 a layout 多样的输出子类
EmfPrinter ( 增强的 meta-file) PsPrinter ( 支持打印机脚本 ) ArcPressPrinter
Paper class 用来管理打印纸张设置
发送到打印机或者是文件
PrinterIPrinter
Em fPrinter PsPrinter
ArcPressPrinter
Application Paper
12-46Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
输出 layout 对象 多样化的输出格式
Adobe Acrobat (*.pdf) JPEG ArcPress
使用的 IActiveView 方法 StartExporting 输出聚焦的 Map 或 PageLayout
ExporterIExporter
JpegExporter PdfExporter TiffExporter
PsExporterArcPressExporterIA rcPressExporter
ArcPressExporterJPEG ArcPressExporter T IFF
12-47Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
例子 : 把 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
12-48Introduction to Programming ArcObjects with VBACopyright © 2001, 2002 ESRI. All rights reserved.
例子 : 把 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