内容发布更新时间 : 2024/11/14 14:45:29星期一 下面是文章的全部内容请认真阅读。
Set pFields =m_pFClass.Fields i =pFields.FindField(\
'Assume wehavealreadyspecifiedaqueryfilter Set pFCursor =m_pFClass.Update(pQueryFilter,False)
Set pFeature =pFCursor.NextFeature Do UntilpFeatureIsNothing
'Update theFieldNAMEwiththevalue\ pFeature.value(i) = \ pFCursor.UpdateFeature pFeature Set pFeature =pFCursor.NextFeature Loop
IFeatureCursor接口的第三个方法InsertFeature(buffer) (方法,用参数传进来的属性值插入一个新的要素到数据库中,返回该插入新的Feature的ID值,其中参数类型为IFeatureBuffer)
例子代码:
Public Sub FeatureBufferCode() Dim pWorFactAsIWorkspaceFactory Dim pWorAsIWorkspace Dim pFeatWorAsIFeatureWorkspace Dim pWorEditAsIWorkspaceEdit Dim pFCAsIFeatureClass Dim pFeatureBufferAsIFeatureBuffer Dim pFeatureCursorAsIFeatureCursor Dim pFeatureAsIFeature Dim pPolylineAsIPolyline Dim ptAsIPoint Dim qAsLong,iAsLong
Set pWorFact =NewAccessWorkspaceFactory
Set pWor =pWorFact.OpenFromFile(\:\\Testing\\Data\\GDB1.mdb\ Set pFeatWor =pWor Set pWorEdit =pWor
Set pFC =pFeatWor.OpenFeatureClass(\
pWorEdit.StartEditing True pWorEdit.StartEditOperation
SetpFeatureBuffer= pFC.CreateFeatureBuffer SetpFeatureCursor= pFC.Insert(True) SetpFeature =pFeatureBuffer SetpPolyline =NewPolyline
'Create100featuresusingFeatureBufferandinsertintoafeaturecursor Fori =0To99
'Create the polylinegeometrytoassigntothenewfeature Set pt = NewPoint pt.X = 2213300+i pt.Y = 396500+i pPolyline.FromPoint =pt Set pt = NewPoint pt.X = 2213300+i pt.Y = 396500+i pPolyline.ToPoint =pt
'Set the feature'sshape Set pFeature.Shape = pPolyline
'Insert the featureintothefeaturecursor q = pFeatureCursor.InsertFeature(pFeatureBuffer) Nexti
'Flushthefeaturecursortothedatabase pFeatureCursor.Flush pWorEdit.StopEditOperation pWorEdit.StopEditing True
End Sub
16. 关于IQueryFilter接口(esriGeoDatabase)
Dim pQueryFilter AsIQueryFilter Set pQueryFilter = NewQueryFilter
pQueryFilter.SubFields= \ pQueryFilter.WhereClause= \ 'California'\
Dim pFeatureCursor AsIFeatureCursor
Set pFeatureCursor = pFeatureClass.Search(pQueryFilter,False) IQueryFilter接口的第一个属性WhereClause(读写,为过滤器设置条件语句)
注意!各种不同的数据,设置条件查询语句的语法是不相同的,如一个shp文件在设置字段的时候要加“””双引号,而在SDE数据连接中,则什么都不加;在gdb文件的语句中,符号是“*”,而在SDE或者shp文件查询中则是“%” IQueryFilter接口的第二个属性SubFields(读写,为过滤器设置提供赛选的字段,用逗号来分隔每一个逗号,如果不设置该属性,则当做所有字段均为查找字段)
17. 关于IFeatureLayer接口(esriCarto)
Sub AddLayer()
'createsaFeatureLayerfromashapefileandaddstothemapinArcMap Dim pShpWksFactAsIWorkspaceFactory Dim pFeatWksAsIFeatureWorkspace Dim pFeatClassAsIFeatureClass Dim pFeatLayerAsIFeatureLayer Dim pDataSetAsIDataset Dim pMxDocAsIMxDocument Dim pMapAsIMap
Set pShpWksFact =NewShapefileWorkspaceFactory
Set pFeatWks =pShpWksFact.OpenFromFile(\:\\Data\\CentreCounty\ Set pFeatClass =pFeatWks.OpenFeatureClass(\ Set pFeatLayer =NewFeatureLayer Set pFeatLayer.FeatureClass= pFeatClass Set pDataSet =pFeatClass pFeatLayer.Name =pDataSet.Name Set pMxDoc =Application.Document Set pMap =pMxDoc.FocusMap pMap.AddLayerpFeatLayer
End Sub
IFeatureLayer接口的第一个属性FeatureClass(读写,设置或者读取此layer的要素类) IFeatureLayer接口的第二个属性MaximumScale(读写,设置或者读取此layer显示的最大比例尺) IFeatureLayer接口的第三个属性MinimumScale(读写,设置或者读取此layer显示的最小比例尺)
IFeatureLayer接口的第四个方法Search (queryFilter, recycling ) (方法,创建一个游标去查询相应设置的过滤器的查询)
IFeatureLayer接口的第五个属性Visible(读写,设置或者读取此layer的可见性)
IFeatureLayer接口的第六个属性AreaOfInterest(只读,读取此layer的最大范围,回返一个IEnvelope接口的变量)
18. 关于IFeatureSelection接口(esriCarto)
IFeatureSelection接口的第一个方法SelectFeatures (Filter, Method, justOne ) (方法,根据指定的标准过滤器filter和方法,选择要素,第一个参数为QueryFilter类型的变量,第二个参数为esriSelectionResultEnum类型的变量,第三个参数为布尔型变量,通常为false)
19. 关于IMap接口(esriCarto)
IMap接口的第一个属性Layers (uid, recursive ) (只读,第二个参数为True的时候,该属性获取第一个参数uid指定的Layers,赋值给一个IEnumLayer的变量)
例子代码:
Sub GetFeatureLayers() Dim pMxDocumentAsIMxDocument Dim pMapAsIMap
Dim pEnumLayerAsIEnumLayer Dim pLayerAsILayer Dim pIdAsNewUID
Set pMxDocument =Application.Document Set pMap =pMxDocument.FocusMap
pId =\-22AF-11D3-9F99-00C04F6BC78E}\ Set pEnumLayer =pMap.Layers(pId,True) pEnumLayer.Reset
Set pLayer =pEnumLayer.Next Do WhileNotpLayerIsNothing MsgBox pLayer.Name Set pLayer =pEnumLayer.Next Loop
End Sub
其中比较常用的UID参数值如下: {6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IDataLayer {40A9E885-5533-11d0-98BE-00805F7CED21} IFeatureLayer {E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGeoFeatureLayer {34B2EF81-F4AC-11D1-A245-080009B6F22B} IGraphicsLayer {5CEAE408-4C0A-437F-9DB3-054D83919850} IFDOGraphicsLayer {0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} ICoverageAnnotationLayer
{EDAD6644-1810-11D1-86AE-0000F8751720} IGroupLayer
IMap接口的第二个属性LayerCount(只读,返回该map里面Layer的个数) IMap接口的第三个属性Layer(Index) (只读,返回指定索引index位置的Layer) IMap接口的第四个方法AddLayer(Layer) (方法,向该map添加一个Layer)
例子代码:
Public Sub AddShapeFile()
Dim pWorkspaceFactoryAsIWorkspaceFactory Dim pFeatureWorkspaceAsIFeatureWorkspace Dim pFeatureLayerAsIFeatureLayer Dim pMxDocumentAsIMxDocument Dim pMapAsIMap
Set pWorkspaceFactory= New ShapefileWorkspaceFactory
Set pFeatureWorkspace= pWorkspaceFactory.OpenFromFile(\:\\digitizing\ Set pFeatureLayer =NewFeatureLayer
Set pFeatureLayer.FeatureClass= pFeatureWorkspace.OpenFeatureClass(\ pFeatureLayer.Name= pFeatureLayer.FeatureClass.AliasName Set pMxDocument =Application.Document Set pMap =pMxDocument.FocusMap
pMap.AddLayerpFeatureLayer'alternatively,wecouldcallAddLayeronIMXDocument
End Sub
IMap接口的第五个方法AddLayers(Layers, autoArrange) (方法,添加一个EnumLayer变量的layers到该map,第一个参数为IEnumLayer类型,第二个参数为bool型变量)
IMap接口的第六个方法ClearLayers(方法,将所有的layer从map中移除) IMap接口的第七个方法ClearSelection(方法,将该map中选择的要素清空) IMap接口的第八个属性SelectionCount(只读,返回该map被选中要素的个数)
IMap接口的第九个方法SelectFeature(Layer,Feature) (方法,从一个Layer中选择一个Feature) IMap接口的第十个属性MapScale(读写,获取或者设置当前map的地图比例尺,double类型)
IMap接口的第十一个方法MoveLayer(Layer,toIndex) (方法,把一个Layer从当前的位置移动到指定的索引位置)
例子代码:
Public Sub MoveLayer()
Dim pMxDocumentAsIMxDocument Dim pMapAsIMap