|
阅读:1424回复:1
VB+mo新建shp文件遇到的问题
<P>Function CreateNewPointFile()<BR> Dim lngFieldNum As Long<BR> Dim strPath As String<BR> Dim strFileName As String<BR> Dim strFilePath As String<BR> Dim arrStrTmp() As String<BR> Dim lngIndexRow As Long<BR> <BR> Dim Desc As New TableDesc<BR> Dim GeoData As MapObjects2.GeoDataset<BR> Dim dc As New DataConnection<BR> Dim LayerAdd As New MapObjects2.MapLayer<BR> Dim GeoSym As New MapObjects2.GeoCoordSys<BR> Dim ProSym As New MapObjects2.ProjCoordSys<BR> <BR> Dim i As Long<BR> <BR> '************************************************<BR> '文件名处理<BR> <BR> With CDForSavePoint<BR> .FileName = ""<BR> .Filter = "shap文件(*.shp)|*.shp"<BR> .ShowSave<BR> strPath = .FileName<BR> End With<BR> If strPath = "" Then<BR> ExitSubFlag = False<BR> Exit Function<BR> End If<BR> <BR> arrStrTmp = Split(strPath, "\")<BR> strFileName = Left(arrStrTmp(UBound(arrStrTmp)), Len(arrStrTmp(UBound(arrStrTmp))) - 4)<BR> strFilePath = Left(strPath, Len(strPath) - Len(arrStrTmp(UBound(arrStrTmp))) - 1)<BR> <BR> <BR> <BR> '*******************************************************<BR> '字段定义处理<BR> <BR> With Desc<BR> .FieldCount = propertyNum<BR> For i = 0 To propertyNum - 1<BR> .FieldName(i) = propertyName(i)<BR> Select Case propertyType(i)<BR> Case 3, 4<BR> .FieldType(i) = moLong<BR> Case 6, 7<BR> .FieldType(i) = moDouble<BR> Case 8<BR> .FieldType(i) = moDate<BR> Case 10<BR> .FieldType(i) = moString<BR> End Select<BR> Next<BR>' .FieldCount=3<BR>' .FieldName(0) = "a"<BR>' .FieldName(1) = "b"<BR>' .FieldName(2) = "c"<BR>'<BR>' .FieldType(0) = moString<BR>' .FieldType(1) = moDouble<BR>' .FieldType(2) = moLong</P>
<P> End With<BR> <BR> <BR> '************************************************<BR> '生成shp文件<BR> dc.Database = strFilePath<BR> If Not dc.Connect Then<BR> MsgBox "保存文件路径不对!"<BR> ExitSubFlag = False<BR> Exit Function<BR> End If<BR> </P> <P> Set GeoData = dc.AddGeoDataset(strFileName, moPoint, Desc)<BR> <BR> If GeoData Is Nothing Then<BR> MsgBox "图层产生过程失败!请重新试一次。"<BR> ExitSubFlag = False<BR> Exit Function<BR> End If<BR> <BR> Set LayerAdd.GeoDataset = GeoData<BR> frmMainWin.mapDisp.Layers.Add LayerAdd<BR> frmMainWin.mapDisp.Refresh<BR> <BR> '产生地理坐标系文件<BR> If frmMainWin.mapDisp.CoordinateSystem.IsProjected Then<BR> ProSym.Type = 4241<BR> Set LayerAdd.CoordinateSystem = ProSym<BR> LayerAdd.CoordinateSystem.Export (strFilePath ; "\" ; strFileName ; ".prj")<BR> Else<BR> GeoSym.Type = 4241<BR> Set LayerAdd.CoordinateSystem = GeoSym<BR> LayerAdd.CoordinateSystem.Export (strFilePath ; "\" ; strFileName ; ".prj")<BR> End If<BR> <BR> '工程列表中添加新文件<BR> frmMainWin.legMapDisp.setMapSource frmMainWin.mapDisp<BR> frmMainWin.legMapDisp.LoadLegend True<BR> <BR>End Function</P> |
|
|
1楼#
发布于:2006-11-08 15:41
在字段定义处理出错,不知道什么原因,但是用解释掉的几段就可以建文件,那位大虾,可不可以告诉我是什么原因啊
|
|