阅读:1295回复:1
关于保存Shp格式文件的问题?你遇到过吗?
<P> 我想将一图层以Shp格式文件输出,但如果图层的字段数(tabledesc.fieldcount)>16时,就不能正常输出文件,<=16时则正常,并且我已测试并非第16位后的字段存储内容有问题,(因为只要字段数<=16 ,第16位后的字段也能输出),各位大虾是否也碰到过类似问题????补充说明,我需要输出的数据源是SDE图层。下面是我的代码</P>
<P>Public Sub NewShpFile() '生成一个shp文件<BR> Dim dc As New DataConnection<BR> Dim gds As New MapObjects2.Recordset<BR> Dim rst As New MapObjects2.Recordset<BR> Dim gds1 As New MapObjects2.GeoDatasets<BR> Dim gds2 As New MapObjects2.GeoDataset<BR> Dim ly As New MapObjects2.maplayer<BR> Dim i As Integer<BR> Set rst = Explyr.Records 'Explyr 为输出的图层,为全局变量<BR> TableStru '获取字段头<BR> desc.FieldLength(0) = 16<BR>bbb:<BR> dc.Database = pathname 'pathname 为输出路径,为全局变量<BR><BR> If dc.Connect Then<BR> For i = 0 To desc.FieldCount - 1<BR>' Debug.Print desc.FieldName(i)<BR> <BR> Next i<BR> <BR> Set gds2 = dc.AddGeoDataset(outfile, Explyr.ShapeType, desc) 'outfile 为输出文件名,为全局变量<BR><BR> Else<BR> MsgBox "Bad dataConnection!"<BR> GoTo bbb<BR> End If<BR> Set ly.GeoDataset = gds2<BR> Set gds = ly.Records<BR> If gds Is Nothing Then<BR> 'MsgBox "Failed to create new Shape file (GeoDataset)!"<BR> GoTo bbb<BR> Else<BR> Do Until rst.EOF<BR> gds.AddNew<BR> For i = 0 To gds.TableDesc.FieldCount - 1<BR> With gds<BR> <BR> .Fields(.TableDesc.FieldName(i)).Value = rst.Fields(rst.TableDesc.FieldName(i)).Value<BR> .Fields("Shape").Value = rst.Fields("shape").Value<BR> End With<BR> <BR> Next<BR> gds.Update<BR> rst.MoveNext<BR> Loop<BR> End If<BR> <BR>End Sub</P> <P>Private Sub TableStru()<BR> Dim exprst As New MapObjects2.Recordset<BR> Set exprst = Explyr.Records<BR> Set desc = exprst.TableDesc<BR>'Set TableDesc object<BR> With desc<BR> .FieldName(0) = "FID"<BR> End With<BR>End Sub</P> |
|
1楼#
发布于:2006-07-25 11:25
<P>版主能帮一下忙吗?如果图层的存储的字段太多,怎么才能正常导出到shp文件呢???</P>
|
|