内容发布更新时间 : 2024/12/23 11:10:05星期一 下面是文章的全部内容请认真阅读。
pPoint.PutCoords100,100
IPoint接口的第二个方法QueryCoords(X,Y)(方法,得到该点的坐标)
例子代码: Dim pPoint asIPoint Dim dX asDouble,dYasDouble pPoint.QueryCoordsdX,dY
IPoint接口的第三个方法ConstrainAngle (constraintAngle, anchor, allowOpposite ) (方法,如果第三个参数allowOpposite为True,则将第二个参数anchor这个点作为一个原点,然后以第一个参数 constraintAngle为与x轴的角度,做一条直线,再将调用此参数的点向该直线做垂线并交于一个新点,并将调用此方法的点移动到该点)
例子代码:
'Finds the closespointtolinefrom(0,0)withangles 'defined by stepsofpi/4(Noteallanglesinradians) Dim pApointAsIPoint Dim pNpointAsIPoint Dim piAsDouble Dim dAngleAsDouble Dim iAsLong Set pApoint =NewPoint pi = 4 *Atn(1) dAngle = 0 pApoint.PutCoords 0,0 Set pNpoint =NewPoint For i =0To7
pNpoint.PutCoords 1,0 dAngle = i *pi/4
pNpoint.ConstrainAngle dAngle,pApoint,True
MsgBox\ \ i & \ vbCrLf & pNpoint.X & \ pNpoint.Y Next i
IPoint接口的第四个方法ConstrainDistance(constraintRadius, anchor ) (方法,以第二个参数anchor这个点为圆心,然后以第一个参数constraintRadius为半径做一个圆,将调用此参数的点移动到该点与圆心做线段交于该圆的交点上)
例子代码:
Public Sub t_constraindistance() Dim pPointAsIPoint Dim pNPointAsIPoint Dim dRadiusAsDouble
Set pPoint =NewPoint
pPoint.PutCoords 0,0
Set pNPoint =NewPoint pNPoint.PutCoords 2,2 dRadius = 1.4142135623731
pNPoint.ConstrainDistance dRadius,pPoint
MsgBox \ \ x,y = \ \ pNPoint.Y EndSub
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)
Public Sub t_ICurve_QueryPoints() Dim pIDAsNewUID pID = \ Dim pEditorAsIEditor
Dim pAppAsIApplication Set pApp =MxApplication
Set pEditor =pApp.FindExtensionByCLSID(pID)
If pEditor.SelectionCount<> 1 Then MsgBox\ ExitSub End If
Dim pEnumFeatAsIEnumFeature Dim pFeatureAsIFeature
Set pEnumFeat =pEditor.EditSelection
Dim pCurveAsICurve Dim pPointFromAsIPoint Dim pPointToAsIPoint
Set pPointFrom =NewPoint Set pPointTo =NewPoint
Set pFeature =pEnumFeat.Next
While NotpFeatureIsNothing
IfpFeature.Shape.GeometryType= esriGeometryPolyline Or_ esriGeometryPolyline OresriGeometryLineThen SetpCurve =pFeature.Shape pCurve.QueryFromPoint pPointFrom pCurve.QueryToPoint pPointTo
MsgBox\ vbCrLf _
& \ \ pPointFrom.Y &vbCrLf_ & \ \ pPointTo.Y &vbCrLf EndIf
SetpFeature =pEnumFeat.Next Wend
End Sub
IPolyline接口的第四个方法Generalize (maxAllowableOffset ) (方法,用道格拉斯普克发来简化polyline) IPolyline接口的第五个方法Weed (maxAllowableOffsetFactor ) (方法,和方法Generalize类似,均为简化polyline的方法,不同的是参数。)
8. 关于IGeometry接口(esriGeometry)
Public Sub t_IGeometry_polygon() Dim pIDAsNewUID pID = \ Dim pEditorAsIEditor Dim pAppAsIApplication Set pApp =Application
Set pEditor =pApp.FindExtensionByCLSID(pID)
If pEditor.SelectionCount<> 1Then MsgBox\ ExitSub End If
Dim pEnumFeatAsIEnumFeature Dim pFeatureAsIFeature
Set pEnumFeat =pEditor.EditSelection Dim pGeometryAsIGeometry Set pFeature =pEnumFeat.Next While NotpFeatureIsNothing
IfpFeature.Shape.GeometryType= esriGeometryPolygon Then
(通过pFeature.Shape获得Geometry) SetpGeometry =pFeature.Shape
MsgBox\ properties...\ & \ vbCrLf _ & \ type =\ vbCrLf _
& \ \ \ pGeometry.Envelope.YMin& \ _ & pGeometry.Envelope.XMax &\ pGeometry.Envelope.YMin & vbCrLf_ & \ \ vbCrLf _ & \ EndIf
SetpFeature =pEnumFeat.Next Wend