2
Vote

ExportToKml should export to SqlXml

description

Perhaps like so: -
 
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlXml ExportToKml(SqlGeography g)
{
    if (g == null || g.IsNull)
        return new SqlXml();
 
    MemoryStream stream = new MemoryStream();
    XmlWriter writer = XmlWriter.Create(stream);
 
    KeyholeMarkupLanguageGeography sink = new KeyholeMarkupLanguageGeography(writer);
 
    g.Populate(sink);
 
    sink.FinalizeKMLDocument();
 
    writer.Flush();
    stream.Seek(0, SeekOrigin.Begin);
 
    return new SqlXml(stream);
}
 
 
Can also be added to register scripts as follows: -
 
create function ExportToKml(@g geography) returns xml
as external name SQLSpatialTools.[KMLFunctions].ExportToKml
go

comments

purekrome wrote Jun 13, 2011 at 5:33 AM

Is there a performance difference with returning this as a SqlXml instead of a SqlString?

purekrome wrote Jun 13, 2011 at 5:49 AM

and I'm wondering if it's worth having another version of this function, which COMPRESSES (ie. zips) the output for large result sets .. so the data that goes over the wire is smaller .. at the cost of a tiny bit more cpu on both ends?

wrote Jan 28, 2013 at 7:06 PM

wrote Feb 21, 2013 at 11:39 PM