转载 基于SharpMap扩展程序开发实例
2012-04-02 01:38
337 查看
基于SharpMap扩展程序开发实例
转载自:/article/5372012.html
SharpMap是基于.Net平台开发的GIS地图渲染组件。在SharpMap的内部设计了基于OGC标准的几何模型构架,设计了IProvider策略模式的多源矢量地图数据适配器接口,地图要素渲染的底层主要通过几何变换将Geometry转换为.Net支持的几何模型如System.Drawing.Point、System.Drawing.Rectangle、System.Drawing.Drawing2D.GraphicsPath等,然后调用System.Drawing.Graphics类的Draw方法实现地图要素的绘制。在SharpMap内部由于没有设计Symbol的构架,因此,对于需要开发真正的GIS系统,需要封装Symbol架构,以便实现专题渲染和地图符号库。
SharpMap为我们提供了GIS系统最基本的功能集合,如地图可视化、空间查询等功能,因此我们可以利用SharpMap提供的部分功能为我们在.Net平台上实现地图可视化提供支持,而不需要借助一些商业组件。本文就将简单的介绍一些基于SharpMap实现部分程序的代码示例,希望对研究开源的朋友有所启示和帮助。注:我已经对SharpMap部分Bug做了修改,重新设计了系统的构架,也新开发了一些新的模块。这些都将在以后的文章中有所阐述。
基于Jackey.Framework开发Windows应用程序示例
开发Asp.Net应用程序示例
页面代码为:
下面是我定制实现的示例。
图片上载的麻烦,请点击这里下载。
基于SharpMap扩展程序开发实例
转载自:/article/5372012.html
SharpMap是基于.Net平台开发的GIS地图渲染组件。在SharpMap的内部设计了基于OGC标准的几何模型构架,设计了IProvider策略模式的多源矢量地图数据适配器接口,地图要素渲染的底层主要通过几何变换将Geometry转换为.Net支持的几何模型如System.Drawing.Point、System.Drawing.Rectangle、System.Drawing.Drawing2D.GraphicsPath等,然后调用System.Drawing.Graphics类的Draw方法实现地图要素的绘制。在SharpMap内部由于没有设计Symbol的构架,因此,对于需要开发真正的GIS系统,需要封装Symbol架构,以便实现专题渲染和地图符号库。
SharpMap为我们提供了GIS系统最基本的功能集合,如地图可视化、空间查询等功能,因此我们可以利用SharpMap提供的部分功能为我们在.Net平台上实现地图可视化提供支持,而不需要借助一些商业组件。本文就将简单的介绍一些基于SharpMap实现部分程序的代码示例,希望对研究开源的朋友有所启示和帮助。注:我已经对SharpMap部分Bug做了修改,重新设计了系统的构架,也新开发了一些新的模块。这些都将在以后的文章中有所阐述。
基于Jackey.Framework开发Windows应用程序示例
//初始化代码,请在窗体装载事件中调用该方法。 privatevoid init() { //Set buddy control. this.tocControl1.MapControl =this.mapControl1; //create a vector layer and set the default renderer. SharpMap.Layers.VectorLayerlayCity=new SharpMap.Layers.VectorLayer("City"); layCity.DataSource=newSharpMap.Data.Providers.ShapeFileProvider(@"D:"ArcGIS"DeveloperKit"SamplesNET"data"GulfOfStLawrence"data"Can_Mjr_Cities.shp"); ((SharpMap.Rendering.SimpleFeatureRenderer)layCity.Renderer).Symbol=newSharpMap.Symbols.MarkerSymbol(SharpMap.Symbols.SymbolType.Circle,Color.Blue,10f); //create a vector layer and set the default renderer. SharpMap.Layers.VectorLayerlayRoad = new SharpMap.Layers.VectorLayer("Road"); layRoad.DataSource =new SharpMap.Data.Providers.ShapeFileProvider(@"D:"ArcGIS"DeveloperKit"SamplesNET"data"GulfOfStLawrence"data"mjrroads.shp"); ((SharpMap.Rendering.SimpleFeatureRenderer)layRoad.Renderer).Symbol = new SharpMap.Symbols.LineSymbol(Color.Green, 2f); //create a vector layer and set the default renderer. SharpMap.Layers.VectorLayerlayCoasts = newSharpMap.Layers.VectorLayer("Coasts"); layCoasts.DataSource =new SharpMap.Data.Providers.ShapeFileProvider(@"D:"ArcGIS"DeveloperKit"SamplesNET"data"GulfOfStLawrence"data"Coasts.shp"); ((SharpMap.Rendering.SimpleFeatureRenderer)layCoasts.Renderer).Symbol = new SharpMap.Symbols.FillSymbol(Color.LightCyan); //add the layer to the map this.mapControl1.Map.Layers.Add(layCoasts); this.mapControl1.Map.Layers.Add(layRoad); this.mapControl1.Map.Layers.Add(layCity); //zoom the map to the full extent this.mapControl1.ZoomToFullExtent(); } |
页面代码为:
usingSystem; usingSystem.Data; usingSystem.Configuration; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingSystem.Web.UI.WebControls.WebParts; usingSystem.Web.UI.HtmlControls; publicpartial class _Default : System.Web.UI.Page { private SharpMap.MapmyMap; /// <summary> /// Creates the map, inserts it into the cache and sets the ImageButton Url /// </summary> private void GenerateMap() { //Save the current mapcenter and zoom in the viewstate ViewState.Add("mapCenter",myMap.Center); ViewState.Add("mapZoom",myMap.Zoom); //Render map System.Drawing.Imageimg = myMap.GetMap(); //img.Save("c:""testsharpmapimg.bmp"); string imgID = SharpMap.Web.Caching.InsertIntoCache(1,img); imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID); } protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing the map myMap = MapHelper.InitializeImageMap(newSystem.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value)); //页面首次被加载 if (!Page.IsPostBack){ GenerateMap(); } else{ //Page is post back. Restore center and zoom-values from viewstate myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"]; myMap.Zoom = (double)ViewState["mapZoom"]; } } protected void Button1_Click(object sender, EventArgs e) { //ZoomIn SharpMap.Geometries.BoundingBoxbbox=myMap.VisibleBounds; bbox.Expand(0.5,0.5,true); myMap.ZoomToBox(bbox); GenerateMap(); } protected void Button2_Click(object sender, EventArgs e) { //ZoomOut SharpMap.Geometries.BoundingBoxbbox = myMap.VisibleBounds; bbox.Expand(1.5, 1.5, true); myMap.ZoomToBox(bbox); GenerateMap(); } protected void Button4_Click(object sender, EventArgs e) { //FullExtent myMap.ZoomToExtents(); GenerateMap(); } protected void imgMap_Click1(object sender, ImageClickEventArgs e) { //Set center of the map to where the client clicked myMap.Center = myMap.ToMapPoint(e.X,e.Y); GenerateMap(); } } |
usingSystem; usingSystem.Data; usingSystem.Configuration; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingSystem.Web.UI.WebControls.WebParts; usingSystem.Web.UI.HtmlControls; usingSystem.Drawing; usingSystem.Drawing.Drawing2D; ///<summary> /// Summary description for CreateMap ///</summary> publicclass MapHelper { public static SharpMap.Map InitializeImageMap(System.Drawing.Sizesize) { //Initialize a new map of size 'imagesize' SharpMap.Map map = new SharpMap.Map(size); SharpMap.Layers.GdalRasterLayerimgLayer = newSharpMap.Layers.GdalRasterLayer("Aster",HttpContext.Current.Server.MapPath(@"~"App_data"aster.tif")); map.Layers.Add(imgLayer); //Set up the countries layer SharpMap.Layers.VectorLayerlayCoal = new SharpMap.Layers.VectorLayer("Coal"); layCoal.DataSource = new SharpMap.Data.Providers.ShapeFileProvider(HttpContext.Current.Server.MapPath(@"~"App_data"huoqu.shp"),true); ((SharpMap.Rendering.SimpleFeatureRenderer)layCoal.Renderer).Symbol = new SharpMap.Symbols.FillSymbol(Color.Red); map.Layers.Add(layCoal); //Set the datasource to a shapefile in the App_data folder SharpMap.Layers.VectorLayerlayRoad=new SharpMap.Layers.VectorLayer("Road"); layRoad.DataSource = new SharpMap.Data.Providers.ShapeFileProvider(HttpContext.Current.Server.MapPath(@"~"App_data"daolu.shp"),true); ((SharpMap.Rendering.SimpleFeatureRenderer)layRoad.Renderer).Symbol = new SharpMap.Symbols.LineSymbol(Color.Blue); map.Layers.Add(layRoad); map.ZoomToExtents(); return map; } } |
图片上载的麻烦,请点击这里下载。
基于SharpMap扩展程序开发实例
相关文章推荐
- 基于SharpMap扩展程序开发实例
- 基于SBO程序开发框架的实例:仓库扩展属性设置
- 基于.NET 2.0的GIS开源项目SharpMap分析手记(八):怎样对SharpMap进行扩展开发——从许可角度来谈
- [转载]基于Oracle的高性能动态SQL程序开发(二)
- 【转载】基于我的Winform开发框架扩展而成的WCF开发框架
- 基于Visual C#的DirectX开发实例——第一个DirectX程序
- 基于.NET 2.0的GIS开源项目SharpMap分析手记(八):怎样对SharpMap进行扩展开发——从许可角度来谈
- Android蓝牙聊天程序的扩展开发(基于Google Sample,类QQ设计)
- Unity3D游戏开发之编辑器扩展程序开发实例
- Android蓝牙聊天程序的扩展开发(基于Google Sample,类QQ设计)
- Chrome扩展程序开发实例
- Unity3D游戏开发之编辑器扩展程序开发实例
- Windows下使用Dev-C++开发基于pthread.h的多线程程序实例
- 用MyEclipse10开发基于JAX-WS的Web Service实例 (转载)
- [转载]基于Oracle的高性能动态SQL程序开发(一)
- Android开发实例之多点触控程序
- 黑莓应用开发综述(转载加工基于CSDN黑莓专区)
- Restlet - 基于JAX-RS的Restlet开发实例
- [转载]基于PDIUSBD12的USB通讯开发的一些经验
- 如何基于BS架构开发聊天程序