惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
C
Cisco Blogs
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
S
Security Affairs
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News and Events Feed by Topic
W
WeLiveSecurity
T
Tenable Blog
L
LINUX DO - 最新话题
T
Tor Project blog
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
爱范儿
爱范儿
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
I
Intezer
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
S
Securelist
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
量子位
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Scott Helme
Scott Helme
H
Help Net Security
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
Know Your Adversary
Know Your Adversary
I
InfoQ
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes

博客园 - Bēniaǒ

简化工作流程,10款必备的HTML5开发工具 Bing Maps开发扩展三:Bing Maps中渲染ESRI SHP空间数据 Bing Maps开发扩展二:基于Oracle Spatial的空间数据分析 Flash中各种图形的绘制 ASP.NET 4.5新特性一:强类型数据绑定(Strongly-Type Data-Bindings) 产品管理,明天会如何发展? 产品经理的34个感想 Bing Maps开发扩展一:Oracle Spatial的空间数据渲染 DeepEarth自定义图元的中心位置纠偏 研发管理:产品研发团队的早会 中国式产品管理,探索中前行 Bing Maps WPF Control SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案 【动画技巧】GIF动画转SWF小技巧 【动画技巧】在Flash中自定义鼠标外观 SQL Server 2008空间数据应用系列十:使用存储过程生成GeoRSS聚合空间信息 Bing Maps Android SDK Released SQL Server 2008空间数据应用系列九:使用空间工具(Spatial Tools)导入ESRI格式地图数据 SQL Server 2008空间数据应用系列八:基于Bing Maps(Silverlight)的空间数据存储
SQL Server 2008空间数据应用系列十二:Bing Maps中呈现GeoRSS订阅的空间数据
Bēniaǒ · 2011-08-30 · via 博客园 - Bēniaǒ

友情提示,您阅读本篇博文的先决条件如下:

  1、本文示例基于Microsoft SQL Server 2008 R2调测。

  2、具备 Transact-SQL 编程经验和使用 SQL Server Management Studio 的经验。

  3、熟悉或了解Microsoft SQL Server 2008中的空间数据类型。

  4、具备相应(比如OGC规范、KML规范)的GIS专业理论知识。

  5、GeoRss订阅技术以及其他相关知识。


  GeoRSS是一种描述和查明互联网内容所在物理位置的方法。通过使用GeoRSS,搜索Web站点或者与地理位置有关的项目就成为可能。GeoRSS利用地理标识语言(GML),即利用可扩展标记语言 (Extensible Markup Language, XML)存储和传输地理数据的方法。原始的GML模型以由World Wide Web联盟(W3C)所开发的资源描述框架(RDF)为基础。GML保持着RDF的许多特性,包括智能代理和一个用于描述和查询数据的标准语法。

  GeoRSS 是在 RSS 订阅源中包含地理空间数据时所用的一个标准,它定义了一种名为 GeoRSS GML 的特定格式,用来在订阅源中包含 GML 格式的数据。客户端应用程序可以订阅 GeoRSS 订阅源,订阅方式与订阅常规 RSS 订阅源相同。可以轻松地将 GeoRSS 格式的数据导入Microsoft Bing Maps、Google Maps中,同样也可以将空间数据库中的空间数据发布为GeoRss订阅后快速的在GIS中呈现,本篇将介绍如何基于微软Bing Maps for Silverlight中呈现GeoRss订阅的空间数据。

一、发布空间数据到GeoRss

   前一篇文章《SQL Server 2008空间数据应用系列十:使用存储过程生成GeoRSS聚合空间信息》介绍了如何将空间数据通过存储过程+HTTP请求接口发布为GeoRss的具体实现,这里就一笔带过,详细请查阅上篇博文。

二、创建GeoRss阅读器

  创建GeoRss阅读器的目的是为了动态的请求GeoRss地址,将GeoRss数据解析为自己想要的数据结构,如下便是根据自己的需求结合GeoRss定义的一种数据结构样例。

using System.Collections.Generic;
using Microsoft.Maps.MapControl;
namespace GeoRss.Map.GeoRssUtils
{
    
public class GeoRssItem
    {
        
public string Title { getset; }
        
public string Description { getset; }
        
public string Link { getset; }
        
public string PubData { getset; }
        
public LocationCollection Locatios { getset; }
    }
}

  核心原理就是使用WebClient动态的发起http请求,将返回的GeoRss数据通过Linq To XML的方式解析为对象结构的数据。其实现非常简单,不做具体分析,详细代码如下所示:

using System.Collections.Generic;
using System;
using System.Net;
using System.Xml.Linq;
using System.Linq;
using System.Windows;
using Microsoft.Maps.MapControl;
namespace GeoRss.Map.GeoRssUtils
{
    
public delegate void DownloadGeoRssCompletedEventHandler(List<GeoRssItem> items);public delegate void DownloadGeoRssExceptionEventHandler(Exception e);public class GeoRssReader
    {
        
public GeoRssReader()
        {
            wc 
= new WebClient();
            wc.DownloadStringCompleted 
+= WebClientDownloadGeoRssCompleted;
        }
public GeoRssReader(Uri uri)
            : 
this()
        {
            
this.uri = uri;
        }
public GeoRssReader(Uri uri, DownloadGeoRssCompletedEventHandler evh)
            : 
this(uri)
        {
            DownloadGeoRssCompleted 
+= evh;
        }
public Uri uri { getset; }public event DownloadGeoRssCompletedEventHandler DownloadGeoRssCompleted;
        
public event DownloadGeoRssExceptionEventHandler DownloadGeoRssException;public void ReadAsync()
        {
            
if (DownloadGeoRssCompleted.Target != null)
            {
                wc.DownloadStringAsync(uri);
            }
        }
#region _privateprivate readonly WebClient wc;private void WebClientDownloadGeoRssCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            
try
            {
                XNamespace nsXml 
= "http://www.w3.org/2005/Atom";
                XNamespace nsGeorss 
= "http://www.georss.org/georss";
                XNamespace nsGeo 
= "http://www.w3.org/2003/01/geo/wgs84_pos#";
                XNamespace nsMedia 
= "http://search.yahoo.com/mrss/";

                var items 

= from item in XElement.Parse(e.Result).Descendants("item")
                            select 
new GeoRssItem
                            {
                                Title 
= (item.Element("title"!= null? item.Element("title").Value : null,
                                Link 
= (item.Element("link"!= null? item.Element("link").Value : null,
                                Description 
= (item.Element("description"!= null? item.Element("description").Value : null,
                                PubData 
= (item.Element("pubDate"!= null? item.Element("pubDate").Value : null,
                                Locatios 
= ParserLocations(XElement.Parse(item.LastNode.ToString().Replace(":""X")).Value)
                            };
                 
if (DownloadGeoRssCompleted.Method != null)
                {
                    DownloadGeoRssCompleted.Invoke(items.ToList());
                }
            }
            
catch (Exception ex)
            {
                
if (DownloadGeoRssException.Method != null)
                {
                    DownloadGeoRssException.Invoke(ex);
                }
                
else
                {
                    
throw;
                }
            }
        }
private LocationCollection ParserLocations(string points)
        {
            LocationCollection lc 
= new LocationCollection();
            
string[] ps = points.Split(' ');
            
for (int i = 0; i < ps.Length; i+=2)
            {
                lc.Add(
new Location(double.Parse(ps[i]), double.Parse(ps[i + 1])));
            }
            
return lc;
        }
#endregion

    }
}

三、基于SLBM呈现GeoRss数据

  引入Bing Maps Silverlight Control的控件库,定义一个专门的MapLayer图层来呈现GeoRss数据,其Silverlight前台的代码如下。

<Grid x:Name="LayoutRoot" Background="White">
    
<map:Map x:Name="map" Margin="0,0,0,0" CredentialsProvider="{StaticResource MyCredentials}" 
            ScaleVisibility
="Visible"
            CopyrightVisibility
="Collapsed">
        
<map:MapLayer Name="mlayer"></map:MapLayer>
    
</map:Map>
</Grid>

  应用程序加载的过程中使用上面所开发完成的GeoRss阅读器进行数据读取并解析,随后将结果呈现在Bing Maps Silverlight Control的应用中。代码如下:

public MainPage()
{
    InitializeComponent();
string url = "http://localhost:32484/SHBuildingGeoHandler.ashx";
    GeoRssReader reader 
= new GeoRssReader(new Uri(url, UriKind.RelativeOrAbsolute));
    reader.DownloadGeoRssCompleted
+=new DownloadGeoRssCompletedEventHandler(reader_DownloadGeoRssCompleted);
    reader.ReadAsync();
}
void reader_DownloadGeoRssCompleted(List<GeoRssItem> items)
{
    
//System.Diagnostics.Debug.WriteLine(items.Count);
    foreach (var item in items)
    {
        MapPolygon mp 
= new MapPolygon();
        mp.Locations 
= item.Locatios;
        mp.Fill 
= new SolidColorBrush(Colors.Red);
        
this.mlayer.Children.Add(mp);

    }
}

        

四、相关资料

  [1]、数据表中使用空间数据类型:http://www.cnblogs.com/beniao/archive/2011/02/21/1959347.html

  [2]、几何实例上的OGC方法:http://msdn.microsoft.com/zh-cn/visualc/bb933960.aspx

  [3]、几何图形实例上的扩展方法:http://msdn.microsoft.com/zh-cn/library/bb933880.aspx

  [4]、OGC 静态几何图形方法:http://msdn.microsoft.com/zh-cn/library/bb933894.aspx

  [5]、Bing Maps开发系列博文:http://www.cnblogs.com/beniao/archive/2010/01/13/1646446.html