ArcEngine接口大全 下载本文

1. IField接口(esriGeoDatabase)

IField接口的第一个属性AliasName(只读,获得字段的别名)

IField接口的第二个方法CheckValue(Value)(方法,对于指定的属性字段,基于字段类型判断参数值是否有效,有效,则返回True,否则返回False) 例子代码:

1.

2.

Set pField = pFields.Field(6) ’第六个字段 bChkField = pField.CheckValue(45.86)

3. If bChkField = True Then……

IField接口的其他属性均为只读属性,常用有Name(只读,获得字段的名称) 例子代码:

1.

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25.

Dim pFields As IFields Dim pField As IField

Dim pGeoDef As IGeometryDef Dim pDomain As IDomain Dim i As Long

Set pFields = pFeatClass.Fields For i = 0 To pFields.FieldCount - 1 Set pField = pFields.Field(i)

If pField.Type = esriFieldTypeGeometry Then Set pGeoDef = pField.GeometryDef Else

Debug.Print pField.AliasName Debug.Print pField.DefaultValue 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.VarType End If Next

2. IFieldEdit接口(esriGeoDatabase)

所有该接口的属性均为可读可写,经常用与对新建字段的设置,因为字段一旦被设置,其基本属性就不能被更改,所以就需要该接口类型的变量去转换,方法为:

IFeatureClass pFC_SCP_PT;

IFieldEdit editPT = new FieldClass(); pFC_SCP_PT.AddField((IField)editPT);

如果在vb中去编写代码,则赋值和获取均为同一属性,而在C#中,为了区分设置和获取,属性均有两个,类似于Name和Name_2,这样就可以区分了,普遍用设置的带有_2的那个属性。

IFieldEdit接口的第一个属性Name (读写,设置或者获取该变量类型变量字段的名称) IFieldEdit接口的第二个属性Precision(读写,设置或者获取该变量类型变量字段的长度) IFieldEdit接口的第三个属性Scale(读写,设置或者获取该变量类型变量字段的精度) IFieldEdit接口的第四个属性Type(读写,设置或者获取该变量类型变量字段的类型) 例子代码: 1. 2. 3. 4. 5. 6.

3. IFields接口(esriGeoDatabase)

IFields接口的第一个属性Field(Index) (只读,以用于获取具体的字段,返回类型为IField) IFields接口的第二个属性FieldCount(只读,以用于获取属性的数量) 利用上面两个接口并用索引去依次循环获得每一列的属性pField(Ifield接口) 例子代码: 1. 2. 3. 4. 5.

Dim i As Long

Dim pField As IField

For i = 0 To (pFields.FieldCount - 1)

Set pField = pFields.Field(i)

Debug.Print pField.Name & \IFeatureClass pFC_SCP_PT; editPT = new FieldClass(); editPT.Precision_2 = 8; editPT.Scale_2 = 3;

editPT.Name_2 = \

editPT.Type_2 = esriFieldType.esriFieldTypeDouble;

6. Next i

IFields接口的第三个方法FindField(Name)(方法,输入想要查找的属性域字段的名称,如果有,则返回该属性域字段在此Fields的索引,没有则返回-1) 例子代码: 1. 2. 3. 4. 5. 6.

Dim i As Integer Dim pFields As IFields Dim pField As IField 'Get Fields

Set pFields = pFeatClass.Fields

'Find the field named \

7. 8. 9.

i = pFields.FindField(\ 'Set the current field

Set pField = pFields.Field(i)

10. 'Delete field from featureclass 11. pFeatClass.DeleteField pField

IFields接口的第四个方法FindFieldByAliasName(Name)(方法,与第三个方法类似,此时输入的为该列属性字段的别名,此方法不经常用) 例子代码: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

4. 关于IPoint接口(esriGeometry)

IPoint接口的第一个方法PutCoords(X,Y)(方法,设置该点的坐标)或者直接调用可以读写的属性X和Y,将坐标赋值给X和Y 例子代码: 1. 2. 3.

Dim pPoint As IPoint Set pPoint = New Point pPoint.PutCoords 100, 100

Dim i As Integer

Dim pFields As IFields Dim pField As IField 'Get Fields

Set pFields = pFeatClass.Fields

'Find the field with the aliasname \i = pFields.FindFieldByAliasName(\'Set the current field

Set pField = pFields.Field(i) 'Delete field from featureclass pFeatClass.DeleteField pField

IPoint接口的第二个方法QueryCoords(X,Y) (方法,得到该点的坐标) 例子代码: 1. 2. 3.

Dim pPoint as IPoint

Dim dX as Double, dY as Double pPoint.QueryCoords dX, dY

IPoint接口的第三个方法ConstrainAngle (constraintAngle, anchor, allowOpposite ) (方法,如果第三个参数allowOpposite为True,则将第二个参数anchor这个点作为一个原点,然后以第一个参数constraintAngle为与x轴的角度,做一条直线,再将调用此参数的点向该直线做垂线并交于一个新点,并将调用此方法的点移动到该点)

例子代码: 1. 2. 3.

'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

4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21.

Dim pNpoint As IPoint Dim pi As Double Dim dAngle As Double Dim 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 \ Next i

IPoint接口的第四个方法ConstrainDistance (constraintRadius, anchor ) (方法,以第二个参数anchor这个点为圆心,然后以第一个参数constraintRadius为半径做一个圆,将调用此参数的点移动到该点与圆心做线段交于该圆的交点上)

例子代码: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 1.

4. 关于IPointArray接口(esriGeometry)

IPointArray接口的第一个方法Add(p) (方法,向该类型的数组变量添加Point)

IPointArray接口的第二个属性Count (只读,获得该数组变量中Point的个数,返回Long类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 pNPoint.PutCoords 2, 2 dRadius = 1.4142135623731

pNPoint.ConstrainDistance dRadius, pPoint

MsgBox \

2. End Sub