zhqh
路人甲
路人甲
  • 注册日期2007-06-05
  • 发帖数16
  • QQ
  • 铜币145枚
  • 威望0点
  • 贡献值0点
  • 银元0个
110楼#
发布于:2008-06-23 16:14
<P 0cm 0cm 0pt"><FONT face=宋体>如何将选中的点集转换成Polygon<p></p></FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><FONT face=宋体>本例要实现的功能是根据选中的Points创建一个Polygon,并且保存到Polygon类型的FeatureLayer中,要求被选择的Points最少为3个。 </FONT><BR><FONT face=宋体>●</FONT><FONT face=宋体> </FONT><FONT face=宋体>要点</FONT><FONT face=宋体> <BR>    根据选择的点创建一个Polygon,首先要判断生成的Polygon是否是Simple,这里用到接口ITopologicalOperator2的属性IsSimple。如果不是,则要对做Polygon排序等处理。此外还用到了接口IPointCollection的方法ReplacePoints,进行点的交换。将排好序的点,按顺序创建Segment,运用实例化为Ring的ISegmentCollection接口方法AddSegment增加Segment。实例化为Polygon的IGeometryCollection接口方法AddGeometry增加Ring。这样,通过上面的方法便可以创建Polygon。 </FONT><BR><FONT face=宋体>●程序说明 <p></p></FONT></P>
<P 0cm 0cm 0pt 8.5pt"><FONT face=宋体>根据接口ITopologicalOperator2.IsSimple属性判断Polygon是否Simple。如果返回为False,就对Polygon上的点进行排序等处理,排好序后,找出X方向上值最大和最小的点,由这两点创建一条直线,将所有点分成在直线左边和右边两部分。 </FONT><BR><FONT face=宋体>●代码 </FONT><BR><FONT face=宋体>Public Sub ConvertPointToPolygon() <BR>Dim pMxDoc As IMxDocument <BR>Dim pMap As IMap <BR>Dim pEnumFeature As IEnumFeature <BR>Dim pMultiPoint As IPointCollection <BR>Dim pMultiPointSorted As IPointCollection <BR>Dim pFeature As IFeature <BR>Dim pPointi As IPoint <BR>Dim pTopoOp As ITopologicalOperator2 <BR>Dim pLine As ILine <BR>Dim pGonColl As IPointCollection <BR>Dim pClonei As IClone <BR>Dim ptMin As IPoint <BR>Dim ptMax As IPoint <BR>Dim pBaseLine As ILine <BR>Dim pBaseCurve As ICurve <BR>Dim pOutpoint As IPoint <BR>Dim pMultiRight As IPointCollection <BR>Dim pMultiLeft As IPointCollection <BR>Dim pGonColl2 As IGeometryCollection <BR>Dim pPolygon As IPolygon <BR>Dim pRing As IRing <BR>Dim pFeatureClass As IFeatureClass <BR>Dim pFeatureLayer As IfeatureLayer <BR>Dim pFeature1 As IFeature <BR>Dim pFeatureClass1 As IFeatureClass <BR>Dim pFeatureLayer1 As IFeatureLayer <BR>Dim pDataSet As IDataset <BR>Dim pWorkspaceFactory As IWorkspaceFactory <BR>Dim pWorkspaceEdit As IWorkspaceEdit </FONT></P>
<P 0cm 0cm 0pt 8.5pt"><FONT face=宋体>Dim pRingColl As ISegmentCollection <BR>Dim dDistAlong As Double <BR>Dim dDistFrom As Double <BR>Dim bIsRight As Boolean <BR>Dim i As Long <BR>Dim j As Long <BR>Dim lFlag As Long <BR>On Error GoTo errorHander <BR>Set pMxDoc = ThisDocument <BR>Set pMap = pMxDoc.FocusMap <BR>Set pActiveView = pMap <BR>Set pFeatureLayer = pMap.Layer(0) <BR>Set pFeatureClass = pFeatureLayer.FeatureClass </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>创建一个工作区,开始编辑 </FONT><BR><FONT face=宋体>Set pDataSet = pFeatureClass <BR>Set pWorkspaceFactory = New ShapefileWorkspaceFactory <BR>Set pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0) <BR>pWorkspaceEdit.StartEditOperation <BR>pWorkspaceEdit.StartEditing True </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>Set pMultiLeft = New Multipoint <BR>Set pMultiRight = New Multipoint <BR>Set pGonColl = New Polygon <BR>Set pMultiPoint = New Multipoint <BR>Set pMultiPointSorted = New Multipoint </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>得到所选择的图形集 </FONT><BR><FONT face=宋体>Set pEnumFeature = pMxDoc.FocusMap.FeatureSelection <BR>Set pFeature = pEnumFeature.Next <BR></FONT><FONT face=宋体>'增加点到MultiPoint </FONT><BR><FONT face=宋体>While Not pFeature Is Nothing <BR>If pFeature.ShapeCopy.GeometryType = esriGeometryPoint Then <BR>pMultiPoint.AddPoint pFeature.ShapeCopy <BR>ElseIf pFeature.ShapeCopy.GeometryType = esriGeometryMultipoint Then <BR>pMultiPoint.AddPointCollection pFeature.ShapeCopy <BR>End If <BR>Set pFeature = pEnumFeature.Next <BR>Wend <BR>If pMultiPoint.PointCount < 3 Then <BR>MsgBox "Select a least 3 points !" <BR>Exit Sub </FONT><p></p></P>
<P 0cm 0cm 0pt 8pt"><FONT face=宋体>End If </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>创建第一个Polygon </FONT><BR><FONT face=宋体>pGonColl.AddPointCollection pMultiPoint <BR>Set pTopoOp = pGonColl <BR>'</FONT><FONT face=宋体>将Polygon是否是Simple设置成未知</FONT><FONT face=宋体> <BR>pTopoOp.IsKnownSimple = False </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>经判断,如果不是Simple,则经过以下处理,将其转换为Simple </FONT><BR><FONT face=宋体>If pTopoOp.IsSimple = False and pMultiPoint.PointCount>3 Then <BR>lFlag = 1 <BR>Set pTopoOp = pMultiPoint <BR>pTopoOp.IsKnownSimple = False <BR>pTopoOp.Simplify </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>将Multipoint进行排序 </FONT><BR><FONT face=宋体>For i = 0 To pMultiPoint.PointCount - 1 <BR>For j = i + 1 To pMultiPoint.PointCount - 1 <BR>If pMultiPoint.Point(j).x < pMultiPoint.Point(i).x Or pMultiPoint.Point(j).x = _ </FONT><p></p></P>
<P 0cm 0cm 0pt 27.5pt"><FONT face=宋体>pMultiPoint.Point(i).x And_ pMultiPoint.Point(j).y < <BR>pMultiPoint.Point(i).y Then </FONT><BR><FONT face=宋体>Set pClonei = pMultiPoint.Point(i) <BR>Set pPointi = pClonei.Clone </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>交换两点 </FONT><BR><FONT face=宋体>pMultiPoint.ReplacePoints i, 1, 1, pMultiPoint.Point(j) <BR>pMultiPoint.ReplacePoints j, 1, 1, pPointi <BR>End If <BR>Next </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>Next <BR>Set ptMin = New Point <BR>Set ptMax = New Point </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>找出MultiPoint中的最大和最小点 </FONT><BR><FONT face=宋体>pMultiPoint.QueryPoint 0, ptMin <BR>pMultiPoint.QueryPoint pMultiPoint.PointCount - 1, ptMax </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>创建一条线段 </FONT><BR><FONT face=宋体>Set pBaseLine = New Line </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>pBaseLine.PutCoords ptMin, ptMax <BR>Set pBaseCurve = pBaseLine <BR>For i = 0 To pMultiPoint.PointCount - 1 <BR>Set pOutpoint = New Point <BR>pBaseCurve.QueryPointAndDistance esriNoExtension, pMultiPoint.Point(i), False, <p></p></FONT></P>
<P 0cm 0cm 0pt"><FONT face=宋体>pOutpoint, _ dDistAlong, dDistFrom, bIsRight <BR>If bIsRight Then <BR>pMultiRight.AddPoint pMultiPoint.Point(i) <BR>Else <BR>pMultiLeft.AddPoint pMultiPoint.Point(i) <BR>End If <BR>Next <BR>Set pRingColl = New Ring </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>将左边的线添加到Ring </FONT><BR><FONT face=宋体>For i = 0 To pMultiLeft.PointCount - 2 <BR>Set pLine = New Line <BR>pLine.PutCoords pMultiLeft.Point(i), pMultiLeft.Point(i + 1) <BR>pRingColl.AddSegment pLine <BR>Next </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>第一条线 </FONT><BR><FONT face=宋体>Set pLine = New Line <BR>pLine.PutCoords pMultiLeft.Point(pMultiLeft.PointCount - 1), pMultiRight.Point(0) <BR>pRingColl.AddSegment pLine </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>将右边的先添加到Ring </FONT><BR><FONT face=宋体>For i = (pMultiRight.PointCount - 1) To 1 Step -1 <BR>Set pLine = New Line <BR>pLine.PutCoords pMultiRight.Point(i), pMultiRight.Point(i - 1) <BR>pRingColl.AddSegment pLine <BR>Next </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>最后一条线 </FONT><BR><FONT face=宋体>Set pLine = New Line <BR>pLine.PutCoords pMultiRight.Point(0), pMultiLeft.Point(0) <BR>pRingColl.AddSegment pLine <BR>Set pRing = pRingColl <BR>pRing.Close <BR>Set pGonColl2 = New Polygon <BR>pGonColl2.AddGeometry pRing <BR>End If <BR>If lFlag = 0 Then <BR>Set pPolygon = pGonColl <BR>Else <BR>Set pPolygon = pGonColl2 'QI <BR>End If <BR></FONT><FONT face=宋体>'画出Polygon </FONT><BR><FONT face=宋体>Set pFeatureLayer1 = pMap.Layer(1) <BR>Set pFeatureClass1 = pFeatureLayer1.FeatureClass <BR>Set pFeature1 = pFeatureClass1.CreateFeature </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>把画的Polygon加到新建的Feature上 </FONT><BR><FONT face=宋体>Set pFeature1.Shape = pPolygon </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>保存Feature </FONT><BR><FONT face=宋体>pFeature1.Store <BR>pMxDoc.ActiveView.Refresh </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>停止编辑 </FONT><BR><FONT face=宋体>pWorkspaceEdit.StopEditOperation <BR>pWorkspaceEdit.StopEditing True </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>Exit Sub <BR>ErrorHander: <BR>pWorkspaceEdit.AbortEditOperation <BR>MsgBox Err.Description <BR>End Sub</FONT><FONT face=宋体> <BR><BR line-break"><BR line-break"><p></p></FONT></P>
<P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P>
举报 回复(0) 喜欢(0)     评分
zhqh
路人甲
路人甲
  • 注册日期2007-06-05
  • 发帖数16
  • QQ
  • 铜币145枚
  • 威望0点
  • 贡献值0点
  • 银元0个
111楼#
发布于:2008-06-23 16:20
<P 0cm 0cm 0pt"><FONT face=宋体>如何将Multipoint转换成</FONT><FONT face=宋体>Points <BR>本例要实现的功能是根据一个FeatureLayer中被选择一个或多个</FONT><BR><FONT face=宋体>MultiPoint</FONT><FONT face=宋体>,生成多个Point并把这些新生成的Point保存在一个Point类型的</FONT><BR><FONT face=宋体>Feature Layer</FONT><FONT face=宋体>上。 </FONT><BR><FONT face=宋体>●要点</FONT><FONT face=宋体> <BR>本例将选择的Multipoints上的每个点都生成一个对应得Point,并用一个</FONT><BR><FONT face=宋体>接口IPointCollection的变量来接收。利用IPointCollection的方法</FONT><BR><FONT face=宋体>point(index),</FONT><FONT face=宋体>取出新生成的每个点,用来创建Point类型的Feature。 </FONT><BR><FONT face=宋体>●程序说明 <p></p></FONT></P>
<P 0cm 0cm 0pt 8.5pt"><FONT face=宋体>本例要求在ArcMap中添加两个层,最上面的是层Multipoint,下面是层</FONT><BR><FONT face=宋体>wind</FONT><FONT face=宋体>。根据循环得到选择的每个Multipoint的每个点,为wind层生成新的</FONT><BR><FONT face=宋体>Feature</FONT><FONT face=宋体>并保存 </FONT><BR><FONT face=宋体>●代码 </FONT><BR><FONT face=宋体>Sub convertMultipointToPoints() <BR>Dim pMxDocument As IMxDocument <BR>Dim pMap As IMap <BR>Dim pActiveView As IActiveView <BR>Dim pEnumFeature As IEnumFeature <BR>Dim pFeature0 As IFeature <BR>Dim pFeatureLayer0 As IFeatureLayer <BR>Dim pFeatureClass0 As IFeatureClass <BR>Dim pFeature1 As IFeature <BR>Dim pFeatureLayer1 As IFeatureLayer <BR>Dim pFeatureClass1 As IFeatureClass <BR>Dim pPointCollection As IPointCollection <BR>Dim pDataSet As IDataset <BR>Dim pWorkspaceFactory As IWorkspaceFactory <BR>Dim pWorkspaceEdit As IWorkspaceEdit <BR>Dim lPointIndex As Long <BR>Dim lPointFieldIndex As Long <BR>On Error GoTo ErrorHanlder </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>得到当前层 </FONT><BR><FONT face=宋体>Set pMxDocument = ThisDocument <BR>Set pMap = pMxDocument.FocusMap <BR>Set pActiveView = pMap </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>得到0层和1层的FeatureClass <p></p></FONT></P>
<P 0cm 0cm 0pt"><FONT face=宋体>Set pFeatureLayer0 = pMxDocument.FocusMap.Layer(0) <BR>Set pFeatureClass0 = pFeatureLayer0.FeatureClass <BR>Set pFeatureLayer1 = pMxDocument.FocusMap.Layer(1) <BR>Set pFeatureClass1 = pFeatureLayer1.FeatureClass </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>建立编辑工作区 </FONT><BR><FONT face=宋体>Set pDataSet = pFeatureClass1 <BR>Set pWorkspaceFactory = New ShapefileWorkspaceFactory <BR>Set pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName,0) <BR>pWorkspaceEdit.StartEditOperation <BR>pWorkspaceEdit.StartEditing True </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>得到Feature </FONT><BR><FONT face=宋体>Set pEnumFeature = pMxDocument.FocusMap.FeatureSelection <BR>Set pFeature0 = pEnumFeature.Next <BR>If pFeature0 Is Nothing Then <BR>MsgBox "Must have Select in Position 0" <BR>Exit Sub <BR>End If </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>循环,通过每个MultiPoint,在1图层上,生成以每个点为特征的Points </FONT><BR><FONT face=宋体>While Not pFeature0 Is Nothing <BR>If pFeature0.ShapeCopy.GeometryType = esriGeometryMultipoint Then <BR>Set pPointCollection = pFeature0.ShapeCopy <BR>For nPointIndex = 0 To pPointCollection.PointCount - 1 <BR>Set pFeature1 = pFeatureClass1.CreateFeature </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>在pFeature1上生成Point </FONT><BR><FONT face=宋体>Set pFeature1.Shape = pPointCollection.Point(nPointIndex) </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>如果两Feature的FieldCount相同,赋每个Field的值,ID, <p></p></FONT></P>
<P 0cm 0cm 0pt"><FONT face=宋体>'TypeGeometry的Field除外 </FONT><BR><FONT face=宋体>If pFeature1.Fields.FieldCount = pFeature0.Fields.FieldCount Then <BR>For lPointFieldIndex = 0 To pFeature1.Fields.FieldCount - 1 <BR>If Not pFeature1.Fields.Field(lPointFieldIndex).Type = _ </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>esriFieldTypeGeometry And Not pFeature1.Fields. _ <BR>Field(lPointFieldIndex).Type = esriFieldTypeOID Then <BR>pFeature1.Value(lPointFieldIndex) = _ <p></p></FONT></P>
<P 0cm 0cm 0pt"><FONT face=宋体>pFeature0.Value(lPointFieldIndex) <BR>End If <BR>Next <BR>End If <BR>'保存Feature </FONT><BR><FONT face=宋体>pFeature1.Store <BR>Next <BR>Else <BR>MsgBox "Must have Multipoint in position 0" <BR>Exit Sub <BR>End If <BR>Set pFeature0 = pEnumFeature.Next <BR>Wend </FONT><BR><FONT face=宋体>'</FONT><FONT face=宋体>停止编辑 </FONT><BR><FONT face=宋体>pWorkspaceEdit.StopEditOperation <BR>pWorkspaceEdit.StopEditing True <BR>Exit Sub <BR><BR>ErrorHanlder: <BR>pWorkspaceEdit. AbortEditOperation </FONT><p></p></P>
<P 0cm 0cm 0pt"><FONT face=宋体>MsgBox Err.Description <BR>End Sub <p></p></FONT></P>
举报 回复(0) 喜欢(0)     评分
zhqh
路人甲
路人甲
  • 注册日期2007-06-05
  • 发帖数16
  • QQ
  • 铜币145枚
  • 威望0点
  • 贡献值0点
  • 银元0个
112楼#
发布于:2008-06-23 16:23
<P>我有PDF文件,谁要的话联系我吧。</P>
<P>(不会上传)</P>
<P>QQ:280246507</P>
举报 回复(0) 喜欢(0)     评分
liuwq05
路人甲
路人甲
  • 注册日期2007-02-25
  • 发帖数13
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
113楼#
发布于:2008-08-27 10:17
<P>是相当不错,老大能不能再提供点vb.net开发的东西。</P>
举报 回复(0) 喜欢(0)     评分
zsj1986
外卖仔
外卖仔
  • 注册日期2007-07-11
  • 发帖数42
  • QQ
  • 铜币221枚
  • 威望2点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
114楼#
发布于:2008-09-25 17:17
<img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
JamLau
路人甲
路人甲
  • 注册日期2007-05-16
  • 发帖数14
  • QQ
  • 铜币21枚
  • 威望0点
  • 贡献值0点
  • 银元0个
115楼#
发布于:2008-10-04 15:58
我顶<img src="images/post/smile/dvbbs/em11.gif" /><img src="images/post/smile/dvbbs/em11.gif" />
举报 回复(0) 喜欢(0)     评分
100200y
路人甲
路人甲
  • 注册日期2008-05-19
  • 发帖数26
  • QQ
  • 铜币146枚
  • 威望0点
  • 贡献值0点
  • 银元0个
116楼#
发布于:2008-10-31 15:43
你好历害啊,佩服
举报 回复(0) 喜欢(0)     评分
上一页 下一页
游客

返回顶部