粟卫民ID:suen
127356次访问,排名603好友26人,关注者70
suen的文章
原创 35 篇
翻译 5 篇
转载 41 篇
评论 59 篇
小粟的公告
终于完成GeoWeb开源社区(http://www.gisdev.cn)的搭建和初步测试,请大家注册用户,测试,并提出宝贵意见。
最近评论
quzhoushijie:
杭州百度推广
杭州网站优化
杭州百度代理
再推荐两篇不错的参考文献:
(1) ASP.NET 2.0 Callback实例讲解,http://blog.csdn.net/lxjhb/archive/2007/11/09/1875968.aspx
(2)深度解析Asp.Net2.0中的Callback机制,http://www.cnblogs.com/orin-chan/archive/2005/12/13/296……
phdbrianlee:on the fly--怎么能翻译成“飞行时”?
它在这里是“实时、即时、在线”的意思,在英文中常对应offline。
wf0522:不错,很适合初学者
momolulu:域名和空间已经开通,www.helpwenchuan.com
基于google map 来做,现在需要有热情,有爱心的能够一起合作的志愿者.
文章分类
收藏
    相册
    我的照片
    GIS
    .NET开源GIS翻译WiKi
    GeoWeb开源社区
    GIS空间站
    GIS论坛
    中科院地理所
    国家测绘局
    我的旧BLOG归档
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

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

    新一篇: 基于.NET 2.0的GIS开源项目SharpMap分析手记(五):WebGIS原理分析及思考 | 旧一篇: 基于.NET 2.0的GIS开源项目SharpMap分析手记(三):地图渲染分析

    前面初略分析了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接口的相交查询通过空间索引实现,空间索引及四叉树将在以后专门介绍。
     
     

    发表于 @ 2006年12月13日 16:42:00|评论(loading...)|编辑

    新一篇: 基于.NET 2.0的GIS开源项目SharpMap分析手记(五):WebGIS原理分析及思考 | 旧一篇: 基于.NET 2.0的GIS开源项目SharpMap分析手记(三):地图渲染分析

    评论

    #advancegongyu 发表于2007-12-21 14:10:03  IP: 221.178.131.*
    不错,不错,楼主辛苦了
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 小粟