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:
How to use:
- Resiter the XYPointLayer.dll on your machine. (请到本站论坛ESRI版“XYPointLayer.dll 下载”帖子中下载)。
- Start a new blank ArcMac document.
- 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.
- Copy-paste the following procedure into VBA Make sure you have xyPoints.txt file in the location specified.
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.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 SubPrivate 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 - 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.
