溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

SQL Server 2008空間數(shù)據(jù)應用中GeoRSS的用法

發(fā)布時間:2021-10-13 10:03:12 來源:億速云 閱讀:98 作者:柒染 欄目:數(shù)據(jù)庫

SQL Server 2008空間數(shù)據(jù)應用中GeoRSS的用法,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

 GeoRSS是一種描述和查明互聯(lián)網(wǎng)內(nèi)容所在物理位置的方法。通過使用GeoRSS,搜索Web站點或者與地理位置有關的項目就成為可能。GeoRSS利用地理標識語言(GML),即利用可擴展標記語言 (Extensible Markup Language, XML)存儲和傳輸?shù)乩頂?shù)據(jù)的方法。原始的GML模型以由World Wide Web聯(lián)盟(W3C)所開發(fā)的資源描述框架(RDF)為基礎。GML保持著RDF的許多特性,包括智能代理和一個用于描述和查詢數(shù)據(jù)的標準語法。GeoRSS 是在 RSS 訂閱源中包含地理空間數(shù)據(jù)時所用的一個標準,它定義了一種名為 GeoRSS GML 的特定格式,用來在訂閱源中包含 GML 格式的數(shù)據(jù)??蛻舳藨贸绦蚩梢杂嗛?GeoRSS 訂閱源,訂閱方式與訂閱常規(guī) RSS 訂閱源相同??梢暂p松地將 GeoRSS 格式的數(shù)據(jù)導入Microsoft Bing Maps、Google Maps中。
 
一、GeoRSS聚合格式
  相信很多朋友多玩過RSS訂閱的,其聚合數(shù)據(jù)的格式以XML方式承載,主要包括頭信息和體信息,體信息可能是一項或多項的數(shù)據(jù)組成。以下為RSS的聚合格式:
<?xml version=“1.0” en coding=“gb2312”?>
<rss version=“2.0”>
   <channel>
      <title>網(wǎng)站或欄目的名稱</title>
      <link>網(wǎng)站或欄目的URL地址</link>
      <description>網(wǎng)站或欄目的簡要介紹</description>
      <item>
         <title>新聞標題</title>
         <link>新聞的鏈接地址</link>
         <description>新聞簡要介紹</description>
         <pubDate>新聞發(fā)布時間</pubDate>
         <author>新聞作者名稱</author>
      </item>
      <item>
        &hellip;&hellip;
       </item>
   </channel>
</rss>
 
  而GeoRSS的XML數(shù)據(jù)格式和RSS幾乎相同,只是在RSS的基礎上使用GML擴展了對于地理空間數(shù)據(jù)的描述信息,如下GeoRSS數(shù)據(jù)。
<feed
  xmlns=""
  xmlns:georss=""
  xmlns:gml=""
  >
  <entry>
    <id>urn:uuid:7e8ee974-9181-4eae-ad65-55d29175d942</id>
    <link href=">
    <title>Cedarburg Trip</title>
    <summary>We went to visit downtown Cedarburg before the
    conference. Had some great sandwiches at Joe's. If you
    haven't been to Cedarburg, Wisconsin, then you haven't
    really experienced the MidWest...</summary>
    <content type="html" src=">
  </entry>
  <entry>
    <id>urn:uuid:53664db3-4598-45d4-a727-022c6203322e</id>
    <link rel="related" href=">
    <title>Downtown Cedarburg, Wis.</title>
    <summary>Went to visit downtown Cedarburg...</summary>
    <georss:where>
      <gml:Point>
        <gml:pos>43.296700 -87.98750</gml:pos>
      </gml:Point>
    </georss:where>
  </entry>
  <entry>
    <id>urn:uuid:2528d1b4-b5a9-415c-be69-f83974e3e6af</id>
    <link rel="related" href=">
    <title>Convention Center</title>
    <georss:where>
      <gml:LineString>
        <gml:posList>43.296700 -87.987500 43.3 -88 -44 -89</gml:posList>
      </gml:LineString>
    </georss:where>
  </entry>
</feed>


        
二、GeoRSS空間編碼
  通常有三種GeoRSS編碼,既簡單編碼、GML編碼和W3C編碼。詳細請查閱:。
 
  簡單編碼通常用于定義點、線、多邊形等規(guī)則的空間數(shù)據(jù),GML則通常適用于定義不規(guī)則的空間數(shù)據(jù),如地市區(qū)域。
 
三、定義GeoRSS數(shù)據(jù)
  定義GeoRSS數(shù)據(jù)其實主要就是在玩GeoRSS空間編碼,知道如何定義點、線、多邊形以及不規(guī)則的空間圖形。如下GeoRSS定義了一個點(重慶)坐標。
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns=""
  xmlns:georss="">
  <title>重慶</title>
  <subtitle>重慶坐標</subtitle>
  <link href=">
  <updated>2011-3-25 23:34:26</updated>
  <author>
    <name>Beniao</name>
    <email>beniao@live.cn</email>
  </author>
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  <entry>
    <title>ChongQing</title>
    <link href=">
    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
    <updated>2011-3-25 23:35:00</updated>
    <summary>summary>
    <georss:point>29.5076372217973 106.489384971208</georss:point>
  </entry>
</feed>
 
  同樣的定義一條空間線段,只是使用的GeoRSS編碼不同,如下定義了【成都--重慶】的空間線段示例。
<georss:line>30.6666587469201 104.062021177233 29.5076372217973 106.489384971208</georss:line>
 
四、創(chuàng)建GeoRSS聚合存儲過程
  創(chuàng)建GeoRSS聚合存儲過程的作用就是將空間數(shù)據(jù)格式化為GeoRSS的數(shù)據(jù)格式,存儲過程中實現(xiàn)查詢空間數(shù)據(jù),轉換空間數(shù)據(jù)為GML后并構造為GeoRSS的數(shù)據(jù)輸出。《SQL Server 2008空間數(shù)據(jù)應用系列九:使用空間工具(Spatial Tools)導入ESRI格式地圖數(shù)據(jù)》一文中實現(xiàn)了將shp數(shù)據(jù)導入到SQL Server 2008中,本篇以此數(shù)據(jù)為例創(chuàng)建存儲過程發(fā)布GeoRSS。

 
USE [BingMapsDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[CQGeoRSSFeeder]
AS
BEGIN

SET NOCOUNT ON;

-- 定義XML類型變量用于存儲GeoRSS內(nèi)容
DECLARE @GeoRSS xml;

WITH XMLNAMESPACES (
  'http://www.opengis.net/gml' AS gml,
  'http://www.georss.org/georss' AS georss
)
SELECT @GeoRSS =
  (SELECT
    [NAME] AS title,
    [NAME] AS description,
    'http://www.beginningspatial.com/' + CAST([ID] AS varchar(8)) AS link,
    geom.AsGml() AS [georss:where]
  FROM
    CQ_Region
  FOR XML PATH('item'), ROOT('channel')
)

/**
 * 使用XQuery格式化XML結果
 **/
SELECT @GeoRSS.query('
<rss version="2.0"
  xmlns:georss=""
  xmlns:gml="">
<channel>
  <title>SQL Server 2008 GeoRSS</title>
  <description>GeoRSS數(shù)據(jù)描述</description>
  <link>http://www.beginningspatial.com</link>
  {
    for $e in channel/item
    return
    <item>
    <title> { $e/title/text() }</title>
    <description> { $e/description/text() }</description>
    <link> { $e/link/text() }</link>
    <pubDate>  { $e/pubDate/text() }</pubDate>
    <georss:where>
      {
        for $child in $e/georss:where/*
        return
        if (fn:local-name($child) = "Point") then  <gml:Point> { $child/* } </gml:Point>
        else  if (fn:local-name($child) = "LineString") then  <gml:LineString> { $child/* } </gml:LineString>
        else  if (fn:local-name($child) = "Polygon") then  <gml:Polygon> { $child/* } </gml:Polygon>
        else  if (fn:local-name($child) = "MultiPoint") then  <gml:MultiPoint> { $child/* } </gml:MultiPoint>
        else  if (fn:local-name($child) = "MultiCurve") then  <gml:MultiCurve> { $child/* } </gml:MultiCurve>
        else  if (fn:local-name($child) = "MultiSurface") then  <gml:MultiSurface> { $child/* } </gml:MultiSurface>
        else  if (fn:local-name($child) = "MultiGeometry") then  <gml:MultiGeometry> { $child/* } </gml:MultiGeometry>
        else  ()
      }
    </georss:where>
  </item>
  }
</channel>
</rss>
') AS GeoRSSFeed;
end
 
  注:執(zhí)行該存儲過程后的就可以將表中所有的空間數(shù)據(jù)建立GeoRSS輸出,輸出內(nèi)容比較大,這里就不貼XML結果了,隨本文末的示例代碼一起提供給大家。
 
五、.NET發(fā)布GeoRSS訂閱
  .NET服務端可以通過ASPX、ASHX等方式來發(fā)布GeoRSS訂閱服務,這一步其實非常簡單,就是直接調用上面的存儲過程,見中的空間數(shù)據(jù)以GeoRSS的數(shù)據(jù)格式輸出到客戶端呈現(xiàn)即可。以下為詳細的代碼實現(xiàn):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace GeoRSSService
{
    /// <summary>
    /// 發(fā)布SQL Server 2008中的空間數(shù)據(jù)為GeoRSS。
    /// </summary>
    public class GeoRSSHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            context.Response.Charset = "iso-8859-1";
            context.Response.CacheControl = "no-cache";
            context.Response.Expires = 0;

            SqlConnection myConn = new SqlConnection(
                @"server=.;database=BingMapsDB;uid=sa;pwd=beniao;");
            myConn.Open();

            string myQuery = "exec dbo.CQGeoRSSFeeder";
            SqlCommand myCMD = new SqlCommand(myQuery, myConn);
            SqlDataReader myReader = myCMD.ExecuteReader();

            while (myReader.Read())
            {
                //輸出GeoRSS到客戶端
                context.Response.Write(myReader["GeoRSSFeed"].ToString());
            }

            myReader.Close();
            myConn.Close();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

看完上述內(nèi)容,你們掌握SQL Server 2008空間數(shù)據(jù)應用中GeoRSS的用法的方法了嗎?如果還想學到更多技能或想了解更多相關內(nèi)容,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI