24小时热门版块排行榜    

查看: 1933  |  回复: 10
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

zzahkj

木虫 (著名写手)


[交流] Vb.net+ArcEngine生成点状图层的速度太慢了该怎么办?

Vb.net+ArcEngine生成点状图层的速度太慢了该怎么办?由于我做的是预警预报系统,速度尽可能短,现在生成全部点要好几天,这也太慢了,根本就不适用,请问有什么好的办法解决吗?我的代码如下:
CODE:
Public Sub dianshengcheng()
        Dim filePath As String = My.Computer.FileSystem.CurrentDirectory & "\ResultsFileName"
        If System.IO.File.Exists(filePath & "\点.shp") Then
            MessageBox.Show("点文件已存在")
            Main.AxMapControl1.AddShapeFile(filePath, "点")
        Else
            Dim pShpWksFact As IWorkspaceFactory = New ShapefileWorkspaceFactory()
            Dim pFeatWks As IFeatureWorkspace
            pFeatWks = CType(pShpWksFact.OpenFromFile(filePath, 0), IFeatureWorkspace)
            Const strShapeFieldName As String = "shape"
            Dim pFields1 As IFields
            Dim pFieldsEdit1 As IFieldsEdit
            pFields1 = New FieldsClass()
            pFieldsEdit1 = CType(pFields1, IFieldsEdit)
            Dim pField1 As IField = New FieldClass()
            Dim pFieldEdit1 As IFieldEdit = New FieldClass()
            pFieldEdit1.Name_2 = strShapeFieldName
            pFieldEdit1.Type_2 = esriFieldType.esriFieldTypeGeometry
            pField1 = CType(pFieldEdit1, IField)
            Dim pGeomDef1 As IGeometryDef = New GeometryDefClass()
            Dim pGeomDefEdit1 As IGeometryDefEdit = New GeometryDefClass()
            pGeomDefEdit1 = CType(pGeomDef1, IGeometryDefEdit)
            pGeomDefEdit1.GeometryType_2 = esriGeometryType.esriGeometryPoint
            pGeomDefEdit1.SpatialReference_2 = Main.AxMapControl1.Map.SpatialReference
            'pGeomDefEdit1.HasZ_2 = True
            pFieldEdit1.GeometryDef_2 = pGeomDef1

            pFieldsEdit1.AddField(pField1)
            pFields1 = CType(pFieldsEdit1, IFields)

            pField1 = New Field
            pFieldEdit1 = pField1
            With pFieldEdit1
                pFieldEdit1.Length_2 = 10
                pFieldEdit1.Name_2 = "温度"
                pFieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble
            End With
            pFieldsEdit1.AddField(pField1)
            pField1 = New Field
            pFieldEdit1 = pField1
            With pFieldEdit1
                pFieldEdit1.Length_2 = 10
                pFieldEdit1.Name_2 = "盐度"
                pFieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble
            End With
            pFieldsEdit1.AddField(pField1)
            pField1 = New Field
            pFieldEdit1 = pField1
            With pFieldEdit1
                pFieldEdit1.Length_2 = 10
                pFieldEdit1.Name_2 = "水质指标"
                pFieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble
            End With
            pFieldsEdit1.AddField(pField1)
            Dim pFeatureClass1 As IFeatureClass
            pFeatureClass1 = pFeatWks.CreateFeatureClass("点", pFields1, Nothing, Nothing, esriFeatureType.esriFTSimple, strShapeFieldName, "")
            Dim pPointCol As IPointCollection = New MultipointClass()
            Dim sr As StreamReader = New StreamReader(My.Computer.FileSystem.CurrentDirectory & "\shu\dianceng.txt")
            Dim str As String = sr.ReadLine()
            While str IsNot Nothing
                Dim strs() As String = Regex.Split(str, "        ")
                Dim x As Double = Convert.ToDouble(strs(0))
                Dim y As Double = Convert.ToDouble(strs(1))
                Dim t As Double = Convert.ToDouble(strs(2))
                Dim s As Double = Convert.ToDouble(strs(3))
                Dim c As Double = Convert.ToDouble(strs(4))
                Dim pPoint As IPoint = New PointClass()
                pPoint.X = x
                pPoint.Y = y
                Dim missing As Object = Type.Missing
                pPointCol.AddPoint(pPoint, missing, missing)
                str = sr.ReadLine()
                Dim i As Integer
                For i = 0 To pPointCol.PointCount - 1 Step 1
                    Dim newFeature As IFeature = pFeatureClass1.CreateFeature
                    newFeature.Shape = pPointCol.Point(i)
                    newFeature.Value(newFeature.Fields.FindField("温度")) = t
                    newFeature.Value(newFeature.Fields.FindField("盐度")) = s
                    newFeature.Value(newFeature.Fields.FindField("水质指标")) = c
                    newFeature.Store()
                Next
            End While
            Main.AxMapControl1.Refresh()
            Main.AxMapControl1.AddShapeFile(filePath, "点")
            MessageBox.Show("文件创建成功")
        End If
    End Sub

[ Last edited by zzahkj on 2011-5-6 at 15:36 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

雷小雨

银虫 (著名写手)



小木虫(金币+0.5):给个红包,谢谢回帖
没有运行环境,读了一下代码
在while循环里面,第1次for循环生成pPointCol的第1个点
第2次for循环生成pPointCol的第1~2个点
第3次for循环生成pPointCol的第1~3个点
第N次for循环生成pPointCol的第1~N个点

也就说,第i个点生成了N-i+1次,所以并不是生成了N个点,而是生成了N(N+1)/2个点,时间从O(N)上升到了O(N^2),不知道我理解得对不对

[ Last edited by 雷小雨 on 2011-5-8 at 11:38 ]
9楼2011-05-08 11:37:00
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 11 个回答

efeng522

木虫 (初入文坛)



小木虫(金币+0.5):给个红包,谢谢回帖
这个要看你数据量的大小,如果数据量不大,那么这个效率肯定是不正常的;如果数据量确实有这么大,你就要考虑是否有必要一次性生成这么多数据,或者在这么大的空间范围内生成数据。
VB不熟,所以代码没细看,只是泛泛而谈,抛砖引玉
2楼2011-05-06 16:07:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zzahkj

木虫 (著名写手)


引用回帖:
Originally posted by efeng522 at 2011-05-06 16:07:05:
这个要看你数据量的大小,如果数据量不大,那么这个效率肯定是不正常的;如果数据量确实有这么大,你就要考虑是否有必要一次性生成这么多数据,或者在这么大的空间范围内生成数据。
VB不熟,所以代码没细看,只是 ...

数据量还是非常大的,必须得一次性生成这么多数据!我也觉得这个效率不正常,可没有很好的办法解决?
3楼2011-05-06 16:25:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xiangling1

金虫 (正式写手)



小木虫(金币+0.5):给个红包,谢谢回帖
zzahkj(金币+10): 2011-05-07 15:43:13
后面的循环可以优化,你把For循环提出来

你把三个属性封装一下,循环一次,把三个属性赋进去值

你这样做出来的点的属性值是不对的

你多写几个函数,把这段代码分解开一定不要循环里面再有循环

速度会增加的
4楼2011-05-06 21:31:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 材料学硕318求调剂 +5 February_Feb 2026-03-19 5/250 2026-03-19 23:51 by 23Postgrad
[考研] 321求调剂 +8 何润采123 2026-03-18 10/500 2026-03-19 16:46 by 何润采123
[考研] 304求调剂 +3 曼殊2266 2026-03-18 3/150 2026-03-19 14:42 by peike
[考研] 一志愿福大288有机化学,求调剂 +3 小木虫200408204 2026-03-18 3/150 2026-03-19 13:31 by houyaoxu
[考研] 281求调剂(0805) +9 烟汐忆海 2026-03-16 19/950 2026-03-19 11:42 by laoshidan
[考研] 0703化学 305求调剂 +4 FY_yy 2026-03-14 4/200 2026-03-19 05:54 by anny19840123
[考研] 298-一志愿中国农业大学-求调剂 +7 手机用户 2026-03-17 7/350 2026-03-18 14:34 by vgtyfty
[考博] 环境领域全国重点实验室招收博士1-2名 +3 QGZDSYS 2026-03-13 5/250 2026-03-18 11:13 by QGZDSYS
[考研] 0703化学求调剂 总分331 +3 ZY-05 2026-03-13 3/150 2026-03-18 10:58 by macy2011
[考研] 085601求调剂 +4 Du.11 2026-03-16 4/200 2026-03-17 17:08 by ruiyingmiao
[考研] 332求调剂 +6 Zz版 2026-03-13 6/300 2026-03-17 17:03 by ruiyingmiao
[考研] [导师推荐]西南科技大学国防/材料导师推荐 +3 尖角小荷 2026-03-16 6/300 2026-03-16 23:21 by 尖角小荷
[考研] 东南大学364求调剂 +5 JasonYuiui 2026-03-15 5/250 2026-03-16 21:28 by 木瓜膏
[考研] 318求调剂 +3 Yanyali 2026-03-15 3/150 2026-03-16 16:41 by houyaoxu
[考研] 070303 总分349求调剂 +3 LJY9966 2026-03-15 5/250 2026-03-16 14:24 by xwxstudy
[考研] 0703化学调剂 290分有科研经历,论文在投 +7 腻腻gk 2026-03-14 7/350 2026-03-16 10:12 by houyaoxu
[考研] 326求调剂 +3 mlpqaz03 2026-03-15 3/150 2026-03-16 07:33 by Iveryant
[考研] 070305求调剂 +3 mlpqaz03 2026-03-14 4/200 2026-03-15 11:04 by peike
[考研] 本科南京大学一志愿川大药学327 +3 麦田耕者 2026-03-14 3/150 2026-03-14 20:04 by 外星文明
[考研] 311求调剂 +3 冬十三 2026-03-13 3/150 2026-03-13 20:41 by JourneyLucky
信息提示
请填处理意见