<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://footheory.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bennie&amp;#39;s Weblog : SQL Server</title><link>http://footheory.com/blogs/bennie/archive/tags/SQL+Server/default.aspx</link><description>Tags: SQL Server</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Debug Build: 20611.960)</generator><item><title>Investigating the new Spatial Types in SQL Server 2008 - Part 2</title><link>http://footheory.com/blogs/bennie/archive/2008/10/08/investigating-the-new-spatial-type-in-sql-server-2008-part-2.aspx</link><pubDate>Wed, 08 Oct 2008 19:32:51 GMT</pubDate><guid isPermaLink="false">9ce7e6ef-4587-4f0e-939d-3f75f3a8ddfc:415</guid><dc:creator>bennie</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://footheory.com/blogs/bennie/rsscomments.aspx?PostID=415</wfw:commentRss><comments>http://footheory.com/blogs/bennie/archive/2008/10/08/investigating-the-new-spatial-type-in-sql-server-2008-part-2.aspx#comments</comments><description>&lt;h3&gt;&lt;/h3&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;In the &lt;a href="http://footheory.com/blogs/bennie/archive/2008/10/05/investigating-the-new-spatial-types-in-sql-server-2008-part-1.aspx"&gt;previous part&lt;/a&gt; of this series, we talked about the importance of spatial data in our everyday lives. We talked about vector and raster data, and we explained that the current version of SQL Server 2008 focuses on two-dimensional vector data. Next, we introduced the new &lt;strong&gt;geography&lt;/strong&gt; and &lt;strong&gt;geometry&lt;/strong&gt; data types in SQL server 2008, and we took a quick detour into some important object-oriented principles.&lt;/p&gt;  &lt;p&gt;In this article, we start out by taking a look at the class hierarchies for both the geometry and the geography data types in SQL Server 2008. We will focus on the concrete classes in the class diagram which are:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="2" face="tahom"&gt;Point.&amp;#160; &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="tahom"&gt;LineString &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="tahom"&gt;Polygon&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;We will also take a look at the collection classes in the object hierarchy, which allow us to store multiple instances of each type.&lt;/p&gt;  &lt;p&gt;Once we have a good grasp on the geometry and geography class hierarchy we will dive into the details of each concrete class. We will start our investigation by looking into the details of the &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;LineString&lt;/font&gt; class, and we will write a T-SQL script that highlights the most important features. In the process we will take a look at the three different data formats that can be used to represent spatial data:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The Well-Known-Binary&amp;#160; (&lt;a href="http://edndoc.esri.com/arcsde/9.0/general_topics/wkb_representation.htm"&gt;WKB&lt;/a&gt;) format &lt;/li&gt;    &lt;li&gt;The Well-Known-Text (&lt;a href="http://en.wikipedia.org/wiki/Well-known_text"&gt;WKT&lt;/a&gt;) format &lt;/li&gt;    &lt;li&gt;The Geography Markup Language (&lt;a href="http://en.wikipedia.org/wiki/Geography_Markup_Language"&gt;GML&lt;/a&gt;) data format. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;All of these formats are published as a standard by the Open Geospatial Consortium (&lt;a href="http://www.opengeospatial.org/"&gt;OGC&lt;/a&gt;), which is the leading standards body for geospatial and location based services.&lt;/p&gt;  &lt;h3&gt;The Geometry class hierarchy&lt;/h3&gt;  &lt;h4&gt;Overview&lt;/h4&gt;  &lt;p&gt;A class diagram showing the &lt;font size="2" face="Courier New"&gt;Geometry&lt;/font&gt; class and all of its sub-classes is shown below (note that the &lt;font size="2" face="Courier New"&gt;Geography&lt;/font&gt; class diagram is basically identical, with the &lt;font size="2" face="Courier New"&gt;Geography&lt;/font&gt; class at the root of the tree):&lt;/p&gt;  &lt;p&gt;&lt;a title="Geometry Class Diagram" href="http://www.flickr.com/photos/99548241@N00/2918867849/"&gt;&lt;img border="0" alt="Geometry Class Diagram" src="http://static.flickr.com/3202/2918867849_6193d71671.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The darker-blue shaded classes are abstract base classes, so they cannot be directly instantiated in the database engine. The light-blue shaded classes are the concrete classes that we can use directly in our T-SQL code:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="Courier New"&gt;LineString&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="Courier New"&gt;Polygon&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Each of these single-instance classes has a collection equivalent that can contain multiple instances:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;MultiPoint&lt;/font&gt;&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="Courier New"&gt;MultiLineString&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="2" face="Courier New"&gt;MultiPolygon&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The &lt;font size="2" face="Courier New"&gt;GeomCollection&lt;/font&gt; class is an additional collection class that can contain a mixture of instances of any type (&lt;font size="2" face="Courier New"&gt;Points&lt;/font&gt;, &lt;font size="2" face="Courier New"&gt;LineStrings&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;Polygons&lt;/font&gt;).&lt;/p&gt;  &lt;h4&gt;Supported Data Formats&lt;/h4&gt;  &lt;p&gt;All of the classes in the &lt;font size="2" face="Courier New"&gt;geometry&lt;/font&gt; and the &lt;font size="2" face="Courier New"&gt;geography&lt;/font&gt; class hierarchy can be represented by three different formats:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;The Well-Known Binary (&lt;a href="http://edndoc.esri.com/arcsde/9.0/general_topics/wkb_representation.htm"&gt;WKB&lt;/a&gt;) format&lt;/strong&gt;. This is a byte-stream (binary) representation for a geography instance. This format is the preferred serialization format for those applications that need to store geospatial information in a compact, self-contained format.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The Well-Known Text (&lt;a href="http://en.wikipedia.org/wiki/Well-known_text"&gt;WKT&lt;/a&gt;) format.&lt;/strong&gt; This is a compact, easy to read representation. Because of its user-friendly format it is the most commonly used representation for ad-hoc geospatial queries. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;The Geography Markup Language (&lt;a href="http://en.wikipedia.org/wiki/Geography_Markup_Language"&gt;GML&lt;/a&gt;) format&lt;/strong&gt;. This is an XML-based representation, which is best suited for including geospatial information in an XML document. This format is very useful for those applications that need to exchange geospatial information by means of an XML Web service. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;All of the above formats are published as standards by the &lt;a href="http://www.opengeospatial.org/"&gt;OGC&lt;/a&gt;. In the code samples that follow, we will be showing multiple examples of each format.&lt;/p&gt;  &lt;h4&gt;The Point Class&lt;/h4&gt;  &lt;h5&gt;&lt;/h5&gt;  &lt;h5&gt;Basic Representation&lt;/h5&gt;  &lt;p&gt;A &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; is a zero-dimensional object which represents a single, exact location. It always contains an X and Y coordinate, and can optionally can contain a Z (elevation) value, and a M (measure) value. The measure value is an arbitrary floating point measurement value that you can associate with the &lt;font size="2" face="Courier New"&gt;Point &lt;/font&gt;instance.&lt;/p&gt;  &lt;p&gt;The sample &lt;font size="2" face="tah"&gt;T-SQL script (&lt;font face="Courier New"&gt;GeometryPoint.sql)&lt;/font&gt;illustrates some&lt;/font&gt; of the capabilities of the &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; class. Throughout all of our demos, we will be working with a very simple table called &lt;font size="2" face="Courier New"&gt;GeometryDemo&lt;/font&gt;, which allows us to associate a Geometry instance with an integer ID: &lt;/p&gt;  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;   &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; GeometryDemo&lt;/pre&gt;

  &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt; (&lt;/pre&gt;

  &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt;     ID    &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;NOT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   4:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt; GEOMETRY &lt;span style="color:#0000ff;"&gt;NOT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;NULL&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   5:&lt;/span&gt; );&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;In the following code sample, we insert a &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; instance, and then perform a &lt;font size="2" face="Courier New"&gt;select&lt;/font&gt; to retrieve the point instance in a number of formats:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- Insert a simple Point with an&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- X and Y coordinate&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt; INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; GeometryDemo (ID, &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;)&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;VALUES&lt;/span&gt;    (1, &lt;span style="color:#006080;"&gt;&amp;#39;POINT(50 65)&amp;#39;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   6:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- Get the X and Y coordinates and &lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   7:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- the most relevant methods&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   8:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; ID, &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.ToString() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; WKT, &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   9:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STX &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [X Coordinate],                        &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  10:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STY &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [Y Coordinate],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  11:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STAsBinary() &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;Binary&lt;/span&gt; Representation],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  12:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STasText() &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; [Text Representation]&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  13:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; GeometryDemo&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  14:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; ID = 1;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In lines 3 and 4, we use the WKT format to insert a &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; with an X coordinate of 50 and a Y coordinate of 65. The WKT format for a &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt; simply requires you to to specify the X and Y coordinates. Note that you should NOT use a comma separator between the two, which might seem counterintuitive at first.&lt;/p&gt;

&lt;p&gt;In lines 8 through 14 we select the instance that we just inserted. Since &lt;font size="2" face="Courier New"&gt;Value&lt;/font&gt; is a geometry class instance, we need to use the&amp;#160; dot (&amp;quot;.&amp;quot;) notation to access properties and invoke methods on the object:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In line 8 we invoke the &lt;font size="2" face="Courier New"&gt;ToString()&lt;/font&gt; method. This method will return the Well-Known Text (WKT) representation of the instance. &lt;/li&gt;

  &lt;li&gt;In lines 9 and 10 we invoke the &lt;font size="2" face="Courier New"&gt;STX&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;STY&lt;/font&gt; properties to get the X and Y coordinates of our &lt;font size="2" face="Courier New"&gt;Point.&lt;/font&gt; &lt;/li&gt;

  &lt;li&gt;In line 11 we invoke the &lt;font size="2" face="Courier New"&gt;STAsBinary()&lt;/font&gt; method to get the binary representation of the &lt;font size="2" face="Courier New"&gt;Point&lt;/font&gt;. &lt;/li&gt;

  &lt;li&gt;Finally, in line 12 we invoke the &lt;font size="2" face="Courier New"&gt;STAsText()&lt;/font&gt; method, which will again return the WKT format of the &lt;font size="2" face="Courier New"&gt;Point.&lt;/font&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One important note: although TSQL by itself is not case sensitive, the CLR methods and properties on the spatial data types are, so make sure that you spell the property and method names correctly! For example if you would spell &amp;quot;&lt;font size="2" face="courier ne"&gt;Value.STAsText()&amp;quot;&lt;/font&gt; as &amp;quot;&lt;font size="2" face="Courier New"&gt;Value.STasText()&amp;quot;&lt;/font&gt; you would get the following error message:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; Msg 6506, &lt;span style="color:#0000ff;"&gt;Level&lt;/span&gt; 16, &lt;span style="color:#0000ff;"&gt;State&lt;/span&gt; 10, Line 34&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt; Could &lt;span style="color:#0000ff;"&gt;not&lt;/span&gt; find method &lt;span style="color:#006080;"&gt;&amp;#39;STasText&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;for&lt;/span&gt; type &lt;span style="color:#006080;"&gt;&amp;#39;Microsoft.SqlServer.Types.SqlGeometry&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; assembly &lt;span style="color:#006080;"&gt;&amp;#39;Microsoft.SqlServer.Types&amp;#39;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
The output of the select query is shown below:&lt;/div&gt;

&lt;p&gt;&lt;a title="OutputSimplePoint" href="http://www.flickr.com/photos/99548241@N00/2919284043/"&gt;&lt;img border="0" alt="OutputSimplePoint" src="http://static.flickr.com/3004/2919284043_bdd89474de.jpg" width="725" height="83" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above output, we see that the WKT representation for the &lt;font size="2" face="Courier New"&gt;Point &lt;/font&gt;is returned by both the &lt;font size="2" face="Courier New"&gt;ToString()&lt;/font&gt; and the &lt;font size="2" face="Courier New"&gt;STAsText()&lt;/font&gt; methods. We also see the binary WKB representation and the X and Y coordinates of the &lt;font size="2" face="Courier New"&gt;Point &lt;/font&gt;instance.&lt;/p&gt;

&lt;h5&gt;Using the Z and M coordinates&lt;/h5&gt;

&lt;p&gt;As we mentioned earlier, a Point can optionally contain a Z (Elevation) coordinate and a M (Measurement) value. Note that both the Z and M values should be floats. Below is a T-SQL example:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- Insert a Point with an X, Y, Z and&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- M coordinate&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt; INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; GeometryDemo (ID, &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;)&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;VALUES&lt;/span&gt; (2, &lt;span style="color:#006080;"&gt;&amp;#39;POINT(55 70 100.2 50)&amp;#39;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   6:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; ID, &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.ToString() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; WKT, &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   7:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STX &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [X Coordinate],                        &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   8:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.STY &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [Y Coordinate],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   9:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.Z &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [Elevation],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  10:&lt;/span&gt;            &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.M &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [Measure]&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  11:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; GeometryDemo&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  12:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; ID = 2;&lt;/pre&gt;
  &lt;/div&gt;
As you can see, we simply added the Z and M values in the WKT format. The output of the select query is shown below:&lt;/div&gt;

&lt;p&gt;&lt;a title="OutputAdvancedPoint2" href="http://www.flickr.com/photos/99548241@N00/2920160158/"&gt;&lt;img border="0" alt="OutputAdvancedPoint2" src="http://static.flickr.com/3211/2920160158_0e78117127.jpg" width="571" height="85" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;&lt;/h5&gt;

&lt;h5&gt;OGC-compliant methods and Microsoft Extensions&lt;/h5&gt;

&lt;p&gt;The attentive observer probably noticed that some method and properties have an &lt;strong&gt;ST&lt;/strong&gt; prefix (such as &lt;font size="2" face="Courier New"&gt;STX&lt;/font&gt;, &lt;font size="2" face="courier n"&gt;STY&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;STAsText()&lt;/font&gt;), while other properties and methods do NOT have this prefix (for example: &lt;font size="2" face="Courier New"&gt;Z&lt;/font&gt;, &lt;font size="2" face="Courier New"&gt;M&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;ToString()&lt;/font&gt;). All methods and properties that are prefixed with &lt;strong&gt;ST&lt;/strong&gt; are OGC-compliant methods, while the other methods and properties are Microsoft extensions to the OGC standard.&lt;/p&gt;

&lt;p&gt;In the documentation you will notice that the OGC standard methods and the Microsoft extensions are cleanly separated:&lt;/p&gt;

&lt;p&gt;&lt;a title="OGCMethodsAndExtensions" href="http://www.flickr.com/photos/99548241@N00/2941793987/"&gt;&lt;img border="0" alt="OGCMethodsAndExtensions" src="http://static.flickr.com/3156/2941793987_a96dac7eba.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above diagram we also see sections for static methods (both OGC and Microsoft extensions). We will take a look at static methods in a later section of this post.&lt;/p&gt;

&lt;h5&gt;Geography Markup Language (GML)&lt;/h5&gt;

&lt;p&gt;The only format that we have not worked with so far is the Geographic Markup Language (GML), let&amp;#39;s write a query to retrieve both points as GML:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#008000;"&gt;--    Select both Points as GML&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#008000;"&gt;--  Note that we are NOT retrieving the Z and M&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt; &lt;span style="color:#008000;"&gt;--  coordinates of the second point&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   4:&lt;/span&gt; &lt;span style="color:#008000;"&gt;--  because they are NOT OGC compliant!&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   5:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; ID, &lt;span style="color:#0000ff;"&gt;Value&lt;/span&gt;.AsGml() &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; [GML]&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   6:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; GeometryDemo;&lt;/pre&gt;
  &lt;/div&gt;
The &lt;font size="2" face="Courier New"&gt;AsGml()&lt;/font&gt; method can be used to retrieve a geometry instance in GML format. &lt;/div&gt;

&lt;p&gt;The output of the query is shown below:&lt;/p&gt;

&lt;p&gt;&lt;a title="OutputPointGML" href="http://www.flickr.com/photos/99548241@N00/2920194036/"&gt;&lt;img border="0" alt="OutputPointGML" src="http://static.flickr.com/3195/2920194036_69a4f0766f.jpg" width="553" height="107" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The standard XML namespace for GML will have the URN: &lt;a href="http://www.opengis.net/gml"&gt;http://www.opengis.net/gml&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;There is also one important note that we can make from the above output: the &lt;font size="2" face="Courier New"&gt;Z&lt;/font&gt; and &lt;font size="2" face="Courier New"&gt;M&lt;/font&gt; coordinates that we used for the second point are NOT returned in the GML! That is because they are proprietary Microsoft extensions to the OGC standard.&lt;/p&gt;

&lt;h5&gt;Using the static Point methods&lt;/h5&gt;

&lt;p&gt;The methods and properties we have used so far were invoked on an instance of the Point class, so we used the &amp;quot;dot&amp;quot; (.) notation:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;instanceName.Property &lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;-or-&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;instanceName.MethodCall(... method arguments here ...)&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instance properties and methods are always tied to a particular object &lt;strong&gt;instance&lt;/strong&gt;, in this case a Point instance. Besides instance methods, the spatial data types in SQL Server 2008 also use static methods and properties. Static methods and properties are tied to the &lt;strong&gt;class&lt;/strong&gt; itself, and can thus be invoked without having an instance around. You use the &amp;quot;::&amp;quot; notation in combination with the class name to invoke a static method or property in T-SQL:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;className::Property&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;-or-&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;className::MethodCall()&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One frequent usage pattern for a static method is the Factory Pattern. The Factory Pattern returns a new instance of the class through a static method. This pattern is used in both geospatial types in SQL Server 2008. Below is a code example from the &lt;font size="2" face="Courier New"&gt;GeometryPoint.sql&lt;/font&gt; T-SQL script:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; /* ========================================================================= &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt;    ======= &lt;span style="color:#0000ff;"&gt;Using&lt;/span&gt; the &lt;span style="color:#0000ff;"&gt;Static&lt;/span&gt; methods &lt;span style="color:#0000ff;"&gt;to&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;create&lt;/span&gt; a Point Instance =============&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt;    ========================================================================= */&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @Pnt1 Geometry, @Pnt2 Geometry, @Pnt3 Geometry, @Pnt4 Geometry, @Pnt5 Geometry&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   5:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @xmlSnippet xml;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   7:&lt;/span&gt; &lt;span style="color:#008000;"&gt;--    1. Create a Point from an X and Y coordinate and an SRID&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   8:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt1 = geometry::Point(30, 20, 0);&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  10:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- 2. Create a Point using the Parse method&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  11:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt2 = geometry::Parse(&lt;span style="color:#006080;"&gt;&amp;#39;POINT( 90 23 56000 231)&amp;#39;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  13:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- 3. Create a Point using the OGC STPointFromText method&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  14:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- Notice the SRID at the end&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  15:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt3 = geometry::STPointFromText(&lt;span style="color:#006080;"&gt;&amp;#39;POINT(20 25)&amp;#39;&lt;/span&gt;, 0)&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  17:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- 4. Create a Point from GML &lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  18:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; @xmlSnippet = &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  19:&lt;/span&gt;     &lt;span style="color:#006080;"&gt;&amp;#39;&amp;lt;Point xmlns=&amp;quot;http://www.opengis.net/gml&amp;quot;&amp;gt; &amp;lt;pos&amp;gt;34 23&amp;lt;/pos&amp;gt; &amp;lt;/Point&amp;gt;&amp;#39;&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  20:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt4 = geometry::GeomFromGml(@xmlSnippet, 0);&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  21:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  22:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- 5. Null Point&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  23:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt5 = geometry::[&lt;span style="color:#0000ff;"&gt;Null&lt;/span&gt;];&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  25:&lt;/span&gt; &lt;span style="color:#008000;"&gt;-- Now select all points&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  26:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; @Pnt1.ToString() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;From&lt;/span&gt; Arguments],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  27:&lt;/span&gt;        @Pnt2.ToString() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;From&lt;/span&gt; Parse],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  28:&lt;/span&gt;        @Pnt3.ToString() &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;From&lt;/span&gt; STPointFromText],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  29:&lt;/span&gt;        @Pnt4.ToString() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;From&lt;/span&gt; Xml],&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;  30:&lt;/span&gt;        @Pnt5 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; [&lt;span style="color:#0000ff;"&gt;Null&lt;/span&gt; Point];&lt;/pre&gt;
  &lt;/div&gt;
Following is a discussion of each static method:&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;In line 8, we use the static &lt;font size="2" face="Courier New"&gt;geometry::Point()&lt;/font&gt; method to create a Point instance by passing in the X, Y, Z and M coordinates. &lt;/li&gt;

  &lt;li&gt;In line 11, we use the &lt;font size="2" face="Courier New"&gt;geometry::Parse()&lt;/font&gt; method to create a Point instance from Well-Known Text (WKT). &lt;/li&gt;

  &lt;li&gt;In line 15, we use the &lt;font size="2" face="Courier New"&gt;geometry::STPointFromText()&lt;/font&gt; method to create a Point instance from Well-Known Text. The is the OGC equivalent of the &lt;font size="2" face="Courier New"&gt;geometry::Parse()&lt;/font&gt; method. &lt;/li&gt;

  &lt;li&gt;In line 18, we have an example of how to create a Point instance from a Geographic Markup Language (GML) snippet, using the static &lt;font size="2" face="Courier New"&gt;geometry::GeomFromGml()&lt;/font&gt; method. &lt;/li&gt;

  &lt;li&gt;Finally, in line 23 we create a &lt;font size="2" face="Courier New"&gt;NULL&lt;/font&gt; Point instance with the static &lt;font size="2" face="Courier New"&gt;geometry::[Null]&lt;/font&gt; property. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output of the select statement is shown below:&lt;/p&gt;

&lt;p&gt;&lt;a title="StaticPointMethods" href="http://www.flickr.com/photos/99548241@N00/2941817723/"&gt;&lt;img border="0" alt="StaticPointMethods" src="http://static.flickr.com/3013/2941817723_30bfba9626.jpg" width="544" height="44" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can conclude from the above output, the expected Point instances were created by means of the static methods.&lt;/p&gt;

&lt;h5&gt;The Spatial Reference Identifier&lt;/h5&gt;

&lt;p&gt;In the previous code sample, you might have noticed the &amp;quot;0&amp;quot; after the &lt;font size="2" face="Courier New"&gt;@xmlSnippet&lt;/font&gt; parameter:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;
    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; @xmlSnippet = &lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   2:&lt;/span&gt;     &lt;span style="color:#006080;"&gt;&amp;#39;&amp;lt;Point xmlns=&amp;quot;http://www.opengis.net/gml&amp;quot;&amp;gt; &amp;lt;pos&amp;gt;34 23&amp;lt;/pos&amp;gt; &amp;lt;/Point&amp;gt;&amp;#39;&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style:none;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @Pnt4 = geometry::GeomFromGml(@xmlSnippet, 0);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This argument is the SRID, or the Spatial Reference Identifier. The SRID corresponds to a spatial reference system based upon the specific ellipsoid used for either flat-earth or round-earth mapping. Different projection systems exist, some of you might be familiar with the Mercator Projection that was used to create the maps that were in most classrooms in recent times. A good discussion of map projections can be found at: &lt;a title="http://maps.unomaha.edu/Peterson/gis/notes/MapProjCoord.html" href="http://maps.unomaha.edu/Peterson/gis/notes/MapProjCoord.html"&gt;http://maps.unomaha.edu/Peterson/gis/notes/MapProjCoord.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Each projection is uniquely defined by its own SRID. You can use any projection you want, but you need to be aware that when you are comparing spatial instances using any of the methods (such as &lt;font size="2" face="Courier New"&gt;STIntersection()&lt;/font&gt;) you need to make sure that all objects have the &lt;strong&gt;same&lt;/strong&gt; SRID otherwise you will get a run-time error!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;That concludes part 2 of this series. In part three, we take a look at the LineString and the Polygon class, and we will use some visualization tools such as &lt;a href="http://www.conceptdevelopment.net/Database/Geoquery/"&gt;GeoQuery&lt;/a&gt;, &lt;a href="http://www.codeplex.com/SpatialViewer"&gt;Spatial Viewer&lt;/a&gt;, and SQL Server Management Studio&amp;#39;s very own &amp;quot;Spatial Tab&amp;quot; to get a visual representation of our spatial data!&lt;/p&gt;&lt;img src="http://footheory.com/aggbug.aspx?PostID=415" width="1" height="1"&gt;</description><category domain="http://footheory.com/blogs/bennie/archive/tags/SQL+Server+2008/default.aspx">SQL Server 2008</category><category domain="http://footheory.com/blogs/bennie/archive/tags/Spatial+Data/default.aspx">Spatial Data</category><category domain="http://footheory.com/blogs/bennie/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://footheory.com/blogs/bennie/archive/tags/TSQL/default.aspx">TSQL</category></item></channel></rss>