最近偶然在網(wǎng)上搜索,,發(fā)現(xiàn)了sharpMap這個開源GIS,,其實網(wǎng)上關(guān)于sharpMap的一些講解還是比較多的,,比如GeoWeb開源社區(qū)(
http://www./showforum-6.aspx),,有專門的空間對sharpMap進(jìn)行大量的分析,,本人最近幾天也看了一些關(guān)于sharpMap的資料,,發(fā)現(xiàn)看得多了,,對其也產(chǎn)生了比較濃厚的興趣,,自己在GIS方面的知識也有了很大的提高,,不僅僅是書上純粹的理論,,通過對SharpMap這個開源GIS的學(xué)習(xí),,對以往學(xué)到的理論知識是很好的升華,,也學(xué)會了更多的實際運用。
學(xué)習(xí)一種東西,,往往是從初步的使用開始的,,這樣才能給人以直觀的印象,對于sharpMap的學(xué)習(xí)和分析,,也是一樣的,。呵呵!下面是我用sharpMap寫的一個地圖顯示的小例子,。先發(fā)效果圖:
此地圖是根據(jù)行政區(qū)域代碼作的專題圖,,這樣比一種顏色渲染要好看寫
以下是源代碼:
public partial class szwebgis : System.Web.UI.Page
{
private SharpMap.Map szmap = null;
protected void Page_Load(object sender, EventArgs e)
{
szmap = this.Init_map(new Size((int)this.mapImage.Width.Value , (int)this.mapImage.Height.Value ));
if (IsPostBack)
{
szmap.Center = Session["mapCenter"] as SharpMap.Geometries.Point;
szmap.Zoom = (double)Session["mapZoom"];
}
else
{
this.GenerateMap();
}
}
private void GenerateMap()
{
//記錄地圖的中心和放大系數(shù)
Session.Add("mapCenter", szmap.Center);
Session.Add("mapZoom", szmap.Zoom);
System.Drawing.Image img = szmap.GetMap();
string imgId = SharpMap.Web.Caching.InsertIntoCache(3, img);
this.mapImage.ImageUrl = "GetMap.aspx?ID=" + HttpUtility.UrlEncode(imgId);
}
private SharpMap.Map Init_map(Size mapsize)
{
SharpMap.Map map = new SharpMap.Map(mapsize);
//添加區(qū)域圖層
SharpMap.Layers.VectorLayer areaLyr = new SharpMap.Layers.VectorLayer("深圳區(qū)域");
areaLyr.DataSource = new SharpMap.Data.Providers.ShapeFile(Context.Server.MapPath(@"App_Data\SZ\深圳區(qū)域shp.shp"), true);
//areaLyr.Style.Fill=new SolidBrush(Color.HotPink);
//areaLyr.Style.Outline=new Pen(Color.Black);
//areaLyr.Style.EnableOutline = true;
SharpMap.Styles.VectorStyle firstStyle=new SharpMap.Styles.VectorStyle();
SharpMap.Styles.VectorStyle lastStyle=new SharpMap.Styles.VectorStyle();
firstStyle.Outline = new Pen(Color.Black);
firstStyle.EnableOutline = true;
lastStyle.Outline = new Pen(Color.Black);
lastStyle.EnableOutline = true;
SharpMap.Rendering.Thematics.GradientTheme itheme=new SharpMap.Rendering.Thematics.GradientTheme("CLASSID",0,44,firstStyle ,lastStyle );
itheme.FillColorBlend =SharpMap.Rendering.Thematics.ColorBlend.ThreeColors(Color.Yellow, Color.SkyBlue, Color.HotPink);
areaLyr.Theme = itheme;
areaLyr.SRID = 4326;
//添加區(qū)域label層
SharpMap.Layers.LabelLayer nameLyr = new SharpMap.Layers.LabelLayer("深圳區(qū)域名稱");
nameLyr.DataSource = areaLyr.DataSource;
nameLyr.LabelColumn = "Name";
nameLyr.Style.Font = new Font(FontFamily.GenericSerif, 10);
nameLyr.Style.ForeColor = Color.Black;
nameLyr.Enabled = true;
nameLyr.MaxVisible = 0.5;
nameLyr.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
nameLyr.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.All;
nameLyr.SRID = 4326;
map.Layers.Add(areaLyr);
map.Layers.Add(nameLyr);
//設(shè)置地圖中心
map.Center = new SharpMap.Geometries.Point(114.18, 22.63);
map.Zoom = 1;
return map;
}
protected void mapImage_Click(object sender, ImageClickEventArgs e)
{
//把鼠標(biāo)點擊的地方設(shè)置為地圖中心
SharpMap.Geometries.Point pt_center = null;
pt_center=szmap.ImageToWorld(new PointF((float )e.X,(float )e.Y));
szmap.Center=pt_center;
if (this.RadioButtonList1.Items[0].Selected) //放大
{
szmap.Zoom = szmap.Zoom * 0.5;
}
else if (this.RadioButtonList1.Items[1].Selected) //縮小
{
szmap.Zoom = szmap.Zoom * 2;
}
//重新生成地圖
this.GenerateMap();
}
}
////////////////////////////////////////
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="szwebgis.aspx.cs" Inherits="szwebgis" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www./1999/xhtml" >
<head runat="server">
<title>無標(biāo)題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="z-index: 100; left: 165px; position: absolute; top: 40px; font-family:Verdana; font-size:10pt; width: 506px;">
<tr>
<td style="width: 91px; height: 24px;">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
Style="z-index: 100; left: 0px; position: absolute; top: 0px" Width="236px">
<asp:ListItem>放大</asp:ListItem>
<asp:ListItem>縮小</asp:ListItem>
<asp:ListItem>平移</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="width: 91px; height: 273px;">
<asp:ImageButton ID="mapImage" runat="server" Style="z-index: 100; left: 7px;
position: absolute; top: 37px" Height="264px" Width="492px" OnClick="mapImage_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
原文鏈接:https://www.cnblogs.com/moonvan/archive/2011/06/22/2087130.html