zoukankan      html  css  js  c++  java
  • 关于AE大数据点文件读取生成SHP文件时使用IFeatureBuffer快速提高读取效率

      1 if (kclswjPath == null || kclswjPath == string.Empty)
      2             {
      3                 MessageBox.Show("请选择卡车流水文件");
      4             }
      5 
      6             if (!File.Exists(kclswjPath))
      7             {
      8                 MessageBox.Show("卡车流水文件不存在");
      9             }
     10 
     11             string GpsShpName;
     12             string GpsShpFolder;
     13             int i = gpsShpFullName.LastIndexOf('\\');
     14             GpsShpName = gpsShpFullName.Substring(i + 1);
     15             GpsShpFolder = gpsShpFullName.Substring(0, i);
     16             frmMap frmM = new frmMap();
     17             IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
     18             IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(GpsShpFolder, 0);
     19             ISpatialReference pSpatialReference = frmM.axMapControl1.ActiveView.FocusMap.SpatialReference;
     20             IFeatureClass pFeatureClass;
     21             
     22             if (File.Exists(gpsShpFullName))
     23             {
     24                 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(GpsShpName);
     25                 IDataset pDataset = (IDataset)pFeatureClass;
     26                 pDataset.Delete();
     27             }
     28 
     29             //创建字段
     30             IFields pFields = new FieldsClass();
     31             IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
     32 
     33             IField pField = new FieldClass();
     34             IFieldEdit pFieldEdit = (IFieldEdit)pField;
     35             pFieldEdit.Name_2 = "SHAPE";
     36             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
     37             IGeometryDefEdit pGeoDef = new GeometryDefClass();
     38             IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
     39             pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
     40             pGeoDefEdit.SpatialReference_2 = pSpatialReference; //new UnknownCoordinateSystemClass(); 
     41             pFieldEdit.GeometryDef_2 = pGeoDef;
     42             pFieldsEdit.AddField(pField);
     43 
     44             pField = new FieldClass();
     45             pFieldEdit = (IFieldEdit)pField;
     46             pFieldEdit.Name_2 = "记录顺序";
     47             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
     48             pFieldsEdit.AddField(pField);
     49 
     50             pField = new FieldClass();
     51             pFieldEdit = (IFieldEdit)pField;
     52             pFieldEdit.Name_2 = "X";
     53             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
     54             pFieldsEdit.AddField(pField);
     55 
     56             pField = new FieldClass();
     57             pFieldEdit = (IFieldEdit)pField;
     58             pFieldEdit.Name_2 = "Y";
     59             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
     60             pFieldsEdit.AddField(pField);
     61 
     63             pFeatureClass = pFeatureWorkspace.CreateFeatureClass(GpsShpName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
     64 
     65             string jlsx;
     66             double dx;
     67             double dy;
     68             IPoint pPoint = new PointClass();
     69             //IPointArray pPointList = new PointArrayClass();
     70 
     71             int j = kclswjPath.LastIndexOf('\\');
     72             string kclswjName = kclswjPath.Substring(j + 1);
     73 
     74             DataTable dt = new DataTable();
     75             dt = new ReadStream().GetTruck(kclswjName);
     76 
     77 
     78             for (int k = 0; k < dt.Rows.Count; k++)
     79             {
     80                 jlsx = dt.Rows[k][0].ToString().Trim();
     81                 dx = Convert.ToDouble(dt.Rows[k][16].ToString().Trim());
     82                 dy = Convert.ToDouble(dt.Rows[k][17].ToString().Trim());
     83 
     84                 pPoint.X = dx;
     85                 pPoint.Y = dy;
     86 
     87                 IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
     88                 IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
     89                 //IPoint p = new PointClass();
     90                 pFeatureBuffer.Shape = pPoint;
     91                 pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("记录顺序"), jlsx.ToString());
     92                 pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("X"), dx.ToString());
     93                 pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("Y"), dy.ToString());
     94                 pFeatureCursor.InsertFeature(pFeatureBuffer);
     95 
     96             }
     97 
     98 
     99 
    100 
    101                 IWorkspaceFactoryLockControl ipWsFactoryLock = (IWorkspaceFactoryLockControl)pWorkspaceFactory;
    102                 if (ipWsFactoryLock.SchemaLockingEnabled)
    103                 {
    104                     ipWsFactoryLock.DisableSchemaLocking();
    105                 }
    106                 IFeatureLayer pFeaturelayer = new FeatureLayerClass();
    107                 pFeaturelayer.FeatureClass = pFeatureClass;
    108                 pFeaturelayer.Name = GpsShpName;
    109                 frmM.axMapControl1.AddLayer(pFeaturelayer);
    110                 frmM.axMapControl1.Refresh();

    刚开始参考zkcharge大神的用IFeature添加点,可是数据量太大,效率非常低,后来找到IFeatureBuffer,不到5分钟就可以搞定12万条数据的读取,初学AE开发,希望多多关照,和大家共同进步。
     
  • 相关阅读:
    新IO建立的聊天程序
    “万能数据库查询分析器”在四大软件下载网站的排行榜中均入围前10,可喜可贺
    命令行界面的C/S聊天室应用 (Socket多线程实现)
    URL 多线程下载
    DB 查询分析器 6.03 如何灵活、快捷地操作国产达梦数据库
    DB 查询分析器 6.03 在Windows 8 上安装与运行演示
    Maven部署项目到Tomcat
    中文版Maya基础培训教程
    Arduino技术指南
    Photoshop 淘宝店面设计从入门到精通
  • 原文地址:https://www.cnblogs.com/changxy/p/4223948.html
Copyright © 2011-2022 走看看