Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > 基于.NET 2.0的GIS开源项目SharpMap分析手记(四):地图数据访问机制分析
【标  题】:基于.NET 2.0的GIS开源项目SharpMap分析手记(四):地图数据访问机制分析
【关键字】:.NET,2.0,GIS,SharpMap
【来  源】:http://blog.csdn.net/suen/archive/2006/12/13/1441579.aspx

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

Your Ad Here
前面初略分析了SharpMap的渲染机制,下面再来分析下它的数据访问机制,SharpMap的数据访问机制有两个关键:Provider模式和空间索引。
1 运行机制分析
SharpMap中矢量图层类(SharpMap.Layers.VectorLayer)和注记层(SharpMap.Layers.LabelLayer)的数据源属性(DataSource)其实就是一个IProvider接口(SharpMap.Data.Providers.IProvider):
/// <summary>
/// Gets or sets the datasource
/// </summary>
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>
/// Opens the datasource
/// </summary>
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>
/// Returns all objects whose boundingbox intersects bbox.
/// </summary>
/// <remarks>
/// <para>
/// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
/// that their boundingbox intersects 'bbox'.
/// </para>
/// </remarks>
/// <param name="bbox"></param>
/// <param name="ds"></param>
/// <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);
这个函数的实现如下:
//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 < objectlist.Count; 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>
/// Closes the datasource
/// </summary>
void Close();
(2)得到范围框
/// <summary>
/// <see cref="SharpMap.Geometries.BoundingBox"/> of dataset
/// </summary>
/// <returns>boundingbox</returns>
SharpMap.Geometries.BoundingBox GetExtents();
3 总结
从以上分析可知,SharpMap通过IProvider接口对数据源进行抽象,只要能实现IProvider接口的数据源就可以支持。IProvider接口的相交查询通过空间索引实现,空间索引及四叉树将在以后专门介绍。
 
 
.NET显示gif文件:【上一篇】
Windows Server 2003 安全性指南介绍 —— 强化IIS服务器:【下一篇】
【相关文章】
  • .NET显示gif文件
  • 关于.NET中的值类型和引用类型
  • ASP.NET中如何让textbox内部的文字右对齐
  • 在.NET程序中小心使用String类型
  • Register fails when upgrade ATL project from VC7.1/VS2003 to VC8/VS2005
  • 升级MFC到.NET之一:CFont转换为Font
  • windows64位技术---.NET FrameWork代码的64位移植及与Native代码的交互(四)
  • ASP.NET AJAX Client Framework 源码追踪 3 程序的入口点
  • .NET开源社区存在的问题
  • 疑难杂症:在ASP.NET AJAX中别使用<xhtmlConformance mode="Legacy"/>
  • 【随机文章】
  • C++ 字符串操作经验集
  • Linux进程调度
  • 如何编译Linux内核
  • 机械综合制图:飞轮
  • 获到网卡MAC地址
  • 没有解决的问题!ftp工具和远程桌面连接
  • Oracle 常用函数
  • XDesigner图形软件工作室外包计划(初稿)
  • 常見程式演算
  • Moorhen Season总算完工了
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.