roger1984
路人甲
路人甲
  • 注册日期2005-07-26
  • 发帖数21
  • QQ
  • 铜币213枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1688回复:5

求助!关于怎样设置缓冲区???

楼主#
更多 发布于:2006-05-05 12:57
<P>怎样设置缓冲区,用代码来实现,请高手指点指点,多谢!!!</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2006-05-09 17:22
<DIV><B>Description:</B><BR><BR><TEXT>This sample buffers each selected feature in the focus map and stores the results as polygon graphic elements in the map's basic graphics layer. </TEXT>
<TABLE bgColor=#edf6fd>

<TR>
<TD><B>Products:</B>
<DIV 15px; POSITION: relative">
<P>ArcView: VBA</P></DIV>
<P>
<P><B>Platforms:</B> Windows
<P><B>Minimum ArcGIS Release:</B> 9.0 </P></TD></TR></TABLE><BR><B>How to use:</B>
<DIV>
<OL>
<LI>Paste the code into VBA.
<LI>Load one or more feature layers.
<LI>Select some features.
<LI>From the Macros dialog, run the BufferFeatures macro.</LI></OL></DIV><BR>
<DIV><PRE><CODE><FONT color=#0000ff>Public Sub</FONT></CODE> BufferFeatures()
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pMxDoc <CODE><FONT color=#0000ff>As</FONT></CODE> IMxDocument
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pActiveView <CODE><FONT color=#0000ff>As</FONT></CODE> IActiveView
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pGraphicsContainer <CODE><FONT color=#0000ff>As</FONT></CODE> IGraphicsContainer
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pEnumFeature <CODE><FONT color=#0000ff>As</FONT></CODE> IEnumFeature
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pFeature <CODE><FONT color=#0000ff>As</FONT></CODE> IFeature
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pTopoOp <CODE><FONT color=#0000ff>As</FONT></CODE> ITopologicalOperator
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pElement <CODE><FONT color=#0000ff>As</FONT></CODE> IElement
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> strBufferDistance <CODE><FONT color=#0000ff>As String

  Set</FONT></CODE> pMxDoc = Application.Document
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pActiveView = pMxDoc.FocusMap
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pGraphicsContainer = pMxDoc.FocusMap

  <CODE><FONT color=#008000>'Verify there is a feature selection</FONT></CODE>
  <CODE><FONT color=#0000ff>If</FONT></CODE> pMxDoc.FocusMap.SelectionCount = 0 <CODE><FONT color=#0000ff>Then Exit Sub</FONT></CODE>

  <CODE><FONT color=#008000>'Get a buffer distance from the user</FONT></CODE>
  strBufferDistance = InputBox("Enter Distance:", "Buffer")
  <CODE><FONT color=#0000ff>If</FONT></CODE> strBufferDistance = "" <CODE><FONT color=#0000ff>Or Not</FONT></CODE> IsNumeric(strBufferDistance) <CODE><FONT color=#0000ff>Then Exit Sub</FONT></CODE>

  <CODE><FONT color=#008000>'Buffer all the selected features by the BufferDistance</FONT></CODE>
  <CODE><FONT color=#008000>'and create a new polygon element from each result</FONT></CODE>
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pEnumFeature = pMxDoc.FocusMap.FeatureSelection
  pEnumFeature.Reset
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pFeature = pEnumFeature.Next
  <CODE><FONT color=#0000ff>Do While Not</FONT></CODE> pFeature <CODE><FONT color=#0000ff>Is Nothing
    Set</FONT></CODE> pTopoOp = pFeature.Shape
    <CODE><FONT color=#0000ff>Set</FONT></CODE> pElement = <CODE><FONT color=#0000ff>New</FONT></CODE> PolygonElement
    pElement.Geometry = pTopoOp.Buffer(<CODE><FONT color=#0000ff>CInt</FONT></CODE>(strBufferDistance))
    pGraphicsContainer.AddElement pElement, 0
    <CODE><FONT color=#0000ff>Set</FONT></CODE> pFeature = pEnumFeature.Next
  <CODE><FONT color=#0000ff>Loop</FONT></CODE>

  <CODE><FONT color=#008000>'Redraw the graphics</FONT></CODE>
  pActiveView.PartialRefresh esriViewGraphics, <CODE><FONT color=#0000ff>Nothing</FONT></CODE>, <CODE><FONT color=#0000ff>Nothing
End Sub</FONT></CODE></PRE></DIV></DIV>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
roger1984
路人甲
路人甲
  • 注册日期2005-07-26
  • 发帖数21
  • QQ
  • 铜币213枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-05-12 15:56
但是我执行 pMxDoc.FocusMap.SelectionCount = 0,直接就<FONT color=#0000ff>Exit Sub了,数据不是feature class 的,对于这种情况该怎么办啊?</FONT>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2006-05-12 17:34
<DIV class=quote><B>以下是引用<I>roger1984</I>在2006-5-12 15:56:52的发言:</B><BR>但是我执行 pMxDoc.FocusMap.SelectionCount = 0,直接就<FONT color=#0000ff>Exit Sub了,数据不是feature class 的,对于这种情况该怎么办啊?</FONT></DIV>
<br>请先选择至少一个要素,然后再运行
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
roger1984
路人甲
路人甲
  • 注册日期2005-07-26
  • 发帖数21
  • QQ
  • 铜币213枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-05-12 17:41
我的数据是line 的,怎样用代码来选定?
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
5楼#
发布于:2006-05-15 13:04
<DIV class=quote><B>以下是引用<I>roger1984</I>在2006-5-12 17:41:07的发言:</B><BR>我的数据是line 的,怎样用代码来选定?</DIV>
<P>属性或者空间查找出你要选择的要素,也可以直接选择你要的要素,所用的方法和代码都是不同的
<P>下面是个属性查找的例子,注意修改查找<FONT color=#f70909>条件(红色)</FONT>
<P>
<P><STRONG>How to use:</STRONG>
<DIV>
<OL>
<LI>Paste the code into VBA.
<LI>Modify the default expression if desired.
<LI>Load one or more feature layers.
<LI>From the Macros dialog, run the AttributeQuery macro.
<LI>Create a new query in the query builder and hit apply.</LI></OL></DIV>
<P><BR>
<DIV><PRE><CODE><FONT color=#0000ff>Public Sub</FONT></CODE> AttributeQuery()
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pQueryAttributes <CODE><FONT color=#0000ff>As</FONT></CODE> IQueryAttributes
  <CODE><FONT color=#008000>'Create a new Query Attribute Dialog and set</FONT></CODE>
  <CODE><FONT color=#008000>'some necessary properties before launching it</FONT></CODE>
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pQueryAttributes = <CODE><FONT color=#0000ff>New</FONT></CODE> QueryAttributes
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pQueryAttributes.Application = Application
  pQueryAttributes.SelectFeaturesInLayerOnOK = <CODE><FONT color=#0000ff>True</FONT></CODE>
  <CODE><FONT color=#008000>'Provide a default expression if desired</FONT></CODE>
  pQueryAttributes.Expression = <FONT color=#ff0000>"""NAME"" = 'Halifax'"</FONT>
  <CODE><FONT color=#008000>'Lauch the dialog</FONT></CODE>
  pQueryAttributes.DoModal Application.hWnd
<CODE><FONT color=#0000ff>End Sub</FONT></CODE>

Here is a second approach the doesn<CODE><FONT color=#008000>'t use the 'Select By Attributes' dialog.</FONT></CODE>

<CODE><FONT color=#0000ff>Public Sub</FONT></CODE> SelectMapFeatures()
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pMxDoc <CODE><FONT color=#0000ff>As</FONT></CODE> IMxDocument
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pMap <CODE><FONT color=#0000ff>As</FONT></CODE> IMap
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pActiveView <CODE><FONT color=#0000ff>As</FONT></CODE> IActiveView
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pFeatureLayer <CODE><FONT color=#0000ff>As</FONT></CODE> IFeatureLayer
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pFeatureSelection <CODE><FONT color=#0000ff>As</FONT></CODE> IFeatureSelection
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pQueryFilter <CODE><FONT color=#0000ff>As</FONT></CODE> IQueryFilter
  
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pMxDoc = Application.Document
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pMap = pMxDoc.FocusMap
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pActiveView = pMap
  
  <CODE><FONT color=#008000>'For simplicity sake let's use the first layer in the map</FONT></CODE>
  <CODE><FONT color=#0000ff>If Not TypeOf</FONT></CODE> pMap.Layer(0) <CODE><FONT color=#0000ff>Is</FONT></CODE> IFeatureLayer <CODE><FONT color=#0000ff>Then Exit Sub
  Set</FONT></CODE> pFeatureLayer = pMap.Layer(0)
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pFeatureSelection = pFeatureLayer <CODE><FONT color=#008000>'QI</FONT></CODE>
  
  <CODE><FONT color=#008000>'Create the query filter</FONT></CODE>
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pQueryFilter = <CODE><FONT color=#0000ff>New</FONT></CODE> QueryFilter
  pQueryFilter.WhereClause = "NAME = 'Nova Scotia'"
  
  <CODE><FONT color=#008000>'Invalidate only the selection cache</FONT></CODE>
  <CODE><FONT color=#008000>'Flag the original selection</FONT></CODE>
  pActiveView.PartialRefresh esriViewGeoSelection, <CODE><FONT color=#0000ff>Nothing</FONT></CODE>, <CODE><FONT color=#0000ff>Nothing</FONT></CODE>
  <CODE><FONT color=#008000>'Perform the selection</FONT></CODE>
  pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, <CODE><FONT color=#0000ff>False</FONT></CODE>
  <CODE><FONT color=#008000>'Flag the new selection</FONT></CODE>
  pActiveView.PartialRefresh esriViewGeoSelection, <CODE><FONT color=#0000ff>Nothing</FONT></CODE>, <CODE><FONT color=#0000ff>Nothing
  
End Sub</FONT></CODE>
</PRE></DIV>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部