页面载入中....

页面载入中....

公告

页面载入中....

文章

评论

留言

连接

信息

登陆

搜索

2007-10-24 17:20:00
Creating A Custom Layer(VBA)转ESRI

Description:

This sample demonstrates how to create a custom layer. The layer has as its data source, a text file containing a list of comma-delimited XY coordinates of points.

How to use:
  1. Resiter the XYPointLayer.dll on your machine. (请到本站论坛ESRI版“XYPointLayer.dll 下载”帖子中下载)。
  2. Start a new blank ArcMac document.
  3. In the Visual Basic Editor, go to Tools > References. If this sample's dll does not appear in the Available References box, Browse to the dll and add it. Check the box next to the dll's name and dismiss the References dialog.
  4. Copy-paste the following procedure into VBA Make sure you have xyPoints.txt file in the location specified.
    Sub Test_PointLayer()
      Dim pLyr As New XYPointLayer.PointLayer
      pLyr.XYFileName = "c:\arcgis\arcexe83\ArcObjects Developer Kit\Samples\ArcMap\Layers\Custom Layer\xypoints.txt"
      
      Dim pL As ILayer
      Set pL = pLyr
      pL.Name = "MyXYPointLayer"
    
      Dim pDoc As IMxDocument
      Dim pMap As IMap
      Set pDoc = ThisDocument
      Set pMap = pDoc.FocusMap
      pMap.AddLayer pLyr
      pDoc.ActiveView.Refresh
    End Sub
    If you want to create a file with comma-delimited XY coordinates of all the points in your point featureclass, you can use the procedure below.
    Private Sub WriteXYPointsFile()
      Dim pWSFact As IWorkspaceFactory
      Dim pFeatWS As IFeatureWorkspace
      Dim pFeatCls As IFeatureClass
      Dim pFeatCur As IFeatureCursor
      Dim pFeat As IFeature
      Dim pPt As IPoint
      Dim lFreeFile As Long
      Dim sXY As String
      Dim x As Double, y As Double
      
      Set pWSFact = New AccessWorkspaceFactory
      Set pFeatWS = pWSFact.OpenFromFile("E:\data\access\usa\usa.mdb", 0)
      Set pFeatCls = pFeatWS.OpenFeatureClass("Capitals")
      Set pFeatCur = pFeatCls.Search(Nothing, True)
      
      lFreeFile = FreeFile
      Open "C:\Temp\xyPoints.txt" For Output As #lFreeFile
      
      Do
        Set pFeat = pFeatCur.NextFeature
        If Not pFeat Is Nothing Then
          Set pPt = pFeat.Shape
          pPt.QueryCoords x, y
          sXY = CStr(x) + ", " + CStr(y)
          Print #lFreeFile, sXY
        End If
      Loop Until pFeat Is Nothing
      
      Close #lFreeFile
    End Sub
  5. Run the Test_PointLayer macro. You should see the points from your text file displayed in the map. Save your document as "customlayer.mxd". Open this document and see that the layer has been persisted.


  • 标签:创建 图层 
  • 发表评论:

      大名:
      密码: (游客无须输入密码)
      主页:
      标题:
      页面载入中....
    Powered by Oblog.