<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Developer&#039;s Blog &#187; spatial data</title>
	<atom:link href="http://blog.hoegaerden.be/tag/spatial-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hoegaerden.be</link>
	<description>SQL Server, BI, .NET, IT and anything else I have been playing with.</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:15:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Drawing In SQL Server 2008</title>
		<link>http://blog.hoegaerden.be/2010/02/26/drawing-in-sql-server-2008/</link>
		<comments>http://blog.hoegaerden.be/2010/02/26/drawing-in-sql-server-2008/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 21:18:34 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Hoegaarden]]></category>
		<category><![CDATA[spatial data]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/02/26/drawing-in-sql-server-2008/</guid>
		<description><![CDATA[A while ago I had been playing a bit with the new spatial data types in SQL Server 2008.  Not only can SQL Server store such data, it can also visualize it.  So I had come up with the following query: select geometry::STPolyFromText ('POLYGON((1 1, 1.5 1.85, 2.5 1.85, 3 1, 2.5 0.15, 1.5 0.15, [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I had been playing a bit with <a title="SQL Serve 2008: Spatial Data" href="http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx" target="_blank">the new spatial data types in SQL Server 2008</a>.  Not only can SQL Server store such data, it can also visualize it.  So I had come up with the following query:</p>
<pre class="code"><span style="color: blue;">select geometry</span><span style="color: gray;">::</span>STPolyFromText
<span style="color: gray;">(</span><span style="color: red;">'POLYGON((1 1, 1.5 1.85, 2.5 1.85, 3 1, 2.5 0.15, 1.5 0.15, 1 1),
(1.5 1.5, 1.5 0.5, 1.7 0.5, 1.7 0.9, 2.3 0.9, 2.3 0.5, 2.5 0.5, 2.5 1.5, 2.3 1.5,
2.3 1.1, 1.7 1.1, 1.7 1.5, 1.5 1.5))'</span><span style="color: gray;">, </span>0<span style="color: gray;">);
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Running that in the Management Studio produces something like this on the <strong>Spatial results</strong> tab:</p>
<p><img style="display: inline; border: 0px;" title="Hoegaerden - the polygon" src="http://blog.hoegaerden.be/wp-content/uploads/image193.png" border="0" alt="Hoegaerden - the polygon" width="486" height="404" /></p>
<p>I’m using the <a title="BOL 2008: STPolyFromText (geometry Data Type)" href="http://msdn.microsoft.com/en-us/library/bb933922.aspx" target="_blank">STPolyFromText</a> function to produce a six-sided polygon with a letter H in the center.  To get to the result, I’m passing a bunch of XY coordinates to the function.  A line gets drawn between two coordinates following each other.</p>
<p>The first list of coordinates (the first list of numbers enclosed in round brackets) creates the hexagon while the second list produces the letter H.  Each <em>list of coordinates</em> thus represents one <strong>polygon</strong>.   The starting XY coordinate must be equal to the ending coordinate to form a closed shape.  The shape is then filled with a color.  Overlapping shapes will be filled using different colors, as shown above.</p>
<p>Producing these coordinates was quite interesting: to be able to calculate the angled sides of the hexagon I used the following formulas.</p>
<p>With <strong>S</strong> being <em>the length of one side</em>:</p>
<p>Width = 2 * S</p>
<p>Height = S * SQRT(3)</p>
<p><strong>Note:</strong> these formulas are only applicable when the hexagon is rotated as shown above.</p>
<p>I needed to know these distances to be able to calculate how much I should increase the X/Y coordinates to get to the next connector.</p>
<p>Okay, enough theory, back to the story now.</p>
<p>Q: “So, why are you creating a helipad platform?”</p>
<p>A: No, it’s not supposed to look like a helipad platform.  The shape resembles the beer coasters for the beer called Hoegaarden.  And those coasters always have a funny drawing or comment on them.  Let’s see if I can find one that’s understandable for non-native Dutch-speakers…</p>
<p><em>(And half an hour later – turns out it’s really not easy to find one without text – luckily they’ve also created some in English!)</em></p>
<p><img style="display: inline; border: 0px;" title="Hoegaarden beer coaster" src="http://blog.hoegaerden.be/wp-content/uploads/image194.png" border="0" alt="Hoegaarden beer coaster" width="640" height="556" /></p>
<p>Initially I was planning on writing a longer article about the spatial data types but hadn’t found the time to do it yet.  And then a couple of days ago I came across a challenge that made me think of this query and so now I’m publishing it in this post.</p>
<p>The challenge to which I’m referring was started by Itzik Ben-Gan and is called <a title="Geekiest Sig Challenge" href="http://www.sqlmag.com/Articles/ArticleID/103518/103518.html" target="_blank">Geekiest Sig Challenge</a>.  The point is to use the new SQL Server spatial data types to create a signature for yourself.  Well, a perfect description for my query!</p>
<p>I was happy to just get an H on there, getting those coordinates right without first putting it on paper is really a challenge <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   And on top of that, I was never any good at drawing.  I remember in secondary school we got an assignment to draw a tree.  Any tree.  So at home I looked out the window and started drawing the tree.  I ended up with the most atrocious thing I’d ever seen (well, that may be a bit exaggerated), it could have starred in a Hitchcock movie straight away, really spiky, and probably spooky when encountered in the dark and with the right background noises playing.</p>
<p>Anyway, what I wanted to say, some people are just talented: check out <a title="More images from the Spatial Results tab" href="http://michaeljswart.com/?p=564" target="_blank">this submission by Michael J. Swart</a>!  No further words needed.</p>
<p>Right, enough geeky stuff to close the week, and remember: have fun!</p>
<p><em>(Hmm, now I’ve got something to build my favicon from…)</em></p>
<p>Valentino.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2010%2F02%2F26%2Fdrawing-in-sql-server-2008%2F&amp;title=Drawing%20In%20SQL%20Server%202008" id="wpa2a_2"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/02/26/drawing-in-sql-server-2008/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

