代码之家  ›  专栏  ›  技术社区  ›  Umar Dastgir

在Featureset Dotspatial中设置字段值

  •  2
  • Umar Dastgir  · 技术社区  · 6 年前

    我正在使用Microsoft Visual Studio中的DotSpatial库和C编程语言创建形状文件。shapefile由一个多边形层组成。层中的每个多边形都需要有特定的肥料值。就我的理解而言,我必须首先创建一个字段(称为“肥料值”),然后为创建的每个多边形添加相应的肥料值。我创建了一个字段并创建了一个多边形。但是,我仍然在努力寻找在相应的多边形中添加字段值的正确方法。代码如下:

    // Create a feature set of type Polygon and set the projection
    FeatureSet fs = new FeatureSet(FeatureType.Polygon);
    fs.Projection = ProjectionInfo.FromAuthorityCode("EPSG", 3857);
    
    // Get the DataTable and set the fertilizer field
    DataTable table = fs.DataTable;
    DataColumn FertilizerField = table.Columns.Add("Fertilizer Value", typeof(double));
    
    // Adding a Polygon feature to the layer 
    Coordinate[] coord = new Coordinate[]
    {
        new Coordinate(0.0, 0.0),
        new Coordinate(1.0, 0.0),
        new Coordinate(1.0, 1.0),
        new Coordinate(0.0, 1.0),
        new Coordinate(0.0, 0.0)
    };
    fs.AddFeature(new Polygon(new LinearRing(coord)));
    
    // TODO: HOW TO ADD FERTILIZER VALUE OF 100 TO THE FERTILIZER FIELD OF THIS POLYGON?
    

    我的问题是,如何设置此多边形的“场”值?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Ted    6 年前

    您可以创建一个特征变量,然后更新DataRow属性的内容。然后必须直接将该功能添加到功能集合,而不是使用add feature快捷方式方法。

            // Create a feature set of type Polygon and set the projection
            FeatureSet fs = new FeatureSet(FeatureType.Polygon);
            fs.Projection = ProjectionInfo.FromAuthorityCode("EPSG", 3857);
    
            // Get the DataTable and set the fertilizer field
            DataTable table = fs.DataTable;
            DataColumn FertilizerField = table.Columns.Add("Fertilizer Value", typeof(double));
    
            // Adding a Polygon feature to the layer 
            Coordinate[] coord = new Coordinate[]
            {
                new Coordinate(0.0, 0.0),
                new Coordinate(1.0, 0.0),
                new Coordinate(1.0, 1.0),
                new Coordinate(0.0, 1.0),
                new Coordinate(0.0, 0.0)
            };
            // Create a Feature Variable to update the shape with attribute content.
            Feature f = new Feature(new Polygon(new LinearRing(coord)));
            // Modify the data row like any DataTable DataRow object.
            f.DataRow["Fertilizer Value"] = 100;
            // Add the fully created feature to the list of features directly.
            fs.Features.Add(f);