Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在SHARPMAP中创建新图层_C#_Maps_Sharpmap - Fatal编程技术网

C# 在SHARPMAP中创建新图层

C# 在SHARPMAP中创建新图层,c#,maps,sharpmap,C#,Maps,Sharpmap,我正在制作sharpmaps,比如说我有一张我们的地图,如何在地图上添加新的图层 因为我需要在基本层上写下州名,并用不同的颜色给每个州涂上颜色。 在Sharpmaps中有可能实现这个目标吗?我认为在Sharpmaps中不可能 然而,在c#中,它可以通过映射州边界的坐标来实现。必须对每个州使用“自定义颜色”,对州名称使用“标签层” 您必须首先定义一个委托方法。该委托将FeatureDataRow作为参数,您可以处理自定义样式 比如说 private SharpMap.Styles.VectorSt

我正在制作sharpmaps,比如说我有一张我们的地图,如何在地图上添加新的图层

因为我需要在基本层上写下州名,并用不同的颜色给每个州涂上颜色。
在Sharpmaps中有可能实现这个目标吗?

我认为在Sharpmaps中不可能

然而,在c#中,它可以通过映射州边界的坐标来实现。

必须对每个州使用“自定义颜色”,对州名称使用“标签层”

您必须首先定义一个委托方法。该委托将FeatureDataRow作为参数,您可以处理自定义样式

比如说

private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
{
    SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
    switch (row["NAME"].ToString().ToLower())
    {
        case "denmark": //If country name is Danmark, fill it with green
            style.Fill = Brushes.Green;
            return style;
        case "united states": //If country name is USA, fill it with Blue and add a red outline
            style.Fill = Brushes.Blue;
            style.Outline = Pens.Red;
            return style;
        case "china": //If country name is China, fill it with red
            style.Fill = Brushes.Red;
            return style;
        default:
            break;
    }
    //If country name starts with S make it yellow
    if (row["NAME"].ToString().StartsWith("S"))
    {
        style.Fill = Brushes.Yellow;
        return style;
    }
    // If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
    else if (row.Geometry is GeoAPI.Geometries.IPolygonal && row.Geometry.Area < 30)
    {
        style.Fill = Brushes.Cyan;
        return style;
    }
    else //None of the above -> Use the default style
        return null;
}
对于标签层,您必须将新层定义为LabelLayer 比如说

//Name of table in database
string tablename = "Roads"; 
//Name of object ID column - MUST be integer!
string idColumn = "gid";

//Create layer
SharpMap.Layers.VectorLayer layRoads= new SharpMap.Layers.VectorLayer("Roads");
layRoads.DataSource = datasource;
//Set up a road label layer
SharpMap.Layers.LabelLayer layRoadLabel = new SharpMap.Layers.LabelLayer("Road labels");
//Set the datasource to that of layRoads.
layRoadLabel.DataSource = layRoads.DataSource;
layRoadLabel.Enabled = true;
//Specifiy field that contains the label string.
layRoadLabel.LabelColumn = "RoadOfName";

//Add layer to map
myMap.Layers.Add(layRoads);
//Add label layer to map
myMap.Layers.Add(layRoadLabel); 
告诉所有人

我认为这个链接有帮助
//Name of table in database
string tablename = "Roads"; 
//Name of object ID column - MUST be integer!
string idColumn = "gid";

//Create layer
SharpMap.Layers.VectorLayer layRoads= new SharpMap.Layers.VectorLayer("Roads");
layRoads.DataSource = datasource;
//Set up a road label layer
SharpMap.Layers.LabelLayer layRoadLabel = new SharpMap.Layers.LabelLayer("Road labels");
//Set the datasource to that of layRoads.
layRoadLabel.DataSource = layRoads.DataSource;
layRoadLabel.Enabled = true;
//Specifiy field that contains the label string.
layRoadLabel.LabelColumn = "RoadOfName";

//Add layer to map
myMap.Layers.Add(layRoads);
//Add label layer to map
myMap.Layers.Add(layRoadLabel);