阅读:1907回复:4
大虾们帮看看:实现绘制点并保存。
我自己编制的一段代码,目的是在Map中绘制点并能保存下来。整个过程没有错误提示。但是当我打开保存的点文件发现文件是空的,没有任何记录,望大虾们帮帮忙!!
以下是我的代码: Option Explicit Dim Pts As New MapObjects2.Points Dim ps As New MapObjects2.Points Dim moSymbol As New MapObjects2.Symbol Dim moPoints As New Collection '存储点文件 Private Sub Command1_Click() Dim gds As MapObjects2.GeoDataset Dim sname As String Dim desc As New TableDesc Dim dc As New DataConnection Dim lyr As New MapObjects2.MapLayer Dim k As Long With CommonDialog1 .FileName = "" .Filter = "ESRI Shapefiles (*.shp)|*.shp" .DefaultExt = ".shp" .ShowSave If Len(.FileName) = 0 Then Exit Sub dc.Database = CurDir If Not dc.Connect Then Exit Sub sname = Left(.FileTitle, Len(.FileTitle) - 4) End With Set gds = dc.AddGeoDataset(sname, moShapeTypePoint, desc) If gds Is Nothing Then Exit Sub Set lyr.GeoDataset = gds For k = 0 To ps.Count - 1 With lyr.Records .AddNew .Fields("Shape").Value = ps(k) .Update End With Next lyr.Records.StopEditing Set ps = Nothing End Sub Private Sub Form_Load() Command1.Caption = "±£´æͼ²ã(*.shp)" End Sub Private Sub Map1_AfterTrackingLayerDraw(ByVal hDC As Stdole.OLE_HANDLE) If moPoints.Count <> 0 Then For Each ps In moPoints Map1.DrawShape ps, moSymbol Next End If End Sub Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim ps As MapObjects2.Point Set ps = Map1.ToMapPoint(X, Y) Map1.TrackingLayer.AddEvent ps, 0 End Sub |
|
1楼#
发布于:2003-09-18 16:21
好,很好,非常好!
|
|
2楼#
发布于:2003-09-18 16:42
请帮忙看看,谢谢了!!
|
|
3楼#
发布于:2003-09-18 17:11
没看到对points类型的ps赋值的代码,是不是不全啊?
你写的代码好乱,ps一会是point,一会是points |
|
4楼#
发布于:2003-09-19 14:26
谢谢大家。我终于实现了。尤其谢谢上面的兄弟.谢谢你们。
希望你们多多指导我。 |
|