私はシャープマップに取り組んでいます、私は米国の地図を持っていると言います、地図の上に新しいレイヤーを追加する方法は?
基本レイヤーの上に州の名前を書き、各州を異なる色で着色する必要があるため。Sharpmapsでこの目標を達成することは可能ですか...?
各状態の色には「カスタム」を使用し、状態の名前には「ラベルレイヤー」を使用する必要があります
最初に1つのデリゲートメソッドを定義する必要があります。デリゲートはパラメーターとして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;
}
次に、レイヤーのThemeプロパティをこのメソッドに設定します
SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
myVectorLayer.Theme = myTheme ;
ラベルレイヤーの場合、たとえば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);
ここですべてを伝え ます
シャープマップでは不可能だと思います。
ただし、c#では、状態の境界の座標をマッピングすることで実現できます。