zoukankan      html  css  js  c++  java
  • 随机数创建点shp文件

    很简单,存个档,以后可以直接用,只有一个属性字段——高程。

     1 ISpatialReference pSpatialReference = this.axMapControl1.ActiveView.FocusMap.SpatialReference;
     2             string strShapeFolder="C:/";
     3             string strShapeFile = "test.shp";
     4             string shapeFileFullName = strShapeFolder + strShapeFile;
     5             IWorkspaceFactory pWorkspaceFactory= new ShapefileWorkspaceFactory();
     6             IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace) pWorkspaceFactory.OpenFromFile(strShapeFolder, 0);
     7             IFeatureClass pFeatureClass;
     8             if (File.Exists(shapeFileFullName))
     9             {
    10                 pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFile);
    11                 IDataset pDataset = (IDataset)pFeatureClass;
    12                 pDataset.Delete();
    13             }
    14             IFields pFields = new FieldsClass();
    15             IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
    16             
    17             IField pField = new FieldClass();
    18             IFieldEdit pFieldEdit = (IFieldEdit)pField;
    19             pFieldEdit.Name_2 = "SHAPE";
    20             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
    21             IGeometryDefEdit pGeoDef = new GeometryDefClass();
    22             IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
    23             pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
    24             pGeoDefEdit.SpatialReference_2 = pSpatialReference; //new UnknownCoordinateSystemClass();
    25             pFieldEdit.GeometryDef_2 = pGeoDef;
    26             pFieldsEdit.AddField(pField);
    27 
    28             pField = new FieldClass();
    29             pFieldEdit = (IFieldEdit)pField;
    30             pFieldEdit.Name_2 = "elevation";
    31             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
    32             pFieldsEdit.AddField(pField);
    33 
    34             pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strShapeFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
    35 
    36             Random rd = new Random();
    37             for (int i = 0; i < 20;i++ )
    38             {
    39                 IPoint pPoint = new PointClass();
    40                 pPoint.X = rd.Next(0, 1000);
    41                 pPoint.Y = rd.Next(0, 1000);
    42                 pPoint.Z = rd.Next(0, 100);
    43                 IFeature pFeature = pFeatureClass.CreateFeature();
    44                 pFeature.Shape = pPoint;
    45                 pFeature.set_Value(pFeature.Fields.FindField("elevation"), pPoint.Z);
    46                 pFeature.Store();
    47             }
    48             IFeatureLayer pFeaturelayer = new FeatureLayerClass();
    49             pFeaturelayer.FeatureClass = pFeatureClass;
    50             pFeaturelayer.Name = "layer";
    51             this.axMapControl1.AddLayer(pFeaturelayer);
    52         }
  • 相关阅读:
    【计算机网络】宽带、基带传输
    【操作系统】多道程序的理解
    【操作系统】操作系统的理解
    NLP学习常用的网页链接
    linux下常用FTP命令 1. 连接ftp服务器[转]
    shell运行java/Jar 脚本
    jsp验证码
    用javascript实现的验证码
    eclipse设置高亮显示的颜色
    oracle 导出
  • 原文地址:https://www.cnblogs.com/zhuyuchen/p/2861198.html
Copyright © 2011-2022 走看看