《ArcGIS接口详细说明之个人开发心得.doc》由会员分享,可在线阅读,更多相关《ArcGIS接口详细说明之个人开发心得.doc(42页珍藏版)》请在三一办公上搜索。
1、ArcGIS接口详细说明之个人开发心得万人迷先生217 /文 tj051181 /整理1. 关于IField接口(esriGeoDatabase)3楼2. 关于IFieldEdit接口(esriGeoDatabase)4楼3. 关于IFields接口(esriGeoDatabase)5楼4. 关于IPoint接口(esriGeometry)6楼5. 关于IPointArray接口(esriGeometry)7楼6. 关于IPointCollection接口(esriGeometry)8楼 7. 关于IPolyline接口(esriGeometry)9楼8. 关于IGeometry接口(esri
2、Geometry)10楼9. 关于IArea接口(esriGeometry)11楼10. 关于IEnvelope接口(esriGeometry)12楼11. 关于IFeature接口(esriGeoDatabase)13楼12. 关于IRow接口(esriGeoDatabase)14楼13. 关于IFeatureClass接口(esriGeoDatabase)15楼14. 关于ITable接口(esriGeoDatabase)16楼15. 关于IFeatureCursor接口(esriGeoDatabase)17楼16. 关于IQueryFilter接口(esriGeoDatabase)18楼
3、17. 关于IFeatureLayer接口(esriCarto)19楼18. 关于IFeatureSelection接口(esriCarto)20楼19. 关于IMap接口(esriCarto) 21楼20. 关于IPropertySet接口(esriSystem) 22楼21. 关于IFeatureWorkspace接口(esriGeoDatabase)23楼22. 关于IWorkspaceEdit接口(esriGeoDatabase)24楼23. 关于IWorkspaceFactory接口(esriGeoDatabase)25楼24. 关于ITopologicalOperator接口(es
4、riGeometry)26楼25. 创建Buffer并选择里面的要素 27楼26. Merge要素Union要素28楼27. 怎样从Table中获取具体需求值的Row 42楼28. 怎样ZoomInCenter 43楼29. 怎样读取一个字段内的所有值 44楼30. 怎样编辑更改属性字段的值 45楼31. 怎样将MapControl中的Map复制到PageLayoutControl中 47楼32. 怎样判断是否出于编辑状态 63楼33. 怎样用点创建一个Polygon 64楼34. 怎样运用属性来计算总面积 65楼35. 关于属性域的一些心得 82楼36. 怎样实现翻折Flip方法 83楼37
5、. 回答cumtbGIS关于ITopologicalOperator接口Clip方法的问题 87楼38. 回答机器猫FJJ关于ISpatialFilter接口方法的问题(完整函数) 91楼39. 回答网友韶华响当当关于更改符号的代码(完整函数) 100楼40. 回答网友韶华响当当关于显示属性的代码(完整函数) 101楼41. 回答gjw1015关于IFeature变量添加进List数组里的问题 112楼1. 关于IField接口(esriGeoDatabase)IField接口的第一个属性AliasName(只读,获得字段的别名)IField接口的第二个方法CheckValue(Value)(
6、方法,对于指定的属性字段,基于字段类型判断参数值是否有效,有效,则返回True,否则返回False)例子代码:IFeatureClass pFC_SCP_PT;editPT = new FieldClass();editPT.Precision_2 = 8;editPT.Scale_2 = 3;editPT.Name_2 = ELEV1;editPT.Type_2 = esriFieldType.esriFieldTypeDouble;IField接口的其他属性均为只读属性,常用有Name(只读,获得字段的名称)例子代码:Dim pFields As IFieldsDim pField As
7、IFieldDim pGeoDef As IGeometryDefDim pDomain As IDomainDim i As LongSet pFields = pFeatClass.FieldsFor i = 0 To pFields.FieldCount - 1Set pField = pFields.Field(i)If pField.Type = esriFieldTypeGeometry Then Set pGeoDef = pField.GeometryDefElse Debug.Print pField.AliasName Debug.Print pField.DefaultV
8、alue Set pDomain = pField.Domain Debug.Print pField.Editable Debug.Print pField.IsNullable Debug.Print pField.Length Debug.Print pField.Name Debug.Print pField.Precision Debug.Print pField.Required Debug.Print pField.Scale Debug.Print pField.Type Debug.Print pField.VarTypeEnd IfNext2. 关于IFieldEdit接口
9、(esriGeoDatabase)所有该接口的属性均为可读可写,经常用与对新建字段的设置,因为字段一旦被设置,其基本属性就不能被更改,所以就需要该接口类型的变量去转换,方法为:IFeatureClass pFC_SCP_PT;IFieldEdit editPT = new FieldClass();pFC_SCP_PT.AddField(IField)editPT);如果在vb中去编写代码,则赋值和获取均为同一属性,而在C#中,为了区分设置和获取,属性均有两个,类似于Name和Name_2,这样就可以区分了,普遍用设置的带有_2的那个属性。IFieldEdit接口的第一个属性Name (读写,
10、设置或者获取该变量类型变量字段的名称)IFieldEdit接口的第二个属性Precision(读写,设置或者获取该变量类型变量字段的长度)IFieldEdit接口的第三个属性Scale(读写,设置或者获取该变量类型变量字段的精度)IFieldEdit接口的第四个属性Type(读写,设置或者获取该变量类型变量字段的类型)例子代码:IFeatureClass pFC_SCP_PT;editPT = new FieldClass();editPT.Precision_2 = 8;editPT.Scale_2 = 3;editPT.Name_2 = ELEV1;editPT.Type_2 = esri
11、FieldType.esriFieldTypeDouble;3. 关于IFields接口(esriGeoDatabase)IFields接口的第一个属性Field(Index)(只读,以用于获取具体的字段,返回类型为IField)IFields接口的第二个属性FieldCount(只读,以用于获取属性的数量)利用上面两个接口并用索引去依次循环获得每一列的属性pField(Ifield接口)例子代码:Dim i As LongDim pField As IFieldFor i = 0 To (pFields.FieldCount - 1) Set pField = pFields.Field(i
12、) Debug.Print pField.Name & : & pField.TypeNext iIFields接口的第三个方法FindField(Name)(方法,输入想要查找的属性域字段的名称,如果有,则返回该属性域字段在此Fields的索引,没有则返回-1)例子代码:Dim i As IntegerDim pFields As IFieldsDim pField As IFieldGet FieldsSet pFields = pFeatClass.FieldsFind the field named average_incomei = pFields.FindField(average
13、_income)Set the current fieldSet pField = pFields.Field(i)Delete field from featureclasspFeatClass.DeleteField pFieldIFields接口的第四个方法FindFieldByAliasName(Name)(方法,与第三个方法类似,此时输入的为该列属性字段的别名,此方法不经常用)例子代码:Dim i As IntegerDim pFields As IFieldsDim pField As IFieldGet FieldsSet pFields = pFeatClass.Fields
14、Find the field with the aliasname current populationi = pFields.FindFieldByAliasName(current population)Set the current fieldSet pField = pFields.Field(i)Delete field from featureclasspFeatClass.DeleteField pField4. 关于IPoint接口(esriGeometry)IPoint接口的第一个方法PutCoords(X,Y)(方法,设置该点的坐标)或者直接调用可以读写的属性X和Y,将坐标
15、赋值给X和Y例子代码:Dim pPoint As IPointSet pPoint = New PointpPoint.PutCoords 100, 100IPoint接口的第二个方法QueryCoords(X,Y) (方法,得到该点的坐标)例子代码:Dim pPoint as IPointDim dX as Double, dY as DoublepPoint.QueryCoords dX, dYIPoint接口的第三个方法ConstrainAngle (constraintAngle, anchor, allowOpposite ) (方法,如果第三个参数allowOpposite为Tru
16、e,则将第二个参数anchor这个点作为一个原点,然后以第一个参数 constraintAngle为与x轴的角度,做一条直线,再将调用此参数的点向该直线做垂线并交于一个新点,并将调用此方法的点移动到该点)例子代码:Finds the closes point to line from (0,0) with angles defined by steps of pi/4 (Note all angles in radians) Dim pApoint As IPoint Dim pNpoint As IPoint Dim pi As Double Dim dAngle As Double Dim
17、 i As Long Set pApoint = New Point pi = 4 * Atn(1) dAngle = 0 pApoint.PutCoords 0, 0 Set pNpoint = New Point For i = 0 To 7 pNpoint.PutCoords 1, 0 dAngle = i * pi / 4 pNpoint.ConstrainAngle dAngle, pApoint, True MsgBox angle = & i & *pi/4 & vbCrLf & pNpoint.X & , & pNpoint.Y Next iIPoint接口的第四个方法Cons
18、trainDistance (constraintRadius, anchor ) (方法,以第二个参数anchor这个点为圆心,然后以第一个参数constraintRadius为半径做一个圆,将调用此参数的点移动到该点与圆心做线段交于该圆的交点上)例子代码:Public Sub t_constraindistance() Dim pPoint As IPoint Dim pNPoint As IPoint Dim dRadius As Double Set pPoint = New Point pPoint.PutCoords 0, 0 Set pNPoint = New Point pNP
19、oint.PutCoords 2, 2 dRadius = 1.4142135623731 pNPoint.ConstrainDistance dRadius, pPoint MsgBox Radius = & dRadius & x,y = & pNPoint.X & , & pNPoint.Y End Sub5. 关于IPointArray接口(esriGeometry)IPointArray接口的第一个方法Add(p) (方法,向该类型的数组变量添加Point)IPointArray接口的第二个属性Count (只读,获得该数组变量中Point的个数,返回Long类型变量)IPointA
20、rray接口的第三个属性Element(Index) (只读,获得该数组变量中位于参数Index索引位置的点Point,返回一个Point类型的变量)IPointArray接口的第四个方法Insert (Index, p ) (方法,向索引位置Index插入一个点Point)IPointArray接口的第五个方法Remove (Index )(方法,移除索引位置Index的点Point)IPointArray接口的第六个方法RemoveAll (方法,移除所有在此数组中的点)6. 关于IPointCollection接口(esriGeometry)IPointCollection接口的第一个方
21、法AddPoint(inPoint ,before ,after) (方法,向该类型的点集变量添加Point,第一个参数为添加的Point,第二个第三个参数为可选择的参数,默认添加进点集的末尾)IPointCollection接口的第二个属性Point(i) (只读,获得该点集变量中第i个位置的Point,返回IPoint类型变量,i从0计算开始)IPointCollection接口的第三个属性PointCount (只读,获得该点集变量中点的个数,返回Long类型变量,切记,如果一个PointCollection变量是由闭合的Geometry转换而来的话,那么点的个数比节点数多一个,因为是闭
22、合的,所以首位节点是同一个点)7. 关于IPolyline接口(esriGeometry)IPolyline接口的第一个属性FromPoint与ToPoint(读写,设置或者读取该点的起始点和终止点,返回都是IPoint类型的变量)IPolyline接口的第二个方法QueryFromPoint (from )(方法,返回IPoint类型的变量到参数from)IPolyline接口的第三个方法QueryToPoint (to ) (方法,返回IPoint类型的变量到参数to)Public Sub t_ICurve_QueryPoints() Dim pID As New UID pID = es
23、riEditor.editor Dim pEditor As IEditor Dim pApp As IApplication Set pApp = MxApplication Set pEditor = pApp.FindExtensionByCLSID(pID) If pEditor.SelectionCount 1 Then MsgBox select one Curve Exit Sub End If Dim pEnumFeat As IEnumFeature Dim pFeature As IFeature Set pEnumFeat = pEditor.EditSelection
24、Dim pCurve As ICurve Dim pPointFrom As IPoint Dim pPointTo As IPoint Set pPointFrom = New Point Set pPointTo = New Point Set pFeature = pEnumFeat.Next While Not pFeature Is Nothing If pFeature.Shape.GeometryType = esriGeometryPolyline Or _ esriGeometryPolyline Or esriGeometryLine Then Set pCurve = p
25、Feature.Shape pCurve.QueryFromPoint pPointFrom pCurve.QueryToPoint pPointTo MsgBox +ICurve properties. & vbCrLf _ & Curve.QueryFromPoint (x,y) = & pPointFrom.X & , & pPointFrom.Y & vbCrLf _ & Curve.QueryToPoint (x,y) = & pPointTo.X & , & pPointTo.Y & vbCrLf End If Set pFeature = pEnumFeat.Next WendE
26、nd SubIPolyline接口的第四个方法Generalize (maxAllowableOffset ) (方法,用道格拉斯普克发来简化polyline)IPolyline接口的第五个方法Weed (maxAllowableOffsetFactor ) (方法,和方法Generalize类似,均为简化polyline的方法,不同的是参数。)8. 关于IGeometry接口(esriGeometry)Public Sub t_IGeometry_polygon() Dim pID As New UID pID = esriEditor.editor Dim pEditor As IEdit
27、or Dim pApp As IApplication Set pApp = Application Set pEditor = pApp.FindExtensionByCLSID(pID) If pEditor.SelectionCount 1 Then MsgBox select one polygon Exit Sub End If Dim pEnumFeat As IEnumFeature Dim pFeature As IFeature Set pEnumFeat = pEditor.EditSelection Dim pGeometry As IGeometry Set pFeat
28、ure = pEnumFeat.Next While Not pFeature Is Nothing If pFeature.Shape.GeometryType = esriGeometryPolygon Then(通过pFeature.Shape获得Geometry) Set pGeometry = pFeature.Shape MsgBox +Polygon:IGeometry properties. & vbCrLf _ & Dimension = & pGeometry.Dimension & vbCrLf _ & Geometry type = & pGeometry.Geomet
29、ryType & vbCrLf _ & Envelope = & pGeometry.Envelope.XMin & , & pGeometry.Envelope.YMin & , _ & pGeometry.Envelope.XMax & , & pGeometry.Envelope.YMin & vbCrLf _ & IsEmpty = & pGeometry.IsEmpty & vbCrLf _ & SpatialReference = & pGeometry.SpatialReference.Name End If Set pFeature = pEnumFeat.Next Wend
30、End SubIGeometry接口的第一个属性Dimension(只读,返回一个类型为esriGeometryDimension的该图形的几何维度)-1 esriGeometryNoDimension 1 esriGeometry0Dimension 2 esriGeometry1Dimension 4 esriGeometry2Dimension 5 esriGeometry25Dimension 6 esriGeometry3DimensionIGeometry接口的第二个属性Extent(只读,返回一个类型为IEnvelope的该图形的几何范围的最大边框)IGeometry接口的第三个
31、属性GeometryType(只读,返回一个类型为esriGeometryType的该图形的几何类型)esriGeometryNull = 0esriGeometryPoint = 1esriGeometryMultipoint = 2esriGeometryPolyline = 3esriGeometryPolygon = 4esriGeometryEnvelope = 5esriGeometryPath = 6esriGeometryAny = 7esriGeometryMultiPatch = 9esriGeometryRing = 11esriGeometryLine = 13esri
32、GeometryCircularArc = 14esriGeometryBezier3Curve= 15esriGeometryEllipticArc = 16esriGeometryBag = 17esriGeometryTriangleStrip = 18esriGeometryTriangleFan = 19esriGeometryRay = 20esriGeometrySphere = 219. 关于IArea接口(esriGeometry)Public Sub t_IArea_polygon() Dim pID As New UID pID = esriEditor.editor D
33、im pEditor As IEditor Dim pApp As IApplication Set pApp = Application Set pEditor = pApp.FindExtensionByCLSID(pID) If pEditor.SelectionCount 1 Then MsgBox select one polygon Exit Sub End If Dim pEnumFeat As IEnumFeature Dim pFeature As IFeature Dim i As Long Set pEnumFeat = pEditor.EditSelection Dim
34、 pArea As IArea Dim pCenter As IPoint Dim pLabel As IPoint Set pCenter = New Point Set pLabel = New Point Set pFeature = pEnumFeat.Next While Not pFeature Is Nothing If pFeature.Shape.GeometryType = esriGeometryPolygon Then Set pArea = pFeature.Shape MsgBox +Polygon:IArea properties. & vbCrLf _ & Ar
35、ea = & pArea.Area & vbCrLf _ & Center.X = & pArea.Centroid.X & vbCrLf _ & Center.Y = & pArea.Centroid.Y & vbCrLf _ & pArea.LabelPoint.X & vbCrLf _ & LabelPoint.Y = & pArea.LabelPoint.Y pArea.QueryCentroid pCenter pArea.QueryLabelPoint pLabel MsgBox +Polygon:IArea Queries. & vbCrLf _ & Center = & pCe
36、nter.X & , & pCenter.Y & vbCrLf _ & Label = & pLabel.X & , & pLabel.Y & vbCrLf End If Set pFeature = pEnumFeat.Next WendEnd SubIArea接口的第一个属性Area(只读,返回一个double类型的数值,为此Area的面积)IArea接口的第二个属性Centroid(只读,返回一个IPoint类型的变量,为此Area的重心)IArea接口的第三个属性LablePoint(只读,返回一个IPoint类型的变量,为此Area的标签的位置,一般都在此Area的内部)IArea接
37、口的第四个方法QueryCentroid (Center ) (方法,Center参数为一个IPoint类型的变量,通过调用此方法将重心点赋值给参数Center)IArea接口的第五个方法QueryLablePoint (LablePoint ) (方法,LablePoint参数为设置IPoint类型的变量,通过调用此方法将标签点赋值给参数LablePoint)10. 关于IEnvelope接口(esriGeometry)应用:(中心放大)Public Sub ZoomInCenter()Dim pMxDocument As IMxDocumentDim pActiveView As IAct
38、iveViewDim pDisplayTransform As IDisplayTransformationDim pEnvelope As IEnvelopeDim pCenterPoint As IPointSet pMxDocument = Application.DocumentSet pActiveView = pMxDocument.FocusMapSet pDisplayTransform = pActiveView.ScreenDisplay.DisplayTransformationSet pEnvelope = pDisplayTransform.VisibleBounds
39、In this case, we could have set pEnvelope to IActiveView:ExtentSet pEnvelope = pActiveView.ExtentSet pCenterPoint = New PointpCenterPoint.x = (pEnvelope.XMax - pEnvelope.XMin) / 2) + pEnvelope.XMinpCenterPoint.y = (pEnvelope.YMax - pEnvelope.YMin) / 2) + pEnvelope.YMinpEnvelope.width = pEnvelope.wid
40、th / 2pEnvelope.height = pEnvelope.height / 2pEnvelope.CenterAt pCenterPointpDisplayTransform.VisibleBounds = pEnvelopepActiveView.RefreshEnd SubIEnvelope接口的第一个方法CenterAt(pPoint) (方法,将这个矩形的边框移动到参数pPoint的位置,但是其他属性不变,如它的Width和Height)例子代码: The example shows how to move an Envelope to a new center point
41、 (pPoint). Public Sub t_EnvCenterAt() Dim pEnv1 As IEnvelope Dim pPoint As IPoint Set pEnv1 = New Envelope Set pPoint = New Point pEnv1.PutCoords 100, 100, 200, 200 pPoint.PutCoords 0, 0 pEnv1.CenterAt pPoint Dim dXmin As Double, dYmin As Double, dXmax As Double, dYmax As Double pEnv1.QueryCoords dX
42、min, dYmin, dXmax, dYmax If pEnv1.IsEmpty Then MsgBox envelope is empty Else MsgBox dXmin & , & dYmin & , & dXmax & , &dYmax End If End SubIEnvelope接口的长宽属性Height和Width属性(读写,可以通过该属性获取或设置该边框的长和宽)IEnvelope接口的4个顶点属性UpperLeft、UpperRight、LowerLeft和LowerRight(读写,返回IPoint类型的四个顶点,比直接获得最值坐标更加方便严谨)例子代码:Private Sub Form_Load() Set m_pEnveLope = New Envelope Set m_pCPoint = New Point m_pEnveLope.XMin = 0 m_pEnveLope.YMin = 0 m_pEnveLope.XMax = 0 m_pEnveLope.YMax = 0 m_pCPoint.X = 0 m_pCPoint.Y = 0 Set m_pLowerLeft = New Point Set m_pLowerRight = New Point Set m_pUpperLeft =