`
阿尔萨斯
  • 浏览: 4188133 次
社区版块
存档分类
最新评论

基于.NET 2.0的GIS开源项目SharpMap分析手记(四):地图数据访问机制分析

 
阅读更多
前面初略分析了SharpMap的渲染机制,下面再来分析下它的数据访问机制,SharpMap的数据访问机制有两个关键:Provider模式和空间索引。
1 运行机制分析
SharpMap中矢量图层类(SharpMap.Layers.VectorLayer)和注记层(SharpMap.Layers.LabelLayer)的数据源属性(DataSource)其实就是一个IProvider接口(SharpMap.Data.Providers.IProvider):
/// <summary></summary>
/// Gets or sets the datasource
///
public SharpMap.Data.Providers.IProvider DataSource
{
get { return _DataSource; }
set { _DataSource = value; }
}
因此,SharpMap的所有数据操作都是在IProvider上进行。
下面来看看数据的初始化。
1.1 数据源的初始化
我们再来看看MapHelper.cs文件中的InitializeMap函数,其中图层数据初始化如下:
//Set the datasource to a shapefile in the App_data folder
layCountries.DataSource = new
SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~/App_data/countries.shp"), true);
即生成一个ShapeFile类来初始化DataSource。初始化代码在ShapeFile.cs中,分为三步:
(1)初始化DBF文件
//Initialize DBF
string dbffile = _Filename.Substring(0, _Filename.LastIndexOf(".")) + ".dbf";
if (File.Exists(dbffile))
dbaseFile = new DbaseReader(dbffile);
(2)解析shape文件头
//Parse shape header
ParseHeader();
(3)读取投影文件
//Read projection file
ParseProjection();
1.2 数据源的打开
数据源的打开使用DataSource的Open函数。
/// <summary></summary>
/// Opens the datasource
///
public void Open()
ShapeFile的Open函数分为两步:
(1)初始化Shape文件
主要是InitializeShape函数,其主要功能是装载空间索引:
LoadSpatialIndex(FileBasedIndex); //Load spatial index
以后将对空间索引进行介绍。
(2)打开DBF文件
if (dbaseFile != null)
dbaseFile.Open();
1.3 相交查询
执行相交查询的是IProvider接口的ExecuteIntersectionQuery函数。
/// <summary></summary>
/// Returns all objects whose boundingbox intersects bbox.
///
/// <remarks></remarks>
/// <para></para>
/// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
/// that their boundingbox intersects 'bbox'.
///
///
///
///
/// <returns></returns>
public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox bbox, SharpMap.Data.FeatureDataSet ds)
它分为以下几步:
(1)得到bbox范围框中的所有对象ID
//Use the spatial index to get a list of features whose boundingbox intersects bbox
List<uint> objectlist = GetObjectIDsInView(bbox);</uint>
这个函数的实现如下:
//Use the spatial index to get a list of features whose boundingbox intersects bbox
return tree.Search(bbox);
所以,它实际使用四叉树的搜索功能。以后将在空间索引中予以介绍。
(2)根据ID得到属性信息并加入空间数据集
SharpMap.Data.FeatureDataTable dt = dbaseFile.NewTable;
for (int i = 0; i
{
SharpMap.Data.FeatureDataRow fdr = dbaseFile.GetFeature(objectlist[i], dt);
fdr.Geometry = ReadGeometry(objectlist[i]);
if (fdr.Geometry != null)
if (fdr.Geometry.GetBoundingBox().Intersects(bbox))
if (FilterDelegate == null || FilterDelegate(fdr))
dt.AddRow(fdr);
}
ds.Tables.Add(dt);
2 IProvider接口的其它函数
(1)关闭函数
/// <summary></summary>
/// Closes the datasource
///
void Close();
(2)得到范围框
/// <summary></summary>
/// <see cref="SharpMap.Geometries.BoundingBox"></see> of dataset
///
/// <returns>boundingbox</returns>
SharpMap.Geometries.BoundingBox GetExtents();
3 总结
从以上分析可知,SharpMap通过IProvider接口对数据源进行抽象,只要能实现IProvider接口的数据源就可以支持。IProvider接口的相交查询通过空间索引实现,空间索引及四叉树将在以后专门介绍。



<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
<!-- Baidu Button BEGIN -->
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script><!-- Baidu Button END --><!--192.168.100.35--><!-- Baidu Button BEGIN --><script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=1536434"></script><script type="text/javascript" id="bdshell_js"></script><script type="text/javascript"> document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000) </script><!-- Baidu Button END -->
分享到:
评论

相关推荐

    基于.NET 2.0的GIS开源项目SharpMap分析手记

    基于.NET 2.0的GIS开源项目SharpMap分析手记---粟卫民(收集为doc文档)

    基于.NET2.0的GIS开源项目SharpMap分析手记.doc

    基于.NET2.0的GIS开源项目SharpMap分析手记.doc

    1 基于NET 20的GIS开源项目SharpMap分析手记.doc

    1 基于NET 20的GIS开源项目SharpMap分析手记.doc

    GIS项目SharpMap源代码

    是基于.NET 2.0的GIS开源项目SharpMap 支持sharp文件和mysql等作为数据源 用来做GIS地图显示和渲染很方便

    C#开源GIS项目SharpMAP

    国外开源gis项目源代码及例子,可以做WEBGIS和窗体应用程序GIS

    开源GIS Sharpmap及其shp资源

    SharpMap是一个基于.net 2.0使用C#开发的Map渲染类库,可以渲染各类GIS数据,可应用于桌面和Web程序。 目前支持B/S及C/S两种方式的DLL调用,支持地图渲染效果。稳定版本为0.9,最新版本为2.0,代码行数近10000行。

    最新 SharpMap源码

    目前的很多的项目中都用到了GIS 软件,然而在开源的GIS软件中有SharpMap在工程应用中开始被人发觉。相比一些GIS软件它拥有的优势有: 1、占用资源较少,响应比较快。在对于项目中如果只需要简单的地图功能的话,是...

    sharpmapmap渲染

    SharpMap是一个基于.net 2.0使用C#开发的Map渲染类库,可以渲染各类GIS数据(目前支持ESRI Shape和PostGIS格式),可应用于桌面和Web程序。 它的优点有:  1、占用资源较少,响应比较快。在对于项目中如果只需要...

    实现表格与地图的数据联动

    基于.net2.0和DevExpress、SharpMap的WinFormDemo,选中表格中的行,地图中会自动显示选中行在地图上的位置

    GIS软件SharpMap源码详解及应用

    这本《GIS软件SharpMap源码详解及应用》由陈真、何津、余瑞编著,对目前基于C#语言开发的GIS开源项目——SharpMap进行详细剖析、解释,以便GIS专业学生及GIS的初学者能学习和掌握GIS底层开发技术。全书分为3部分共计...

    asp.net知识库

    asp.net2.0:扩展ImageButton控件定制自己需要的功能 ASP.NET 2.0 正式版中无刷新页面的开发(示例代码的补充) ASP.NET2.0中themes、Skins轻松实现网站换肤! ASP.NET 2.0 中的代码隐藏和编译 ASP.NET 2.0 Language ...

    sharpmap2.0 winformsample 可用

    sharpmap2.0 winformsample 可用,共同学习

    sharpmap英文版说明文档

    SharpMap是一个基于.net 2.0使用C#开发的Map渲染类库,可以渲染各类GIS数据(目前支持ESRI Shape和PostGIS格式),可应用于桌面和Web程序。

    【吐血推荐】史上最全的GIS开源项目源码合集

    史上最全的GIS开源项目源码合集,因项目需要精心收集...共11个开源GIS项目:GDAL、NASA开源GIS软件、World Wind、CoordSystemTransform、sharpmap、sharpkml、shapelib、netDxf、ofoSpider、oxyplot、MatrixLibrary。

    SharpMap开源代码和项目实例

    经典C# GIS,开源,SharpMap开源代码和项目实例

Global site tag (gtag.js) - Google Analytics