首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SHARPMAP中创建新图层

在SHARPMAP中创建新图层
EN

Stack Overflow用户
提问于 2012-03-07 12:06:03
回答 2查看 4.4K关注 0票数 3

我正在做锐化的地图,假设我有一张美国地图,如何在地图上添加新的图层?

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-29 17:26:31

您必须为每个州的颜色使用“自定义图层”,并使用“标签图层”作为州的名称

首先必须有一个委托方法define.The委托接受FeatureDataRow作为参数,您可以处理自定义样式

例如

代码语言:javascript
复制
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;
}

然后将图层的主题属性设置为此方法

代码语言:javascript
复制
SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
myVectorLayer.Theme = myTheme ;

对于标注图层,您必须将新图层定义为LabelLayer,例如

代码语言:javascript
复制
//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); 

告诉所有here

票数 5
EN

Stack Overflow用户

发布于 2012-04-17 11:52:01

我不认为这在锐化地图中是可能的。

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9595681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档