ArcGIS Pro SDK (八)地理数据库 7 DDL

2024-07-11 1367阅读

ArcGIS Pro SDK (八)地理数据库 7 DDL

文章目录

  • ArcGIS Pro SDK (八)地理数据库 7 DDL
    • 1 创建表
    • 2 创建要素类
    • 3 删除表
    • 4 删除要素类
    • 5 打开内存地理数据库
    • 6 创建内存地理数据库
    • 7 删除内存地理数据库
    • 8 创建文件地理数据库
    • 9 删除文件地理数据库
    • 10 创建移动地理数据库
    • 11 删除移动地理数据库
    • 12 创建范围域
    • 13 创建编码值域
    • 14 创建要素数据集
    • 15 删除要素数据集
    • 16 重命名要素数据集
    • 17 在一次操作中创建具有要素类的要素数据集
    • 18 在现有要素数据集中创建要素类
    • 19 将要素类添加到要素数据集
    • 20 重命名表
    • 21 向要素类添加字段
    • 22 添加使用域的字段
    • 23 从表中删除字段
    • 24 创建注记要素类
    • 25 创建关联要素的注记要素类
    • 26 在要素数据集内创建注记要素类

      环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0

      ArcGIS Pro SDK (八)地理数据库 7 DDL
      (图片来源网络,侵删)

      1 创建表

      // 创建一个PoleInspection表,包含以下字段
      //  GlobalID
      //  ObjectID
      //  InspectionDate(日期)
      //  InspectionResults(预定义的InspectionResults编码值域)
      //  InspectionNotes(字符串)
      // 这个静态辅助方法创建一个带有默认值的GlobalID字段的FieldDescription
      FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
      // 这个静态辅助方法创建一个带有默认值的ObjectID字段的FieldDescription
      FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
      // 为InspectionDate字段创建一个FieldDescription
      FieldDescription inspectionDateFieldDescription = new FieldDescription("InspectionDate", FieldType.Date)
      {
          AliasName = "Inspection Date"
      };
      // 这个静态辅助方法为域字段创建一个FieldDescription(来自预定义的域)
      FieldDescription inspectionResultsFieldDescription = FieldDescription.CreateDomainField("InspectionResults", new CodedValueDomainDescription(inspectionResultsDomain));
      inspectionResultsFieldDescription.AliasName = "Inspection Results";
      // 这个静态辅助方法为字符串字段创建一个FieldDescription
      FieldDescription inspectionNotesFieldDescription = FieldDescription.CreateStringField("InspectionNotes", 512);
      inspectionNotesFieldDescription.AliasName = "Inspection Notes";
      // 汇总所有字段描述的列表
      List fieldDescriptions = new List()
      { globalIDFieldDescription, objectIDFieldDescription, inspectionDateFieldDescription, inspectionResultsFieldDescription, inspectionNotesFieldDescription };
      // 创建一个描述要创建表的TableDescription对象
      TableDescription tableDescription = new TableDescription("PoleInspection", fieldDescriptions);
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将PoleInspection表的创建添加到我们的DDL任务列表中
      schemaBuilder.Create(tableDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      // 检查错误信息
      if (!success)
      {
          IReadOnlyList errorMessages = schemaBuilder.ErrorMessages;
          //等等
      }
      

      2 创建要素类

      // 创建一个Cities要素类,包含以下字段
      //  GlobalID
      //  ObjectID
      //  Name(字符串)
      //  Population(整数)
      // 这个静态辅助方法创建一个带有默认值的GlobalID字段的FieldDescription
      FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
      // 这个静态辅助方法创建一个带有默认值的ObjectID字段的FieldDescription
      FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
      // 这个静态辅助方法为字符串字段创建一个FieldDescription
      FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);
      // 这个静态辅助方法为整数字段创建一个FieldDescription
      FieldDescription populationFieldDescription = FieldDescription.CreateIntegerField("Population");
      // 汇总所有字段描述的列表
      List fieldDescriptions = new List()
      { globalIDFieldDescription, objectIDFieldDescription, nameFieldDescription, populationFieldDescription };
      // 创建一个ShapeDescription对象
      ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Point, spatialReference);
      // 或者,ShapeDescription可以从另一个要素类创建。在这种情况下,新的要素类将继承现有类的形状属性
      ShapeDescription alternativeShapeDescription = new ShapeDescription(existingFeatureClass.GetDefinition());
      // 创建一个描述要创建要素类的FeatureClassDescription对象
      FeatureClassDescription featureClassDescription = 
          new FeatureClassDescription("Cities", fieldDescriptions, shapeDescription);
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将Cities要素类的创建添加到我们的DDL任务列表中
      schemaBuilder.Create(featureClassDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      // 检查错误信息
      if (!success)
      {
          IReadOnlyList errorMessages = schemaBuilder.ErrorMessages;
          //等等
      }
      

      3 删除表

      // 创建一个TableDescription对象
      TableDescription tableDescription = new TableDescription(table.GetDefinition());
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将表的删除添加到我们的DDL任务列表中
      schemaBuilder.Delete(tableDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      

      4 删除要素类

      // 创建一个FeatureClassDescription对象
      FeatureClassDescription featureClassDescription = new FeatureClassDescription(featureClass.GetDefinition());
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将要素类的删除添加到我们的DDL任务列表中
      schemaBuilder.Delete(featureClassDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      

      5 打开内存地理数据库

      // 连接到默认的内存地理数据库(如果存在),否则抛出异常
      MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
      // 或者,连接到名为'InterimMemoryGeodatabase'的内存地理数据库
      // MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties("InterimMemoryGeodatabase");
      // 打开内存地理数据库
      using (Geodatabase geodatabase = new Geodatabase(memoryConnectionProperties))
      {
          // 使用内存地理数据库
      }
      

      6 创建内存地理数据库

      // 创建连接默认内存地理数据库的内存连接属性
      MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
      // 或者创建连接名为'InterimMemoryGeodatabase'的内存地理数据库的内存连接属性
      // MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties("InterimMemoryGeodatabase");
      // 创建并使用内存地理数据库
      using (Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(memoryConnectionProperties))
      {
          // 在这里创建额外的模式
      }
      

      7 删除内存地理数据库

      // 创建连接默认内存地理数据库的内存连接属性
      MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
      // 删除内存地理数据库
      SchemaBuilder.DeleteGeodatabase(memoryConnectionProperties);
      

      8 创建文件地理数据库

      // 创建FileGeodatabaseConnectionPath,指定要创建的文件地理数据库名称
      FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = 
          new FileGeodatabaseConnectionPath(new Uri(@"C:\Path-To-File-Geodatabase\YourName.gdb"));
      // 创建并使用文件地理数据库
      using (Geodatabase geodatabase = 
             SchemaBuilder.CreateGeodatabase(fileGeodatabaseConnectionPath))
      {
          // 在这里创建额外的模式
      }
      

      9 删除文件地理数据库

      // 创建FileGeodatabaseConnectionPath,指定要删除的文件地理数据库名称
      FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new FileGeodatabaseConnectionPath(new Uri(@"C:\Path-To-File-Geodatabase\YourName.gdb"));
      // 删除文件地理数据库
      SchemaBuilder.DeleteGeodatabase(fileGeodatabaseConnectionPath);
      

      10 创建移动地理数据库

      // 创建MobileGeodatabaseConnectionPath,指定要创建的移动地理数据库名称
      MobileGeodatabaseConnectionPath mobileGeodatabaseConnectionPath = 
          new MobileGeodatabaseConnectionPath(new Uri(@"C:\Path-To-Mobile-Geodatabase\YourName.geodatabase"));
      // 创建并使用移动地理数据库
      using (Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(mobileGeodatabaseConnectionPath))
      {
          // 在这里创建额外的模式
      }
      

      11 删除移动地理数据库

      // 创建MobileGeodatabaseConnectionPath,指定要删除的移动地理数据库名称
      MobileGeodatabaseConnectionPath mobileGeodatabaseConnectionPath = 
          new MobileGeodatabaseConnectionPath(new Uri(@"C:\Path-To-Mobile-Geodatabase\YourName.geodatabase"));
      // 删除移动地理数据库
      SchemaBuilder.DeleteGeodatabase(mobileGeodatabaseConnectionPath);
      

      12 创建范围域

      // 创建一个范围描述,最小值 = 0,最大值 = 1000
      RangeDomainDescription rangeDomainDescriptionMinMax = new RangeDomainDescription("RangeDomain_0_1000",
                                        FieldType.Integer, 0, 1000)
      { Description = "Domain value ranges from 0 to 1000" };
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 创建范围域
      schemaBuilder.Create(rangeDomainDescriptionMinMax);
      schemaBuilder.Build();
      

      13 创建编码值域

      // 创建一个用于水管的编码值域描述
      CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(
          "WaterPipeTypes", 
          FieldType.String,
          new SortedList 
          {
              { "Copper", "C_1" },
              { "Steel", "S_2" } 
          })
      {
          SplitPolicy = SplitPolicy.Duplicate,
          MergePolicy = MergePolicy.DefaultValue
      };
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 创建编码值域
      CodedValueDomainToken codedValueDomainToken = schemaBuilder.Create(codedValueDomainDescription);
      schemaBuilder.Build();
      

      14 创建要素数据集

      // 创建名为'Parcel_Information'的要素数据集
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 创建名为'Parcel Information'的要素数据集
      FeatureDatasetDescription featureDatasetDescription = 
          new FeatureDatasetDescription("Parcel_Information", SpatialReferences.WGS84);
      schemaBuilder.Create(featureDatasetDescription);
      // 构建状态
      bool buildStatus = schemaBuilder.Build();
      // 构建错误
      if (!buildStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      15 删除要素数据集

      // 删除名为'Parcel_Information'的要素数据集
      FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition("Parcel_Information");
      FeatureDatasetDescription featureDatasetDescription = 
          new FeatureDatasetDescription(featureDatasetDefinition);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 删除名为'Parcel_Information'的现有要素数据集
      schemaBuilder.Delete(featureDatasetDescription);
      schemaBuilder.Build();
      

      16 重命名要素数据集

      // 将一个要素数据集从 'Parcel_Information' 重命名为 'Parcel_Information_With_Tax_Jurisdiction'
      string originalDatasetName = "Parcel_Information";
      string datasetRenameAs = "Parcel_Information_With_Tax_Jurisdiction";
      FeatureDatasetDefinition originalDatasetDefinition = 
          geodatabase.GetDefinition(originalDatasetName);
      FeatureDatasetDescription originalFeatureDatasetDescription = 
          new FeatureDatasetDescription(originalDatasetDefinition);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将现有的要素数据集 'Parcel_Information' 重命名为 'Parcel_Information_With_Tax_Jurisdiction'
      schemaBuilder.Rename(originalFeatureDatasetDescription, datasetRenameAs);
      schemaBuilder.Build();
      

      17 在一次操作中创建具有要素类的要素数据集

      // 在一次操作中创建一个名为 'Parcel_Information' 的要素数据集和一个名为 'Parcels' 的要素类
      string featureDatasetName = "Parcel_Information";
      string featureClassName = "Parcels";
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 创建一个要素数据集令牌
      FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(featureDatasetName, SpatialReferences.WGS84);
      FeatureDatasetToken featureDatasetToken = schemaBuilder.Create(featureDatasetDescription);
      // 创建一个要素类描述
      FeatureClassDescription featureClassDescription = new FeatureClassDescription(
          featureClassName,
          new List()
          {
              new FieldDescription("Id", FieldType.Integer),
              new FieldDescription("Address", FieldType.String)
          },
          new ShapeDescription(GeometryType.Point, SpatialReferences.WGS84));
      // 在要素数据集中创建一个要素类
      FeatureClassToken featureClassToken = schemaBuilder.Create(new FeatureDatasetDescription(featureDatasetToken), featureClassDescription);
      // 构建状态
      bool buildStatus = schemaBuilder.Build();
      // 构建错误
      if (!buildStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      18 在现有要素数据集中创建要素类

      // 在现有名为 'Parcels_Information' 的要素数据集中创建一个名为 'Tax_Jurisdiction' 的要素类
      string featureDatasetName = "Parcels_Information";
      string featureClassName = "Tax_Jurisdiction";
      // 创建一个要素类描述
      FeatureClassDescription featureClassDescription = new FeatureClassDescription(
          featureClassName,
          new List()
          {
              new FieldDescription("Tax_Id", FieldType.Integer),
              new FieldDescription("Address", FieldType.String)
          },
          new ShapeDescription(GeometryType.Point, SpatialReferences.WGS84));
      FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition(featureDatasetName);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 使用FeatureDatasetDefinition在FeatureDataset中创建一个FeatureClass
      schemaBuilder.Create(new FeatureDatasetDescription(featureDatasetDefinition), featureClassDescription);
      // 构建状态
      bool buildStatus = schemaBuilder.Build();
      // 构建错误
      if (!buildStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      19 将要素类添加到要素数据集

      // 将一个名为 'Tax_Jurisdiction' 的要素类添加到一个名为 'Parcels_Information' 的要素数据集中
      string featureDatasetName = "Parcels_Information";
      string featureClassNameToAdd = "Tax_Jurisdiction";
      FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition(featureDatasetName);
      FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(featureDatasetDefinition);
      FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition(featureClassNameToAdd);
      FeatureClassDescription featureClassDescription = new FeatureClassDescription(featureClassDefinition);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将 'Tax_Jurisdiction' 要素类添加到 'Parcels_Information' 要素数据集中
      schemaBuilder.AddFeatureClass(featureDatasetDescription, featureClassDescription);
      bool addStatus = schemaBuilder.Build();
      if (!addStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      20 重命名表

      // 将一个表从 'Original_Table' 重命名为 'Renamed_Table'
      string tableToBeRenamed = "Original_Table";
      string tableRenameAs = "Renamed_Table";
      TableDefinition tableDefinition = geodatabase.GetDefinition(tableToBeRenamed);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 表重命名
      schemaBuilder.Rename(new TableDescription(tableDefinition), tableRenameAs);
      schemaBuilder.Build();
      

      21 向要素类添加字段

      // 向 'Parcels' 要素类添加以下字段
      // 全局 ID
      // Parcel_ID
      // Tax_Code
      // Parcel_Address
      // 要添加字段的要素类
      string featureClassName = "Parcels";
      FeatureClassDefinition originalFeatureClassDefinition = geodatabase.GetDefinition(featureClassName);
      FeatureClassDescription originalFeatureClassDescription = new 
          FeatureClassDescription(originalFeatureClassDefinition);
      // 向 'Parcels' 要素类添加的四个新字段
      FieldDescription globalIdField = FieldDescription.CreateGlobalIDField();
      FieldDescription parcelIdDescription = new FieldDescription("Parcel_ID", FieldType.GUID);
      FieldDescription taxCodeDescription = FieldDescription.CreateIntegerField("Tax_Code");
      FieldDescription addressDescription = FieldDescription.CreateStringField("Parcel_Address", 150);
      List fieldsToAdd = new List 
      { 
          globalIdField, parcelIdDescription,
          taxCodeDescription, addressDescription 
      };
      // 将新字段添加到新的 FieldDescription 列表中
      List modifiedFieldDescriptions = new List(originalFeatureClassDescription.FieldDescriptions);
      modifiedFieldDescriptions.AddRange(fieldsToAdd);
      // 带有附加字段的新 FeatureClassDescription
      FeatureClassDescription modifiedFeatureClassDescription = new FeatureClassDescription(
          originalFeatureClassDescription.Name,
          modifiedFieldDescriptions, 
          originalFeatureClassDescription.ShapeDescription);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 用新添加的字段更新 'Parcels' 要素类
      schemaBuilder.Modify(modifiedFeatureClassDescription);
      bool modifyStatus = schemaBuilder.Build();
      if (!modifyStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      22 添加使用域的字段

      // 添加一个名为“PipeType”的字段,该字段使用编码值域到“Pipes”要素类
      // 要添加字段的要素类
      string featureClassName = "Pipes";
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 创建一个水管的编码值域描述
      CodedValueDomainDescription pipeDomainDescription = new CodedValueDomainDescription(
          "WaterPipeTypes", FieldType.String,
          new SortedList {
              { "Copper", "C_1" },
              { "Steel", "S_2" }
          })
      {
          SplitPolicy = SplitPolicy.Duplicate,
          MergePolicy = MergePolicy.DefaultValue
      };
      // 创建一个编码值域令牌
      CodedValueDomainToken codedValueDomainToken = schemaBuilder.Create(pipeDomainDescription);
      // 从域令牌创建一个新的描述
      CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(codedValueDomainToken);
      // 使用域描述创建一个名为“PipeType”的字段
      FieldDescription domainFieldDescription = new FieldDescription("PipeType", FieldType.String)
      { DomainDescription = codedValueDomainDescription };
      //检索“Pipes”要素类的现有信息
      FeatureClassDefinition originalFeatureClassDefinition = geodatabase.GetDefinition(featureClassName);
      FeatureClassDescription originalFeatureClassDescription = 
          new FeatureClassDescription(originalFeatureClassDefinition);
      // 将域字段添加到现有字段中
      List modifiedFieldDescriptions = new List(originalFeatureClassDescription.FieldDescriptions) { domainFieldDescription };
      // 创建一个带有更新字段的“Pipes”要素类的新描述
      FeatureClassDescription featureClassDescription = 
          new FeatureClassDescription(originalFeatureClassDescription.Name, modifiedFieldDescriptions,
                                      originalFeatureClassDescription.ShapeDescription);
      // 使用域字段更新“Pipes”要素类
      schemaBuilder.Modify(featureClassDescription);
      // 构建状态
      bool buildStatus = schemaBuilder.Build();
      // 构建错误
      if (!buildStatus)
      {
          IReadOnlyList errors = schemaBuilder.ErrorMessages;
      }
      

      23 从表中删除字段

      // 从“Parcels”表中删除所有字段,保留以下字段
      // Tax_Code
      // Parcel_Address
      // 要删除字段的表
      string tableName = "Parcels";
      TableDefinition tableDefinition = geodatabase.GetDefinition(tableName);
      IReadOnlyList fields = tableDefinition.GetFields();
      // 从“Parcels”表中获取现有字段
      Field taxCodeField = fields.First(f => f.Name.Equals("Tax_Code"));
      Field parcelAddressField = fields.First(f => f.Name.Equals("Parcel_Address"));
      FieldDescription taxFieldDescription = new FieldDescription(taxCodeField);
      FieldDescription parcelAddressFieldDescription = new FieldDescription(parcelAddressField);
      // 修改后的表中要保留的字段
      List fieldsToBeRetained = new List()
      {
          taxFieldDescription, parcelAddressFieldDescription
      };
      // 包含“Tax_Code”和“Parcel_Address”字段的“Parcels”表的新描述
      TableDescription modifiedTableDescription = new TableDescription(tableName, fieldsToBeRetained);
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 删除除“Tax_Code”和“Parcel_Address”字段外的所有字段
      schemaBuilder.Modify(modifiedTableDescription);
      schemaBuilder.Build();
      

      24 创建注记要素类

      // 创建一个名为“Cities”的注记要素类
      // 包含以下用户定义字段
      // Name 
      // GlobalID
      // 注记要素类名称
      string annotationFeatureClassName = "CitiesAnnotation";
      // 为注记要素类创建用户定义的属性字段 
      FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
      FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);
      // 创建所有字段描述的列表
      List fieldDescriptions = new List { globalIDFieldDescription, nameFieldDescription };
      // 创建一个ShapeDescription对象
      ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polygon, spatialReference);
      // 为Maplex引擎创建常规放置属性
      CIMMaplexGeneralPlacementProperties generalPlacementProperties =
          new CIMMaplexGeneralPlacementProperties
      {
          AllowBorderOverlap = true,
          PlacementQuality = MaplexQualityType.High,
          DrawUnplacedLabels = true,
          InvertedLabelTolerance = 1.0,
          RotateLabelWithDisplay = true,
          UnplacedLabelColor = new CIMRGBColor
          {
              R = 0,
              G = 255,
              B = 0,
              Alpha = 0.5f // 绿色
          }
      };
      // 为标准引擎创建常规放置属性
      //CIMStandardGeneralPlacementProperties generalPlacementProperties =
      //  new CIMStandardGeneralPlacementProperties
      //  {
      //    DrawUnplacedLabels = true,
      //    InvertedLabelTolerance = 3.0,
      //    RotateLabelWithDisplay = true,
      //    UnplacedLabelColor = new CIMRGBColor
      //    {
      //      R = 255, G = 0, B = 0, Alpha = 0.5f // 红色
      //    } 
      //   };
      // 创建注记标签类
      // 绿色标签
      CIMLabelClass greenLabelClass = new CIMLabelClass
      {
          Name = "Green",
          ExpressionTitle = "Expression-Green",
          ExpressionEngine = LabelExpressionEngine.Arcade,
          Expression = "$feature.OBJECTID",
          ID = 1,
          Priority = 0,
          Visibility = true,
          TextSymbol = new CIMSymbolReference
          {
              Symbol = new CIMTextSymbol()
              {
                  Angle = 45,
                  FontType = FontType.Type1,
                  FontFamilyName = "Tahoma",
                  FontEffects = FontEffects.Normal,
                  HaloSize = 2.0,
                  Symbol = new CIMPolygonSymbol
                  {
                      SymbolLayers = new CIMSymbolLayer[]
                      {
                          new CIMSolidFill
                          {
                              Color = CIMColor.CreateRGBColor(0, 255, 0)
                          }
                      },
                      UseRealWorldSymbolSizes = true
                  }
              },
              MaxScale = 0,
              MinScale = 0,
              SymbolName = "TextSymbol-Green"
          },
          StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
          {
              AllowOverlappingLabels = true,
              LineOffset = 1.0
          },
          MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
          {
              AlignLabelToLineDirection = true,
              AvoidPolygonHoles = true
          }
      };
      // 蓝色标签
      CIMLabelClass blueLabelClass = new CIMLabelClass
      {
          Name = "Blue",
          ExpressionTitle = "Expression-Blue",
          ExpressionEngine = LabelExpressionEngine.Arcade,
          Expression = "$feature.OBJECTID",
          ID = 2,
          Priority = 0,
          Visibility = true,
          TextSymbol = new CIMSymbolReference
          {
              Symbol = new CIMTextSymbol()
              {
                  Angle = 45,
                  FontType = FontType.Type1,
                  FontFamilyName = "Consolas",
                  FontEffects = FontEffects.Normal,
                  HaloSize = 2.0,
                  Symbol = new CIMPolygonSymbol
                  {
                      SymbolLayers = new CIMSymbolLayer[]
                      {
                          new CIMSolidFill
                          {
                              Color = CIMColor.CreateRGBColor(0, 0, 255)
                          }
                      },
                      UseRealWorldSymbolSizes = true
                  }
              },
              MaxScale = 0,
              MinScale = 0,
              SymbolName = "TextSymbol-Blue"
          },
          StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
          {
              AllowOverlappingLabels = true,
              LineOffset = 1.0
          },
          MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
          {
              AlignLabelToLineDirection = true,
              AvoidPolygonHoles = true
          }
      };
      // 创建标签列表
      List labelClasses = new List { greenLabelClass, blueLabelClass };
      // 创建注记要素类描述对象以描述要创建的要素类
      AnnotationFeatureClassDescription annotationFeatureClassDescription =
          new AnnotationFeatureClassDescription(annotationFeatureClassName, fieldDescriptions, shapeDescription,
                                                generalPlacementProperties, labelClasses)
      {
          IsAutoCreate = true,
          IsSymbolIDRequired = false,
          IsUpdatedOnShapeChange = true
      };
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将创建Cities注记要素类的操作添加到DDL任务列表中
      schemaBuilder.Create(annotationFeatureClassDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      // 检查错误消息
      if (!success)
      {
          IReadOnlyList errorMessages = schemaBuilder.ErrorMessages;
          //等。
      }
      

      25 创建关联要素的注记要素类

      // 在供水网络中创建水管和阀门之间的关联注记要素类
      // 包含以下用户定义字段
      // PipeName 
      // GlobalID
      // 注记要素类名称
      string annotationFeatureClassName = "WaterPipeAnnotation";
      // 为注记要素类创建用户定义的属性字段
      FieldDescription pipeGlobalID = FieldDescription.CreateGlobalIDField();
      FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);
      // 创建所有字段描述的列表
      List fieldDescriptions = new List { pipeGlobalID, nameFieldDescription };
      // 创建一个ShapeDescription对象
      ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polygon, spatialReference);
      // 为Maplex引擎创建常规放置属性
      CIMMaplexGeneralPlacementProperties generalPlacementProperties = new CIMMaplexGeneralPlacementProperties
      {
          AllowBorderOverlap = true,
          PlacementQuality = MaplexQualityType.High,
          DrawUnplacedLabels = true,
          InvertedLabelTolerance = 1.0,
          RotateLabelWithDisplay = true,
          UnplacedLabelColor = new CIMRGBColor
          {
              R = 255,
              G = 0,
              B = 0,
              Alpha = 0.5f
          }
      };
      // 创建注记标签类
      // 绿色标签
      CIMLabelClass greenLabelClass = new CIMLabelClass
      {
          Name = "Green",
          ExpressionTitle = "Expression-Green",
          ExpressionEngine = LabelExpressionEngine.Arcade,
          Expression = "$feature.OBJECTID",
          ID = 1,
          Priority = 0,
          Visibility = true,
          TextSymbol = new CIMSymbolReference
          {
              Symbol = new CIMTextSymbol()
              {
                  Angle = 45,
                  FontType = FontType.Type1,
                  FontFamilyName = "Tahoma",
                  FontEffects = FontEffects.Normal,
                  HaloSize = 2.0,
                  Symbol = new CIMPolygonSymbol
                  {
                      SymbolLayers = new CIMSymbolLayer[]
                      {
                          new CIMSolidFill
                          {
                              Color = CIMColor.CreateRGBColor(0, 255, 0)
                          }
                      },
                      UseRealWorldSymbolSizes = true
                  }
              },
              MaxScale = 0,
              MinScale = 0,
              SymbolName = "TextSymbol-Green"
          },
          StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
          {
              AllowOverlappingLabels = true,
              LineOffset = 1.0
          },
          MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
          {
              AlignLabelToLineDirection = true,
              AvoidPolygonHoles = true
          }
      };
      // 蓝色标签
      CIMLabelClass blueLabelClass = new CIMLabelClass
      {
          Name = "Blue",
          ExpressionTitle = "Expression-Blue",
          ExpressionEngine = LabelExpressionEngine.Arcade,
          Expression = "$feature.OBJECTID",
          ID = 2,
          Priority = 0,
          Visibility = true,
          TextSymbol = new CIMSymbolReference
          {
              Symbol = new CIMTextSymbol()
              {
                  Angle = 45,
                  FontType = FontType.Type1,
                  FontFamilyName = "Consolas",
                  FontEffects = FontEffects.Normal,
                  HaloSize = 2.0,
                  Symbol = new CIMPolygonSymbol
                  {
                      SymbolLayers = new CIMSymbolLayer[]
                      {
                          new CIMSolidFill
                          {
                              Color = CIMColor.CreateRGBColor(0, 0, 255)
                          }
                      },
                      UseRealWorldSymbolSizes = true
                  }
              },
              MaxScale = 0,
              MinScale = 0,
              SymbolName = "TextSymbol-Blue"
          },
          StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
          {
              AllowOverlappingLabels = true,
              LineOffset = 1.0
          },
          MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
          {
              AlignLabelToLineDirection = true,
              AvoidPolygonHoles = true
          }
      };
      // 创建标签列表
      List labelClasses = new List { greenLabelClass, blueLabelClass };
      // 创建关联要素描述
      // 关联要素类名称
      string linkedFeatureClassName = "WaterPipe";
      // 为水管创建字段
      FieldDescription waterPipeGlobalID = FieldDescription.CreateGlobalIDField();
      FieldDescription pipeName = FieldDescription.CreateStringField("PipeName", 255);
      // 创建水管字段描述的列表
      List pipeFieldDescriptions = new List { waterPipeGlobalID, pipeName };
      // 创建关联要素类描述
      FeatureClassDescription linkedFeatureClassDescription = new FeatureClassDescription(linkedFeatureClassName, pipeFieldDescriptions,
                                           new ShapeDescription(GeometryType.Polyline, spatialReference));
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 将创建关联要素类的操作添加到DDL任务列表中
      FeatureClassToken linkedFeatureClassToken = schemaBuilder.Create(linkedFeatureClassDescription);
      // 创建一个注记要素类描述对象以描述要创建的要素类
      AnnotationFeatureClassDescription annotationFeatureClassDescription =
          new AnnotationFeatureClassDescription(annotationFeatureClassName, fieldDescriptions, shapeDescription,
                                                generalPlacementProperties, labelClasses, new FeatureClassDescription(linkedFeatureClassToken))
      {
          IsAutoCreate = true,
          IsSymbolIDRequired = false,
          IsUpdatedOnShapeChange = true
      };
      // 将创建注记要素类的操作添加到DDL任务列表中
      schemaBuilder.Create(annotationFeatureClassDescription);
      // 执行DDL
      bool success = schemaBuilder.Build();
      // 检查错误消息
      if (!success)
      {
          IReadOnlyList errorMessages = schemaBuilder.ErrorMessages;
          //等。
      }
      

      26 在要素数据集内创建注记要素类

      // 在Places要素数据集中使用现有注记要素类创建Cities注记要素类
      // 要素数据集名称
      string featureDatasetName = "Places";
      // 注记要素类名称
      string annotationFeatureClassName = "CitiesAnnotation";
      // 创建一个SchemaBuilder对象
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
      // 打开现有的注记要素类
      using (AnnotationFeatureClass existingAnnotationFeatureClass = geodatabase.OpenDataset("ExistingAnnotationFeatureClass"))
      {
          // 创建要素数据集描述
          FeatureDatasetDescription featureDatasetDescription = 
              new FeatureDatasetDescription(featureDatasetName, existingAnnotationFeatureClass.GetDefinition().GetSpatialReference());
          // 将创建Places数据集的操作添加到DDL任务中
          FeatureDatasetToken featureDatasetToken = schemaBuilder.Create(featureDatasetDescription);
          // 使用现有注记要素类创建注记要素类描述
          AnnotationFeatureClassDescription annotationFeatureClassDescription = new AnnotationFeatureClassDescription(annotationFeatureClassName, existingAnnotationFeatureClass.GetDefinition())
          {
              IsAutoCreate = true,
              IsSymbolIDRequired = false,
              IsUpdatedOnShapeChange = true
          };
          // 将创建Cities注记要素类的操作添加到Places要素数据集中
          schemaBuilder.Create(new FeatureDatasetDescription(featureDatasetToken), annotationFeatureClassDescription);
          // 执行DDL
          bool success = schemaBuilder.Build();
          // 检查错误消息
          if (!success)
          {
              IReadOnlyList errorMessages = schemaBuilder.ErrorMessages;
              //等。
          }
      }
      
VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]