ArcEngine - 开发接口集
更新时间:2024-03-01 12:17:01 阅读量: 综合文库 文档下载
- arcengine推荐度:
- 相关推荐
关于IField接口(esriGeoDatabase)
2. 关于IFieldEdit接口(esriGeoDatabase) 3. 关于IFields接口(esriGeoDatabase) 4. 关于IPoint接口(esriGeometry) 5. 关于IPointArray接口(esriGeometry) 6. 关于IPointCollection接口(esriGeometry) 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 关于IPolyline接口(esriGeometry) 关于IGeometry接口(esriGeometry) 关于IArea接口(esriGeometry) 关于IEnvelope接口(esriGeometry) 关于IFeature接口(esriGeoDatabase) 关于IRow接口(esriGeoDatabase)
关于IFeatureClass接口(esriGeoDatabase) 关于ITable接口(esriGeoDatabase) 关于IFeatureCursor接口(esriGeoDatabase) 关于IQueryFilter接口(esriGeoDatabase) 关于IFeatureLayer接口(esriCarto) 关于IFeatureSelection接口(esriCarto) 关于IMap接口(esriCarto)
关于IPropertySet接口(esriSystem)
关于IFeatureWorkspace接口(esriGeoDatabase)关于IWorkspaceEdit接口(esriGeoDatabase) 关于IWorkspaceFactory接口(esriGeoDatabase)关于ITopologicalOperator接口(esriGeometry)创建Buffer并选择里面的要素 Merge要素Union要素
怎样从Table中获取具体需求值的Row 怎样ZoomInCenter
怎样读取一个字段内的所有值 怎样编辑更改属性字段的值
31. 怎样将MapControl中的Map复制到PageLayoutControl中 32. 怎样判断是否出于编辑状态 33. 怎样用点创建一个Polygon 34. 怎样运用属性来计算总面积 35. 关于属性域的一些心得 36. 怎样实现翻折Flip方法
37. 38. 39. 40. 41. 42. 43.
关于ITopologicalOperator接口Clip方法的问题 关于ISpatialFilter接口方法的问题(完整函数) 关于更改符号的代码(完整函数) 关于显示属性的代码(完整函数)
关于IFeature变量添加进List
1. 关于IField接口(esriGeoDatabase)
IField接口的第一个属性AliasName(只读,获得字段的别名)
IField接口的第二个方法CheckValue(Value)(方法,对于指定的属性字段,基于字段类型判断参数值是否有效,有效,则返回True,否则返回False) 例子代码: 1. 'Get Field
2. Set pField = pFields.Field(6) 3. bChkField = pField.CheckValue(45.86) 4. If bChkField = True Then
5. 'Add data to selected rows for the field selected. 6. End If
IField接口的其他属性均为只读属性,常用有Name(只读,获得字段的名称) 例子代码:
1. Dim pFields As IFields 2. Dim pField As IField 3. Dim pGeoDef As IGeometryDef 4. Dim pDomain As IDomain 5. Dim i As Long
6. Set pFields = pFeatClass.Fields 7. For i = 0 To pFields.FieldCount - 1 8. Set pField = pFields.Field(i)
9. If pField.Type = esriFieldTypeGeometry Then 10. Set pGeoDef = pField.GeometryDef 11. Else
12. Debug.Print pField.AliasName 13. Debug.Print pField.DefaultValue 14. Set pDomain = pField.Domain 15. Debug.Print pField.Editable 16. Debug.Print pField.IsNullable 17. Debug.Print pField.Length
18. Debug.Print pField.Name 19. Debug.Print pField.Precision 20. Debug.Print pField.Required 21. Debug.Print pField.Scale 22. Debug.Print pField.Type 23. Debug.Print pField.VarType 24. End If 25. 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. IFeatureClass pFC_SCP_PT; 2. editPT = new FieldClass(); 3. editPT.Precision_2 = 8; 4. editPT.Scale_2 = 3; 5. editPT.Name_2 = \
6. editPT.Type_2 = esriFieldType.esriFieldTypeDouble; 3. 关于IFields接口(esriGeoDatabase)
IFields接口的第一个属性Field(Index) (只读,以用于获取具体的字段,返回类型为IField)
IFields接口的第二个属性FieldCount(只读,以用于获取属性的数量) 利用上面两个接口并用索引去依次循环获得每一列的属性pField(Ifield接口) 例子代码: 1. Dim i As Long 2. Dim pField As IField
3. For i = 0 To (pFields.FieldCount - 1) 4. Set pField = pFields.Field(i)
5. Debug.Print pField.Name & \6. Next i
IFields接口的第三个方法FindField(Name)(方法,输入想要查找的属性域字段的名称,如果有,则返回该属性域字段在此Fields的索引,没有则返回-1) 例子代码:
1. Dim i As Integer 2. Dim pFields As IFields 3. Dim pField As IField 4. 'Get Fields
5. Set pFields = pFeatClass.Fields 6. 'Find the field named \7. i = pFields.FindField(\8. 'Set the current field 9. Set pField = pFields.Field(i) 10. 'Delete field from featureclass 11. pFeatClass.DeleteField pField
IFields接口的第四个方法FindFieldByAliasName(Name)(方法,与第三个方法类似,此时输入的为该列属性字段的别名,此方法不经常用) 例子代码:
1. Dim i As Integer 2. Dim pFields As IFields 3. Dim pField As IField 4. 'Get Fields
5. Set pFields = pFeatClass.Fields
6. 'Find the field with the aliasname \7. i = pFields.FindFieldByAliasName(\8. 'Set the current field 9. Set pField = pFields.Field(i) 10. 'Delete field from featureclass 11. pFeatClass.DeleteField pField
4. 关于IPoint接口(esriGeometry)
IPoint接口的第一个方法PutCoords(X,Y)(方法,设置该点的坐标)或者直接调用可以读写的属性X和Y,将坐标赋值给X和Y 例子代码:
1. Dim pPoint As IPoint 2. Set pPoint = New Point 3. pPoint.PutCoords 100, 100
IPoint接口的第二个方法QueryCoords(X,Y) (方法,得到该点的坐标) 例子代码:
1. Dim pPoint as IPoint
2. Dim dX as Double, dY as Double 3. pPoint.QueryCoords dX, dY
IPoint接口的第三个方法ConstrainAngle (constraintAngle, anchor, allowOpposite ) (方法,如果第三个参数allowOpposite为True,则将第二个参数anchor这个点作为一个原点,然后以第一个参数constraintAngle为与x轴的角度,做一条直线,再将调用此参数的点向该直线做垂线并交于一个新点,并将调用此方法的点移动到该点)例子代码: 1. 'Finds the closes point to line from (0,0) with angles 2. 'defined by steps of pi/4 (Note all angles in radians) 3. Dim pApoint As IPoint 4. Dim pNpoint As IPoint 5. Dim pi As Double
6. Dim dAngle As Double 7. Dim i As Long 8.
9. Set pApoint = New Point 10. pi = 4 * Atn(1) 11. dAngle = 0
12. pApoint.PutCoords 0, 0 13.
14. Set pNpoint = New Point 15.
16. For i = 0 To 7
17. pNpoint.PutCoords 1, 0 18. dAngle = i * pi / 4
19. pNpoint.ConstrainAngle dAngle, pApoint, True
20. MsgBox \= \& i & \& vbCrLf & pNpoint.X & \& pNpoint.Y 21. Next i
IPoint接口的第四个方法ConstrainDistance (constraintRadius, anchor ) (方法,以第二个参数anchor这个点为圆心,然后以第一个参数constraintRadius为半径做一个圆,将调用此参数的点移动到该点与圆心做线段交于该圆的交点上)例子代码: 1. Public Sub t_constraindistance() 2. Dim pPoint As IPoint 3. Dim pNPoint As IPoint 4. Dim dRadius As Double 5.
6. Set pPoint = New Point 7. pPoint.PutCoords 0, 0 8.
9. Set pNPoint = New Point 10. pNPoint.PutCoords 2, 2 11. dRadius = 1.4142135623731 12.
13. pNPoint.ConstrainDistance dRadius, pPoint
14. MsgBox \15. End Sub
5. 关于IPointArray接口(esriGeometry)
IPointArray接口的第一个方法Add(p) (方法,向该类型的数组变量添加Point) IPointArray接口的第二个属性Count (只读,获得该数组变量中Point的个数,返回Long类型变量)
IPointArray接口的第三个属性Element(Index) (只读,获得该数组变量中位于参数Index索引位置的点Point,返回一个Point类型的变量)
IPointArray接口的第四个方法Insert (Index, p ) (方法,向索引位置Index插入一个点Point)
IPointArray接口的第五个方法Remove (Index ) (方法,移除索引位置Index的点Point) IPointArray接口的第六个方法RemoveAll (方法,移除所有在此数组中的点)
6. 关于IPointCollection接口(esriGeometry)
IPointCollection接口的第一个方法AddPoint(inPoint [,before] [,after]) (方法,向该类型的点集变量添加Point,第一个参数为添加的Point,第二个第三个参数为可选择的参数,默认添加进点集的末尾)
IPointCollection接口的第二个属性Point(i) (只读,获得该点集变量中第i个位置的Point,返回IPoint类型变量,i从0计算开始)
IPointCollection接口的第三个属性PointCount (只读,获得该点集变量中点的个数,返回Long类型变量,切记,如果一个PointCollection变量是由闭合的Geometry转换而来的话,那么点的个数比节点数多一个,因为是闭合的,所以首位节点是同一个点)
7. 关于IPolyline接口(esriGeometry)
IPolyline接口的第一个属性FromPoint与ToPoint(读写,设置或者读取该点的起始点和终止点,返回都是IPoint类型的变量)
IPolyline接口的第二个方法QueryFromPoint (from )(方法,返回IPoint类型的变量到参数from)
IPolyline接口的第三个方法QueryToPoint (to ) (方法,返回IPoint类型的变量到参数to)
1. Public Sub t_ICurve_QueryPoints() 2. Dim pID As New UID 3. pID = \4. Dim pEditor As IEditor 5. Dim pApp As IApplication 6. Set pApp = MxApplication
7. Set pEditor = pApp.FindExtensionByCLSID(pID) 8.
9. If pEditor.SelectionCount <> 1 Then 10. MsgBox \11. Exit Sub 12. End If 13.
14. Dim pEnumFeat As IEnumFeature 15. Dim pFeature As IFeature 16.
17. Set pEnumFeat = pEditor.EditSelection 18.
19. Dim pCurve As ICurve 20. Dim pPointFrom As IPoint 21. Dim pPointTo As IPoint 22.
23. Set pPointFrom = New Point 24. Set pPointTo = New Point 25.
26. Set pFeature = pEnumFeat.Next 27.
28. While Not pFeature Is Nothing
29. If pFeature.Shape.GeometryType = esriGeometryPolyline Or _ 30. esriGeometryPolyline Or esriGeometryLine Then 31. Set pCurve = pFeature.Shape 32. pCurve.QueryFromPoint pPointFrom
33. pCurve.QueryToPoint pPointTo
34. MsgBox \
35. & \
pPointFrom.Y & vbCrLf _
36. & \(x,y) = \& pPointTo.X & \& pPointTo.Y
& vbCrLf 37. End If
38. Set pFeature = pEnumFeat.Next 39. Wend 40. End Sub
IPolyline接口的第四个方法Generalize (maxAllowableOffset ) (方法,用道格拉斯普克发来简化polyline)
IPolyline接口的第五个方法Weed (maxAllowableOffsetFactor ) (方法,和方法Generalize类似,均为简化polyline的方法,不同的是参数。)
8. 关于IGeometry接口(esriGeometry) 1. Public Sub t_IGeometry_polygon() 2. Dim pID As New UID 3. pID = \4. Dim pEditor As IEditor 5. Dim pApp As IApplication 6. Set pApp = Application
7. Set pEditor = pApp.FindExtensionByCLSID(pID) 8.
9. If pEditor.SelectionCount <> 1 Then 10. MsgBox \11. Exit Sub 12. End If 13.
14. Dim pEnumFeat As IEnumFeature
15. Dim pFeature As IFeature 16.
17. Set pEnumFeat = pEditor.EditSelection 18.
19. Dim pGeometry As IGeometry 20.
21. Set pFeature = pEnumFeat.Next 22.
23. While Not pFeature Is Nothing
24. If pFeature.Shape.GeometryType = esriGeometryPolygon Then 25. (通过pFeature.Shape获得Geometry) 26. Set pGeometry = pFeature.Shape
27. MsgBox \28. & \29. & \30. & \= \& pGeometry.Envelope.XMin & \&
pGeometry.Envelope.YMin & \
31. & pGeometry.Envelope.XMax & \
vbCrLf _
32. & \ \
33. & \34. End If
35. Set pFeature = pEnumFeat.Next 36. Wend 37. End Sub
IGeometry接口的第一个属性Dimension(只读,返回一个类型为esriGeometryDimension的该图形的几何维度)
-1 esriGeometryNoDimension 1 esriGeometry0Dimension 2 esriGeometry1Dimension 4 esriGeometry2Dimension
5 esriGeometry25Dimension 6 esriGeometry3Dimension
IGeometry接口的第二个属性Extent(只读,返回一个类型为IEnvelope的该图形的几何范围的最大边框)
IGeometry接口的第三个属性GeometryType(只读,返回一个类型为esriGeometryType的该图形的几何类型)
esriGeometryNull = 0 esriGeometryPoint = 1 esriGeometryMultipoint = 2 esriGeometryPolyline = 3 esriGeometryPolygon = 4 esriGeometryEnvelope = 5 esriGeometryPath = 6 esriGeometryAny = 7 esriGeometryMultiPatch = 9 esriGeometryRing = 11 esriGeometryLine = 13 esriGeometryCircularArc = 14 esriGeometryBezier3Curve = 15 esriGeometryEllipticArc = 16 esriGeometryBag = 17 esriGeometryTriangleStrip = 18 esriGeometryTriangleFan = 19 esriGeometryRay = 20 esriGeometrySphere = 21
9. 关于IArea接口(esriGeometry) 1. Public Sub t_IArea_polygon() 2. Dim pID As New UID
3. pID = \4. Dim pEditor As IEditor 5. Dim pApp As IApplication 6. Set pApp = Application
7. Set pEditor = pApp.FindExtensionByCLSID(pID) 8. If pEditor.SelectionCount <> 1 Then 9. MsgBox \10. Exit Sub 11. End If 12.
13. Dim pEnumFeat As IEnumFeature 14. Dim pFeature As IFeature 15. Dim i As Long 16.
17. Set pEnumFeat = pEditor.EditSelection 18.
19. Dim pArea As IArea 20. Dim pCenter As IPoint 21. Dim pLabel As IPoint 22. Set pCenter = New Point 23. Set pLabel = New Point 24.
25. Set pFeature = pEnumFeat.Next 26.
27. While Not pFeature Is Nothing
28. If pFeature.Shape.GeometryType = esriGeometryPolygon Then 29. Set pArea = pFeature.Shape
30. MsgBox \31. & \
32. & \33. & \34. & pArea.LabelPoint.X & vbCrLf _
35. & \36.
37. pArea.QueryCentroid pCenter 38. pArea.QueryLabelPoint pLabel
39. MsgBox \40. & \41. & \42. End If
43. Set pFeature = pEnumFeat.Next 44. Wend 45. End Sub
IArea接口的第一个属性Area(只读,返回一个double类型的数值,为此Area的面积) IArea接口的第二个属性Centroid(只读,返回一个IPoint类型的变量,为此Area的重心) IArea接口的第三个属性LablePoint(只读,返回一个IPoint类型的变量,为此Area的标签的位置,一般都在此Area的内部)
IArea接口的第四个方法QueryCentroid (Center ) (方法,Center参数为一个IPoint类型的变量,通过调用此方法将重心点赋值给参数Center)
IArea接口的第五个方法QueryLablePoint (LablePoint ) (方法,LablePoint参数为设置IPoint类型的变量,通过调用此方法将标签点赋值给参数LablePoint)
10. 关于IEnvelope接口(esriGeometry) 应用:(中心放大)
1. Public Sub ZoomInCenter()
2. Dim pMxDocument As IMxDocument 3. Dim pActiveView As IActiveView
4. Dim pDisplayTransform As IDisplayTransformation 5. Dim pEnvelope As IEnvelope 6. Dim pCenterPoint As IPoint 7.
8. Set pMxDocument = Application.Document
9. Set pActiveView = pMxDocument.FocusMap 10. Set
pDisplayTransform
=
pActiveView.ScreenDisplay.DisplayTransformation 11. Set pEnvelope = pDisplayTransform.VisibleBounds
12. 'In this case, we could have set pEnvelope to IActiveView::Extent 13. 'Set pEnvelope = pActiveView.Extent 14. Set pCenterPoint = New Point 15.
16. pCenterPoint.x = ((pEnvelope.XMax - pEnvelope.XMin) / 2) + pEnvelope.XMin 17. pCenterPoint.y = ((pEnvelope.YMax - pEnvelope.YMin) / 2) + pEnvelope.YMin 18. pEnvelope.width = pEnvelope.width / 2 19. pEnvelope.height = pEnvelope.height / 2 20. pEnvelope.CenterAt pCenterPoint
21. pDisplayTransform.VisibleBounds = pEnvelope 22. pActiveView.Refresh 23. End Sub
IEnvelope接口的第一个方法CenterAt(pPoint) (方法,将这个矩形的边框移动到参数pPoint的位置,但是其他属性不变,如它的Width和Height) 例子代码:
1. ' The example shows how to move an Envelope to a new 2. ' center point (pPoint). 3. Public Sub t_EnvCenterAt() 4. Dim pEnv1 As IEnvelope 5. Dim pPoint As IPoint 6.
7. Set pEnv1 = New Envelope 8. Set pPoint = New Point 9.
10. pEnv1.PutCoords 100, 100, 200, 200 11. pPoint.PutCoords 0, 0 12.
13. pEnv1.CenterAt pPoint 14.
15. Dim dXmin As Double, dYmin As Double, dXmax As Double, dYmax As Double 16. pEnv1.QueryCoords dXmin, dYmin, dXmax, dYmax 17.
18. If pEnv1.IsEmpty Then 19. MsgBox \20. Else
21. MsgBox dXmin & \ dYmax 22. End If 23. End Sub
IEnvelope接口的长宽属性Height和Width属性(读写,可以通过该属性获取或设置该边框的长和宽)
IEnvelope接口的4个顶点属性UpperLeft、UpperRight、LowerLeft和LowerRight(读写,返回IPoint类型的四个顶点,比直接获得最值坐标更加方便严谨) 例子代码:
1. Private Sub Form_Load()
2. Set m_pEnveLope = New Envelope 3. Set m_pCPoint = New Point 4. m_pEnveLope.XMin = 0 5. m_pEnveLope.YMin = 0 6. m_pEnveLope.XMax = 0 7. m_pEnveLope.YMax = 0 8. m_pCPoint.X = 0 9. m_pCPoint.Y = 0
10. Set m_pLowerLeft = New Point 11. Set m_pLowerRight = New Point 12. Set m_pUpperLeft = New Point 13. Set m_pUpperRight = New Point 14. update_props 15. End Sub
16.
17. Private Sub update_props()
18. Set m_pLowerLeft = m_pEnveLope.LowerLeft 19. edtLlx.Text = m_pLowerLeft.X 20. edtLly.Text = m_pLowerLeft.Y
21. Set m_pLowerRight = m_pEnveLope.LowerRight 22. edtLrx.Text = m_pLowerRight.X 23. edtLry.Text = m_pLowerRight.Y
24. Set m_pUpperLeft = m_pEnveLope.UpperLeft 25. edtUlx.Text = m_pUpperLeft.X 26. edtUly.Text = m_pUpperLeft.Y
27. Set m_pUpperRight = m_pEnveLope.UpperRight 28. edtUrx.Text = m_pUpperRight.X 29. edtUry.Text = m_pUpperRight.Y 30. End Sub
IEnvelope接口的最值坐标属性XMax、XMin、YMax和YMin(读写,可以通过该属性获取或设置该边框的四个顶点的坐标)
IEnvelope接口的第五个方法Union (inEnvelope ) (方法,将参数输入的几何边框和调用该方法的几何边框求并集,并将结果赋值给第一个边框,即调用此方法的object) 例子代码:
1. Public Sub t_EnvUnion() 2. Dim pEnv1 As IEnvelope 3. Dim pEnv2 As IEnvelope 4.
5. Set pEnv1 = New Envelope 6. Set pEnv2 = New Envelope 7.
8. pEnv1.PutCoords 100, 100, 200, 200 9. pEnv2.PutCoords 150, 150, 250, 250 10.
11. pEnv1.Union pEnv2
12.
13. Dim dXmin As Double, dYmin As Double, dXmax As Double, dYmax As Double 14. pEnv1.QueryCoords dXmin, dYmin, dXmax, dYmax 15. End Sub
IEnvelope接口的第六个方法Union (inEnvelope ) (方法,返回与输入参数相交的区域的几何边框,并将结果赋值给第一个边框,即调用此方法的object) 例子代码:
1. ' The example shows how to intersect 2 envelopes. The result is put in 2. ' the first envelope. 3. Public Sub t_EnvIntersect() 4. Dim pEnv1 As IEnvelope 5. Dim pEnv2 As IEnvelope 6.
7. Set pEnv1 = New Envelope 8. Set pEnv2 = New Envelope 9.
10. pEnv1.PutCoords 100, 100, 200, 200 11. pEnv2.PutCoords 150, 150, 250, 250 12.
13. pEnv1.Intersect pEnv2 14.
15. Dim dXmin As Double, dYmin As Double, dXmax As Double, dYmax As Double 16. pEnv1.QueryCoords dXmin, dYmin, dXmax, dYmax 17.
18. If pEnv1.IsEmpty Then
19. MsgBox \20. Else
21. MsgBox dXmin & \22. End If 23. End Sub
IEnvelope接口的第七个方法PutCoords (XMin, YMin,XMax,YMax) (方法,将新建的一个边框的4个极坐标设置为输入的参数) 例子代码:
1. Public Function CreateEnvXY(dblXMin As Double, dblYMin As Double, _ 2. dblXMax As Double, dblYMax As
Double) As IEnvelope
3. Set CreateEnvXY = New esriGeometry.Envelope
4. CreateEnvXY.PutCoords dblXMin, dblYMin, dblXMax, dblYMax 5. End Function
IEnvelope接口的第八个方法QueryCoords (XMin, YMin,XMax,YMax)(方法,将已有的一个边框的4个极坐标输出到参数当中以备后用)
IEnvelope接口的第九个方法Expand (dx, dy, asRatio) (方法,按照输入的dx与dy参数来放大或者缩小当前的边框,用与对ArcMap窗体的中心放大或缩小,或者点击屏幕获得点击点的坐标,并将中心点设置成点击点,并进行一定比例的放大或者缩小) 例子代码:
1. Public Sub t_EnvExpand() 2. Dim pEnv1 As IEnvelope 3. Set pEnv1 = New Envelope
4. pEnv1.PutCoords 100, 100, 200, 200 5.
6. pEnv1.Expand 0.5, 0.5, True 7.
8. Dim dXmin As Double, dYmin As Double, dXmax As Double, dYmax As Double 9. pEnv1.QueryCoords dXmin, dYmin, dXmax, dYmax 10.
11. If pEnv1.IsEmpty Then
12. MsgBox \13. Else
14. MsgBox dXmin & \15. End If 16. End Sub
注意!!!一般情况设置为True,来控制倍数的放大
1. Expand scales the size of the Envelope. If asRatio = FALSE, the expansion
is additive. 2. XMin = XMin - dx 3. YMin = YMin - dy 4. XMax = XMax + dx 5. YMax = YMax + dy
6. If asRatio = TRUE, the expansion is multiplicative. 7. XMin = (XMin - dx*Width)/2 8. YMin = (YMin - dy*Height)/2 9. XMax = (XMax + dx*Width)/2 10. YMax = (YMax + dy*Height)/2
11. The Envelope remains centered at the same position.
IEnvelope接口的第十个方法Offset (X, Y) (方法,将已有的一个边框的按照输入参数的大小来进行水平竖直的移动) 例子代码:
1. Private Sub btnOffset_Click() 2. m_pEnveLope.Offset 10, 20 3. update_props 4. End Sub 5. 注意!!!
6. The new position of the Envelope is as follows: 7. new XMin= old XMin + X 8. new YMin = old YMin + Y 9. new XMax = old XMax + X 10. new YMax = old YMax + Y
11. 关于IFeature接口(esriGeoDatabase) IFeature接口的第一个属性Class(只读)
IFeature接口的第二个方法Delete(方法,删除该行。因为一个Feature在表格中对应的
就是一行数据,删除该行就能相应的删除这个Feature)
IFeature接口的第三个属性Extent(只读,获取该Feature要素在地图上的一个矩形范围,返回值为IEnvelope类型)
IFeature接口的第四个属性FeatureType(只读,获取该Feature要素的要素类型,返回值为枚举类型的esriFeatureType)
IFeature接口的第五个属性Fields(只读,获取该Feature要素的字段集合,返回值为IFields类型)
IFeature接口的第六个属性Shape(读写,获取该Feature要素的图形,返回值为IGeometry类型,或者各种实体化的类型,如IPolyline)
IFeature接口的第七个属性ShapeCopy(只读,克隆该Feature要素的几何图形,返回值为IGeometry类型)
IFeature 接口的第八个方法Store(方法,保存该行。) 此属性可用于对Feature要素的几何图形进行操作,步骤如下:
用IFeature.ShapeCopy方法获取一个已经存在的Geometry,或者新建一个Geometry 对Geometry进行操作
通过IFeature.Shape属性将Geometry写入 通过IFeature.Store方法保存该Feature要素 例子代码:
1. Dim pFeature As IFeature 2. Dim pGeo As IGeometry 3. Set pGeo = pFeature.ShapeCopy 4. 'Change the shape 5. pFeature.Shape = pGeo 6. pFeature.Store
IFeature接口的第九个属性Value(读写,利用字段的索引进行对该要素该字段的值的读写) 注意,索引Index是从0开始的。 object.Value(Index ) = [ value ]
IFeature 接口的第十个属性Table(只读,将该行要素转换成ITable格式的数据,即可对一张表进行数据操作,具体方法查看ITable接口) 例子代码:
1. Dim pTable As ITable 2. Set pTable = pRow.Table
12. 关于IRow接口(esriGeoDatabase)
IRow接口的第一个方法Delete(方法,删除该行)
IRow接口的第二个属性Fields(只读,获取该Feature要素的字段集合,返回值为IFields类型)此方法类似于IFeature接口的Fields属性
IRow 接口的第三个方法Store(方法,保存该行。)此方法类似于IFeature接口的Store方法
IRow接口的第四个属性Table(只读,获取该行所在的表格,返回值为ITable类型) 例子代码:
1. Dim pTable As ITable 2. Set pTable = pRow.Table
IRow接口的第五个属性Value(Index) (读写,获取该行在参数索引的字段的值,注意,索引Index是从0开始的。) object.Value(Index ) = [ value ]
IRow接口的第六个属性HasOID(只读,判断指出该行是否有OID) IRow接口的第七个属性OID(只读,获取该行的OID值) 例子代码:
1. If pRow.HasOID Then 2. Debug.Print pRow.OID 3. End If
13. 关于IFeatureClass接口(esriGeoDatabase) 1. Dim pFeatcls As IFeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As IMap 5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0)
9. Set pFeatcls = pFeatLayer.FeatureClass
IFeatureClass接口的第一个方法AddField(Field) (方法,增加一个属性字段到这个要素类,其中传入的参数为一个IField接口的变量,此变量可以由其他要素类获得并赋值给要操作的要素类,可用IFeilds接口的Field属性来获得)
IFeatureClass接口的第二个方法DeleteField(Field) (方法,删除一个属性字段,其中传入的参数为一个IField接口的变量)
IFeatureClass接口的第三个属性Fields(只读,获取该要素类的全部属性字段,返回一个IFields类型的变量) 例子代码:
1. 'Assume we have a reference to a feature class, pFC 2. Dim pFields As IFields 3. Dim pField As IField 4. Set pFields = pFC.Fields
5. Set pField = pFields.Field(pFields.FindField(\6.
7. pFC.DeleteField pField
IFeatureClass接口的第四个方法FindField(Name) (方法,去查找在该要素类里面是否含有参数名字的属性字段,如果有,则返回索引,没有,则返回-1)
IFeatureClass接口的第五个属性AreaField(只读,获取属性字段为geometry的那一个Field) 例子代码:
1. Dim pFeatcls As IfeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As Imap 5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0)
9. Set pFeatcls = pFeatLayer.FeatureClass 10. Dim pFld As IField
11. Set pFld = pFeatcls.AreaField 12.
13. If Not pFld Is Nothing Then 14. MsgBox pFld.Name 15. End If
IFeatureClass接口的第六个方法Search (filter, Recycling) (方法,去得到一个IFeatureCursor类型的游标,该游标由filter来控制赛选,如果filter等于null,则返回整个featureclass的游标,再用IfeatureCursor的NextFeature的方法依次得到每一个Feature) 例子代码:
1. Dim pFeatcls As IFeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As IMap 5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0) 9. Set pFeatcls = pFeatLayer.FeatureClass 10.
11. ' +++ create the query filter, and give 12. ' +++ it a where clause 13. Dim pQFilt As IQueryFilter 14. Dim pFeatCur As IFeatureCursor 15.
16. Set pQFilt = New QueryFilter
17. pQFilt.WhereClause = \18. Set pFeatCur = pFeatcls.Search(pQFilt, False) 19.
20. ' +++ get the area field 21. Dim pFlds As IFields
22. Dim pFld As IField 23. Dim lAIndex As Long 24.
25. Set pFlds = pFeatcls.Fields 26. lAIndex = pFlds.FindField (\27. Set pFld = pFlds.Field(lAIndex) 28.
29. ' +++ a variable to hold the total area 30. Dim dtotArea As Double 31. dtotArea = 0# 32.
33. ' +++ loop through all of the features and 34. ' +++ calculate the sum of all of the areas 35. Dim pFeat As IFeature
36. Set pFeat = pFeatCur.NextFeature 37. Do
38. dtotArea = dtotArea + pFeat.Value(lAIndex) 39. Set pFeat = pFeatCur.NextFeature 40. Loop Until pFeat Is Nothing 41.
42. ' +++ send the total area to a message box 43. MsgBox dtotArea
IFeatureClass接口的第七个方法Insert(useBuffering) (方法,去得到一个IFeatureCursor类型的游标,来用作插入新的Features,useBuffering是一个布尔型参数,当为True时即可以插入新的Feature,再用IFeatureCursor的InsertFeature (buffer )的方法去插入一个新的Feature) 例子代码:
1. Dim pFeatcls As IFeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As Imap
5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0) 9. Set pFeatcls = pFeatLayer.FeatureClass 10.
11. Dim pFeatCur As IFeatureCursor 12. Dim pFeatBuf As IFeatureBuffer 13. Dim v As Variant 14.
15. Set pFeatCur = pFeatcls.Insert(True) 16. Set pFeatBuf = pFeatcls.CreateFeatureBuffer 17. v = pFeatCur.InsertFeature(pFeatBuf)
IFeatureClass接口的第八个方法CreateFeatureBuffer(方法,新建一个缓冲,返回一个IFeatureBuffer类型的变量,然后再对这个变量进行操作) 例子代码:
1. Dim pFeatcls As IFeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As IMap 5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0) 9. Set pFeatcls = pFeatLayer.FeatureClass 10.
11. 'create a feature cursor and feature buffer interface 12. Dim pFeatCur As IFeatureCursor 13. Dim pFeatBuf As IFeatureBuffer 14.
15. 'open the feature cursor and feature buffer
16. Set pFeatCur = pFeatcls.Insert(True) 17. Set pFeatBuf = pFeatcls.CreateFeatureBuffer 18.
19. 'get the list of fields 20. Dim pFlds As IFields 21. Dim pFld As IField 22. Dim i As Long
23. Dim pPolygon As IPolygon 24. Dim pPolyline As IPolyline 25. Dim pPt As IPoint 26.
27. Set pPolygon = New Polygon 28. Set pPolyline = New Polyline 29. Set pPt = New Point 30.
31. 'find the geometry field, based on the shape type, 32. 'set the value for the field to the appropriate object 33. Set pFlds = pFeatcls.Fields 34. For i = 1 To pFlds.FieldCount - 1 35. Set pFld = pFlds.Field(i)
36. If (pFld.Type = esriFieldTypeGeometry) Then 37. Dim pGeom As IGeometry
38. Select Case pFeatcls.ShapeType 39. Case esriGeometryPolygon 40. Set pGeom = pPolygon 41. Case esriGeometryPolyline 42. Set pGeom = pPolyline 43. Case esriGeometryPoint 44. Set pGeom = pPt 45. End Select 46.
47. 'set the value in the feature buffer
48. pFeatBuf.Value(i) = pGeom 49.
50. 'if it is not a geometry column, determine what kind of 51. 'field it is, and insert the equivalent of a null value 52. 'for that field type 53. Else
54. If pFld.Type = esriFieldTypeInteger Then 55. pFeatBuf.Value(i) = CLng(0)
56. ElseIf pFld.Type = esriFieldTypeDouble Then 57. pFeatBuf.Value(i) = CDbl(0)
58. ElseIf pFld.Type = esriFieldTypeSmallInteger Then 59. pFeatBuf.Value(i) = CInt(0)
60. ElseIf pFld.Type = esriFieldTypeString Then 61. pFeatBuf.Value(i) = \62. Else
63. MsgBox \64. End If 65. End If 66. Next i 67.
68. 'insert the feature from the buffer into the database 69. pFeatCur.InsertFeature pFeatBuf
14. 关于ITable接口(esriGeoDatabase)
ITable是把要素类当成一个表格来看,每一列对应一个字段(Field),每一行对应一个要素(Feature),所以对要素类(Ifeatureclass)接口的操作均可以类似的在Itable接口中找到。
两个接口可以进行如下强制转化: VB语言
1. Dim pFC As IFeatureClass 2. Dim pTable As ITable
3.
4. Set pTable = pFC C#语言
1. IFeatureClass pFC; 2. ITable pTable; 3. pTable = (ITable)pFC;
ITable接口的第一个方法AddField(Field) (方法,增加一个属性字段到这个表,其中传入的参数为一个IField接口的变量,此变量可以由其他表获得并赋值给要操作的表,可用IFeilds接口的Field属性来获得)
ITable接口的第二个方法GetRow(OID) (方法,通过OID来从表格数据库中获取一行,返回一个IRow接口的变量)此方法类似于IFeatureClass接口的GetFeature方法 例子代码:
1. Dim pWorkspace As IWorkspace 2. Dim pFact As IWorkspaceFactory 3.
4. ' This example uses an SDE connection. This code works the 5. ' same for any open IWorkspace. 6.
7. Dim pPropset As IPropertySet 8. Set pPropset = New PropertySet 9. With pPropset
10. .SetProperty \11. .SetProperty \12. .SetProperty \13. .SetProperty \14. .SetProperty \15. .SetProperty \16. End With
17. Set pFact = New SdeWorkspaceFactory
18. Set pWorkspace = pFact.Open(pPropset, Me.hWnd)
19. Dim pFeatureWorkspace As IFeatureWorkspace 20. Set pFeatureWorkspace = pWorkspace 21.
22. Dim pTable As ITable
23. Set pTable = pFeatureWorkspace.OpenTable(\24. Dim pRow As IRow
25. Set pRow = pTable.GetRow(59) 26. Debug.Print pRow.Value(2)
ITable接口的第三个方法GetRows(oids, Recycling) (方法,得到一个游标ICursor,通过一个oids的OID数组参数和一个Recycling的布尔类型的参数,一般为True)此方法类似于IFeatureClass接口的GetFeatures方法 例子代码:
1. Dim iOIDList() As Long 2. Dim iOIDListCount As Long 3. iOIDListCount = 5 4.
5. ReDim iOIDList(iOIDListCount) 6. iOIDList(0) = 1 7. iOIDList(1) = 2 8. iOIDList(2) = 3 9. iOIDList(3) = 4 10. iOIDList(4) = 50 11.
12. Dim pCursor As ICursor
13. Set pCursor = pTable.GetRows(iOIDList, True) 14. Dim pRow As IRow
15. Set pRow = pCursor.NextRow 16. While Not pRow Is Nothing 17. Debug.Print pRow.Value(2) 18. Set pRow = pCursor.NextRow 19. Wend
IMap接口的第一个属性Layers (uid, recursive ) (只读,第二个参数为True的时候,该属性获取第一个参数uid指定的Layers,赋值给一个IEnumLayer的变量) 例子代码:
1. Sub GetFeatureLayers()
2. Dim pMxDocument As IMxDocument 3. Dim pMap As IMap
4. Dim pEnumLayer As IEnumLayer 5. Dim pLayer As ILayer 6. Dim pId As New UID 7.
8. Set pMxDocument = Application.Document 9. Set pMap = pMxDocument.FocusMap
10. pId = \11. Set pEnumLayer = pMap.Layers(pId, True) 12. pEnumLayer.Reset
13. Set pLayer = pEnumLayer.Next 14. Do While Not pLayer Is Nothing 15. MsgBox pLayer.Name
16. Set pLayer = pEnumLayer.Next 17. Loop 18. 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) 例子代码:
1. Public Sub AddShapeFile()
2. Dim pWorkspaceFactory As IWorkspaceFactory 3. Dim pFeatureWorkspace As IFeatureWorkspace 4. Dim pFeatureLayer As IFeatureLayer 5. Dim pMxDocument As IMxDocument 6. Dim pMap As IMap 7.
8. Set pWorkspaceFactory = New ShapefileWorkspaceFactory
9. Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(\
0)
10. Set pFeatureLayer = New FeatureLayer 11. Set
pFeatureLayer.FeatureClass
=
pFeatureWorkspace.OpenFeatureClass(\
12. pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName 13. Set pMxDocument = Application.Document 14. Set pMap = pMxDocument.FocusMap
15. pMap.AddLayer pFeatureLayer 'alternatively, we could call AddLayer on
IMXDocument 16. 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从当前的位
置移动到指定的索引位置) 例子代码:
1. Public Sub MoveLayer()
2. Dim pMxDocument As IMxDocument 3. Dim pMap As IMap 4. Dim pLayer As ILayer
5. Set pMxDocument = Application.Document 6. Set pMap = pMxDocument.FocusMap 7. Set pLayer = pMxDocument.SelectedLayer 8. pMap.MoveLayer pLayer, pMap.LayerCount - 1 9. End Sub
IMap接口的第十二个方法SelectByShape(Shape, env, justOne) (方法,从Layer中依靠一个图形的范围shape和一个选择的环境env来选择要素,而在所有图层中只从IFeatureLayer的图层中进行选择)
20. 关于IPropertySet接口(esriSystem)
IPropertySet接口的第一个方法SetProperties (names, values ) (方法,设置属性) IPropertySet接口的第二个方法SetProperty (name, value ) (方法,设置属性) 例子代码:
1. Dim pPropset As IPropertySet 2. Set pPropset = New PropertySet 3. With pPropset
4. .SetProperty \5. .SetProperty \6. .SetProperty \7. .SetProperty \8. .SetProperty \9. .SetProperty \10. End With 11.
12. Dim pFactSDE As IWorkspaceFactory 13. Set pFactSDE = New SdeWorkspaceFactory 14.
15. Dim pWorkSpaceSDE As IWorkspace
16. Set pWorkSpaceSDE = pFactSDE.Open(pPropset, Me.hWnd) 17.
18. 'Example of how to use a property set to open a Personal Geodatabase workspace. 19.
20. Dim pPropset As IPropertySet 21. Set pPropset = New PropertySet 22.
23. pPropset.SetProperty \24.
25. Dim pFactAccess As IWorkspaceFactory 26. Set pFactAccess = New AccessWorkspaceFactory 27.
28. Dim pWorkSpaceAccess As IWorkspace
29. Set pWorkSpaceAccess = pFactAccess.Open(pPropset, Me.hWnd)
21. 关于IWorkspaceEdit接口(esriGeoDatabase) 例子代码:
1. Public Sub WorkspaceEdit()
2. Dim pWorkspaceFactory As IWorkspaceFactory
3. Set pWorkspaceFactory = New esriDataSourcesGDB.AccessWorkspaceFactory 4. Dim pFeatureWorkspace As IFeatureWorkspace
5. Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(\0) 6. Dim pFeatureClass As IFeatureClass
7. Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass(\8. Dim pWorkspaceEdit As IWorkspaceEdit 9. Set pWorkspaceEdit = pFeatureWorkspace 10. Dim pFeature As IFeature
11. Dim iResponse As Integer 12. Dim bHasEdits As Boolean 13. pWorkspaceEdit.StartEditing True 14. pWorkspaceEdit.StartEditOperation
15. Set pFeature = pFeatureClass.GetFeature(1) 16. pFeature.Delete
17. pWorkspaceEdit.StopEditOperation
18. iResponse = MsgBox(\19. If iResponse = vbYes Then
20. pWorkspaceEdit.UndoEditOperation 21. End If
22. pWorkspaceEdit.HasEdits bHasEdits 23. If bHasEdits Then
24. pWorkspaceEdit.StopEditing MsgBox(\25. End If 26. End Sub
在实际问题中,如果有多次操作需要更改Feature的时候,切记要将操作对象重新赋值,不然在pWorkspaceEdit.StopEditing(true)的时候会出现错误,报错代码为-2147467259。 (详细代码可见WindowsApplication6的代码,其中详细操作了对字段的编辑过程,其中涉及到很多对字段Field的方法Add(Field),Delete(Field),get_value(object value),set_value(int index, object value)等等操作,其中还涉及到Feature经过ICursor类选取与经过FeatureClass类的方法GetFeature选取的区别)
22. 关于IWorkspaceFactory接口(esriGeoDatabase)
IWorkspaceFactory接口的第一个方法Open (ConnectionProperties, hWnd ) (方法,从一个工作工厂打开一个工作空间,并返回IWorkspace类型的变量,方法中的第一个参数ConnectionProperties是IPropertySet接口的变量) 例子代码:
1. Dim pSdeWorkspaceFactory As IWorkspaceFactory 2. Dim pSdeWorkspace As IWorkspace
3. Dim pConnectionProperties As IPropertySet 4.
5. Set pConnectionProperties = New PropertySet 6. With pConnectionProperties
7. .SetProperty \8. .SetProperty \9. .SetProperty \10. .SetProperty \11. .SetProperty \12. End With 13.
14. Set pSdeWorkspaceFactory = New SdeWorkspaceFactory
15. Set pSdeWorkspace = pSdeWorkspaceFactory.Open(pConnectionProperties, 0) IWorkspaceFactory接口的第二个方法OpenFromFile (fileName, hWnd ) (方法,从一个路径打开一个工作空间,并返回IWorkspace类型的变量) 例子代码:
1. Dim pSdeWorkspaceFactory As IWorkspaceFactory 2. Dim pSdeWorkspace As IWorkspace 3.
4. Set pSdeWorkspaceFactory = New SdeWorkspaceFactory 5. Set
pSdeWorkspace
=
pSdeWorkspaceFactory.OpenFromFile(\
23. 关于ITopologicalOperator接口(esriGeometry) 例子代码:
1. Share a line segment
2. This sample uses ITopologicalOperator::Intersect to do the equivalent of a
select by location with the share a line segment operator. 3. Public Sub ShareLineSegment() 4.
5. Dim pMxDoc As IMxDocument 6. Set pMxDoc = ThisDocument 7. Dim pMap As IMap
8. Set pMap = pMxDoc.FocusMap
9. Dim pFL1 As IFeatureLayer, pFL2 As IFeatureLayer 10. Set pFL1 = pMap.Layer(0) ' first layer of map 11. Set pFL2 = pMap.Layer(1) ' second layer 12. Dim pF1 As IFeature, pF2 As IFeature
13. Set pF1 = pFL1.FeatureClass.GetFeature(1) ' get feature with ID=1 in first
layer's feature class 14.
15. Dim pfs As IFeatureSelection 16. Set pfs = pFL2 17. Dim id As Long
18. id = pfs.SelectionSet.IDs.Next ' get first id in selection set an
actual function would probably loop over the selection 19.
20. Set pF2 = pFL2.FeatureClass.GetFeature(id) ' this is line 2 21.
22. 'is there an intersection bw the two features 23. Dim pTopo As ITopologicalOperator
24. Set pTopo = pF1.Shape ' store the line 1 shape in the topo op 25. If Not pTopo.IsSimple Then pTopo.Simplify 26. Dim pGeom As IGeometry
27. Set pGeom = pTopo.Intersect(pF2.Shape, esriGeometry1Dimension) ' get
intersection with line 2 28. If pGeom.IsEmpty Then
29. MsgBox \
points\30. Exit Sub 31. End If
32. ' pGeom now contains the intersection of pf1 and pf2
33. ' because dimension = esriGeometry1Dimension 34. ' it is a geometry of type polyline
35. ' if the intersection of the two features consisted of a point or points pgeom
would be empty
36. ' we could use ITopologicalOperator::Intersect with 0 dimension to find about
those points 37.
38. 'if pGeom contains only two vertices then the intersection is a simple line
segment
39. '3 vertices means it's a polyline with two successive segments
40. '>3 means we have several segments or a polyline or a combination of these 41. Dim ppc1 As IPointCollection 42. Set ppc1 = pGeom 43. Dim l As Long, g As Long 44. l = ppc1.PointCount 45. If l = 2 Then
46. MsgBox \47. ElseIf l = 3 Then
48. MsgBox \
of 2 segments\49. ElseIf l > 3 Then
50. Dim pGeomColl As IGeometryCollection 51. Set pGeomColl = pGeom 52. g = pGeomColl.GeometryCount
53. MsgBox \
polyline(s)and/or segment(s)\54. End If 55. End Sub
可以讲一个Polygon类型的数据或者Polyline的数据赋值给该接口的变量,如: 1. Set pUnionedPolylines = New Polyline 2. Set pTopOp = pUnionedPolylines
ITopologicalOperator接口的第一个方法ConstructUnion(geometries ) (方法,合并图形的工具,输入的参数是一个IEnumGeometry类型的参数,此方法效率甚高)
ITopologicalOperator接口的第二个方法Cut(cutter, leftGeom, rightGeom) (方法,剪切图形,第一个参数为剪切的线要素,为IPloyline类型,第二个第三个参数均为剪切后的图形,为输出参数)
ITopologicalOperator接口的第三个方法Boundary(方法,获取一个图形的边框,一个Polygon的boundary是一个Polyline类型的要素,一个Polyline的boundary是一个nultipoint类型的要素,一个Point的boundary是为空的)
ITopologicalOperator接口的第四个方法Buffer(distance) (方法,创造一个Polygon的要素来显示缓冲区域,参数为缓冲距离) 例子代码:
1. 'This example demonstrates how to use ITopologicalOperator::Buffer 2. Sub exampleITopologicalOperator_Buffer()
3. Dim ptc As IPointCollection, i As Long, pa As IArea, ptopo As
ITopologicalOperator
4. Dim pt(4) As IPoint, poutPoly As IPolygon 5. Set ptc = New Polygon
6. 'The spatial reference should be set here using IGeometry::SpatialReference
(Code skipped here) 7. For i = 0 To 4
8. Set pt(i) = New Point 9. Next
10. pt(0).PutCoords 0, 0 11. pt(1).PutCoords 0, 10 12. pt(2).PutCoords 10, 10 13. pt(3).PutCoords 10, 0 14. pt(4).PutCoords 0, 0 15. ptc.AddPoints 5, pt(0) 16. Set pa = ptc
17. Debug.Print \18. Set ptopo = ptc
19. Set poutPoly = ptopo.Buffer(1) 'Outside buffer
20. Set pa = poutPoly
21. Debug.Print \22. Set poutPoly = ptopo.Buffer(-1) 'Inside buffer 23. Set pa = poutPoly
24. Debug.Print \25. End Sub
ITopologicalOperator接口的第五个方法Clip (clipperEnvelope ) (方法,输入一个IEnvelope类型的变量,来获取被这个边框剪切的要素,并将切割后的变量返回给调用方法的变量)
ITopologicalOperator
接口的第六个方法
QueryClipped (clipperEnvelope,
clippedGeometry ) (方法,与Clip类似,但是第二个参数为剪切后返回输出的参数,本身不会改变)
ITopologicalOperator接口的第七个方法ConvexHull(方法,构造一个Geometry,大部分为Polygon类型的几何要素,该要素为调用此方法的ITopologicalOperator类型的变量最小的外边框)
ITopologicalOperator接口的第八个方法SymmetricDifference (other ) (方法,并集减去交集的部分,调用次方法的变量为第一个参数,other为第二个参数,最后返回变量到一个Geometry类型的变量,该变量的范围均在两个参数范围内,但不在两个参数相交的部分)
24. 创建Buffer并选择里面的要素
======================================================== 怎样创建buffer:(来源于管网线处理删除冗余节点)
======================================================== 1. Dim pTopOper As ITopologicalOperator 2. Set pTopOper = pfeature.Shape 3. Dim pGeometry As IGeometry 4. Set pGeometry = pTopOper.Buffer(1)
(注意,这个pfeature是在前面定义的pfeature=pFeatureCursor.NextFeature,不用重新定义一个)
======================================================== 怎样在buffer里面选择要素:
======================================================== 1. Dim pSpFilter As ISpatialFilter 2. Set pSpFilter = New SpatialFilter 3.
4. Dim pTopOper As ITopologicalOperator 5. Set pTopOper = pfeature.Shape 6. Dim pGeometry As IGeometry 7. Set pGeometry = pTopOper.Buffer(1) 8.
9. Set pSpFilter.Geometry = pGeometry
10. pSpFilter.SpatialRel = esriSpatialRelContains
11. '(esriSpatialRelContains是ISpatialFilter里面SpatialRel的一种参数
esriSpatialRelEnum,值为8,代表在这个区域内包含的要素) 12. 13. Set m_pSelGW_D = pLyr_D
14. m_pSelGW_D.SelectFeatures pSpFilter, esriSelectionResultNew, False 15. '(m_pSelGW_D是IfeatureSelection类型的变量) 16. pSpFilter.SpatialRel = esriSpatialRelIntersects 17.
18. Set m_pSelGW_X = pLyr
19. m_pSelGW_X.SelectFeatures pSpFilter, esriSelectionResultNew, False
25. Merge要素Union要素
1. Private Sub UnionSelected() 2. Dim pMxDoc As IMxDocument 3. Dim pFtrLyr As IFeatureLayer 4. Dim pFtrCls As IFeatureClass 5. Dim pFtrSel As IFeatureSelection
6. Dim pFtr As IFeature
7. Dim pEnumGeom As IEnumGeometry 8. Dim pEnumGeomBind As IEnumGeometryBind 9. Dim pTopOp As ITopologicalOperator 10. Dim pUnionedPolylines As IPolyline 11.
12. ' Get a ref to the selected polylines in the 1st layer 13. Set pMxDoc = ThisDocument
14. Set pFtrLyr = pMxDoc.FocusMap.Layer(0) 15. Set pFtrSel = pFtrLyr
16. Set pFtrCls = pFtrLyr.FeatureClass 17.
18. ' Create an enumeration of the selected polyines 19. Set pEnumGeom = New EnumFeatureGeometry 20. Set pEnumGeomBind = pEnumGeom
21. pEnumGeomBind.BindGeometrySource Nothing, pFtrSel.SelectionSet 22. pEnumGeom.Reset 23.
24. ' Union the polylines
25. Set pUnionedPolylines = New Polyline 26. Set pTopOp = pUnionedPolylines 27. pTopOp.ConstructUnion pEnumGeom 28.
29. ' Add this new unioned polyline to the featureclass 30. Set pFtr = pFtrCls.CreateFeature 31. Set pFtr.Shape = pUnionedPolylines 32. pFtr.Store 33. 34. End Sub C#语言
1. if (pFC.ShapeType ==
ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) 2. {
3. IEnumGeometry pEnumGeom;
4. IEnumGeometryBind pEnumGeomBind = new EnumFeatureGeometryClass(); 5. IFeatureLayer pLyr = new FeatureLayerClass(); 6. pLyr.FeatureClass = pFC;
7. IFeatureSelection pFeatSel = (IFeatureSelection)pLyr; 8.
9. IQueryFilter pQfliter = new QueryFilterClass(); 10. pQfliter.WhereClause = this.SQLText.Text; 11. 12.
pFeatSel.SelectFeatures(pQfliter,
esriSelectionResultEnum.esriSelectionResultNew, false); 13.
14. pEnumGeomBind.BindGeometrySource(null, pFeatSel.SelectionSet); 15. pEnumGeom = (IEnumGeometry)pEnumGeomBind; 16. ITopologicalOperator pTopo = new PolygonClass(); 17. pTopo.ConstructUnion(pEnumGeom); 18. pGeom = (IGeometry)pTopo; 19. }
20. return pGeom;
26. 怎样从Table中获取具体需求值的Row
1. ITable pTable = (ITable)pFC; 2.
int
index
=
pTable.Fields.FindField(\
3. IQueryFilter pQFilter = new QueryFilterClass(); 4. ICursor pCur;
5. pCur = pTable.Search(pQFilter, false);
6. IRow pRow = new Row(); 7. IRow pAnswerRow = new Row(); 8. pRow = pCur.NextRow(); 9. while (pRow != null) 10. { 11.
string
Value
=
pRow.get_Value(index).ToString();
12. if (Value == \13. {
14. pAnswerRow = pRow; 15. break; 16. }
17. pRow = pCur.NextRow(); 18. }
27. 怎样ZoomInCenter
1. Public Sub ZoomInCenter()
2. Dim pMxDocument As IMxDocument 3. Dim pActiveView As IActiveView
4. Dim pDisplayTransform As IDisplayTransformation 5. Dim pEnvelope As IEnvelope 6. Dim pCenterPoint As IPoint 7.
8. Set pMxDocument = Application.Document 9. Set pActiveView = pMxDocument.FocusMap 10. Set
pDisplayTransform
=
pActiveView.ScreenDisplay.DisplayTransformation 11. Set pEnvelope = pDisplayTransform.VisibleBounds
12. 'In this case, we could have set pEnvelope to IActiveView::Extent 13. 'Set pEnvelope = pActiveView.Extent 14. Set pCenterPoint = New Point
15.
16. pCenterPoint.x = ((pEnvelope.XMax - pEnvelope.XMin) / 2) + pEnvelope.XMin 17. pCenterPoint.y = ((pEnvelope.YMax - pEnvelope.YMin) / 2) + pEnvelope.YMin 18. pEnvelope.width = pEnvelope.width / 2 19. pEnvelope.height = pEnvelope.height / 2 20. pEnvelope.CenterAt pCenterPoint
21. pDisplayTransform.VisibleBounds = pEnvelope 22. pActiveView.Refresh 23. End Sub
28. 怎样读取一个字段内的所有值 1.
IFeatureClass
pFC
=
m_SDEQuery.getFeatureClass();
2. IFeatureCursor pFeaCur = pFC.Search(null, false); 3. IFeature pFeature = pFeaCur.NextFeature(); 4.
int
pFieldIndex
=
pFC.Fields.FindField(this.m_cboQryFld.SelectedItem.Value.ToString()); 5. System.Collections.ArrayList pArr = new
System.Collections.ArrayList();
6. while (pFeature != null) 7. { 8.
string
theFieldValue
=
pFeature.get_Value(pFieldIndex).ToString();
9. if (!pArr.Contains(theFieldValue) &&
(theFieldValue.Trim() != \10. {
11. m_cboQryText.Items.Add(theFieldVa
lue);
12. pArr.Add(theFieldValue); 13. }
14. pFeature = pFeaCur.NextFeature();
正在阅读:
ArcEngine - 开发接口集03-01
小学体育三年级上册教案07-03
2017-2018学年湖北省黄石市第三中学高一上学期期末考试生物试题11-15
53555铸造吊钩的无损检测和验收标准05-28
架空电气线路防火间距03-28
上海交通大学版大学物理学习题答案之8机械波习题思考题10-09
鹿特丹规则管辖权规定评述_兼谈对我国海事司法的影响05-18
自编童话故事作文550字07-11
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- ArcEngine
- 接口
- 开发
- 2007年江苏省会计从业资格考试试卷《财经法规》
- 合肥教育信息网:合肥十中招聘16人
- (目录)中国互联网+数字图书馆行业发展模式分析与投资潜力预测
- 苏教版小学体育二年级下册全册教案表格式1
- 初一年地理地图、经纬网练习题答案
- 大学生学业倦怠问题研究计划书
- 哈工大C语言课程设计
- 第7周周三英语测
- 苏教版译林英语五年级下补充习题听力材料及答案
- 美术加试复习题
- 特种阀门方案
- 高考历史试题-2018年高考历史试题分类汇编 - 世界资本主义经济政
- (2007-2010年)济南中考数学试题及答案
- 财政金融作业2
- 小学语文阅读教学中存在的问题及解决对策
- 北京工商大学翻译硕士考研各科目如何复习
- 2015海南省预防医学总结最新考试题库
- 中国现代文学史复习题(简答论述题2)
- 湖南省衡阳市八中2016届高三上学期第一次月考 化学 Word版含答案
- 词汇结构选择题期末复习