SQL Server 2008空间数据应用系列十(二)

2014-11-24 14:09:41 · 作者: · 浏览: 1
l.com
{
for $e in channel/item
return

{ $e/title/text() }
{ $e/description/text() }
{ $e/link/text() }
{ $e/pubDate/text() }

{
for $child in $e/georss:where/*
return
if (fn:local-name($child) = "Point") then { $child/* }
else if (fn:local-name($child) = "LineString") then { $child/* }
else if (fn:local-name($child) = "Polygon") then { $child/* }
else if (fn:local-name($child) = "MultiPoint") then { $child/* }
else if (fn:local-name($child) = "MultiCurve") then { $child/* }
else if (fn:local-name($child) = "MultiSurface") then { $child/* }
else if (fn:local-name($child) = "MultiGeometry") then { $child/* }
else ()
}


}


') AS GeoRSSFeed;
end

  注:执行该存储过程后的就可以将表中所有的空间数据建立GeoRSS输出,输出内容比较大,这里就不贴XML结果了,随本文末的示例代码一起提供给大家下载

五、.NET发布GeoRSS订阅
  .NET服务端可以通过ASPX、ASHX等方式来发布GeoRSS订阅服务,这一步其实非常简单,就是直接调用上面的存储过程,见数据库中的空间数据以GeoRSS的数据格式输出到客户端呈现即可。以下为详细的代码实现:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace GeoRSSService
{
///


/// 发布SQL Server 2008中的空间数据为GeoRSS。
///

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;
}
}
}
}


作者:“beniao”