<?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>MaisonBisson.com &#187; MySQL spatial functions</title>
	<atom:link href="http://maisonbisson.com/blog/post/tag/mysql-spatial-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://maisonbisson.com</link>
	<description>A bunch of stuff I would have emailed you about.</description>
	<lastBuildDate>Mon, 23 Nov 2009 16:21:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Find Stuff By Minimum Bounding Rectangle</title>
		<link>http://maisonbisson.com/blog/post/12148/find-stuff-by-minimum-bounding-rectangle/</link>
		<comments>http://maisonbisson.com/blog/post/12148/find-stuff-by-minimum-bounding-rectangle/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 19:34:31 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[MBR]]></category>
		<category><![CDATA[minimum bounding rectangle]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL spatial functions]]></category>
		<category><![CDATA[spatial data]]></category>
		<category><![CDATA[spatial functions]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12148</guid>
		<description><![CDATA[
MySQL offers ENVELOPE() to find the minimum bounding rectangle of a geometric object.
The result is a polygon with four segments, defined by five points. It took me a while to make sense of it, partially because the only documentation that I&#8217;ve run across so far for POLYGON() syntax is in the ENVELOPE() function mentioned above. [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12148"><!-- &nbsp; --></abbr>
<p><a href="http://www.flickr.com/photos/maisonbisson/2568621754/" title="mbr mysql minimum bounding rectangle by misterbisson, on Flickr"><img src="http://farm4.static.flickr.com/3276/2568621716_b5eb180c55_o.png" width="245" height="245" alt="mbr mysql minimum bounding rectangle" style="float: right;" /></a>MySQL offers <code>ENVELOPE()</code> to <a href="http://dev.mysql.com/doc/refman/5.0/en/general-geometry-property-functions.html#function_envelope" title="MySQL :: MySQL 5.0 Reference Manual :: 18.5.2.1 General Geometry Functions">find the minimum bounding rectangle</a> of a geometric object.</p>
<p>The result is a polygon with four segments, defined by five points. It took me a while to make sense of it, partially because the only documentation that I&#8217;ve run across so far for <code>POLYGON()</code> syntax is in the <code>ENVELOPE()</code> function mentioned above. I also had to draw a picture to think it through.</p>
<p>They write this: <code>POLYGON(( MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY ))</code>, I think this (in pseudocode-ish form): <code>POLYGON(( $point_a, $point_b, $point_c, $point_d, $point_a ))</code>, with the <code>$point_</code>s corresponding to the diagram.</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12148/find-stuff-by-minimum-bounding-rectangle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working With Spatial Data in MySQL</title>
		<link>http://maisonbisson.com/blog/post/12147/working-with-spatial-data-in-mysql/</link>
		<comments>http://maisonbisson.com/blog/post/12147/working-with-spatial-data-in-mysql/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 16:41:45 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL spatial functions]]></category>
		<category><![CDATA[spatial data]]></category>
		<category><![CDATA[spatial functions]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12147</guid>
		<description><![CDATA[
It&#8217;s MySQL spatial data week here, though I am spreading out the posts to, um, ease the pain (or boredom). Anyway, here are some commands/functions I don&#8217;t want to forget about later:
Start with an existing table called geometry, add a spatial column and index it:

ALTER TABLE geometry ADD coord POINT NOT NULL;
CREATE SPATIAL INDEX coord [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12147"><!-- &nbsp; --></abbr>
<p>It&#8217;s MySQL spatial data week here, though I am spreading out the posts to, um, ease the pain (or boredom). Anyway, here are some commands/functions I don&#8217;t want to forget about later:</p>
<p>Start with an existing table called <code>geometry</code>, add <a href="http://dev.mysql.com/doc/refman/5.0/en/creating-spatial-columns.html">a spatial column</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/creating-spatial-indexes.html">index it</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">ALTER</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #999900; font-weight: bold;">geometry</span> <span style="color: #990099; font-weight: bold;">ADD</span> coord <span style="color: #999900; font-weight: bold;">POINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #FF9900; font-weight: bold;">SPATIAL</span> <span style="color: #990099; font-weight: bold;">INDEX</span> coord <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #999900; font-weight: bold;">geometry</span> <span style="color: #FF00FF;">&#40;</span>coord<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://dev.mysql.com/doc/refman/5.0/en/populating-spatial-columns.html">Insert</a> some data; think in terms of POINT(X Y) or POINT(lat lon):</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #999900; font-weight: bold;">geometry</span> <span style="color: #FF00FF;">&#40;</span>coord<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #00CC00;">GeomFromText</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">'POINT(40 -100)'</span> <span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #999900; font-weight: bold;">geometry</span> <span style="color: #FF00FF;">&#40;</span>coord<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #00CC00;">GeomFromText</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">'POINT(1 1)'</span> <span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>Get those <a href="http://dev.mysql.com/doc/refman/5.0/en/point-property-functions.html">X,Y coordinates</a> back from the table:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #00CC00;">X</span><span style="color: #FF00FF;">&#40;</span>coord<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #00CC00;">Y</span><span style="color: #FF00FF;">&#40;</span>coord<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #999900; font-weight: bold;">geometry</span></pre></div></div>

<p>Get points within a <a href="http://dev.mysql.com/doc/refman/5.0/en/relations-on-geometry-mbr.html" title="MySQL :: MySQL 5.0 Reference Manual :: 18.5.5 Relations on Geometry Minimal Bounding Rectangles (MBRs)">bounding rectangle</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #00CC00;">MBRContains</span><span style="color: #FF00FF;">&#40;</span>
	<span style="color: #00CC00;">GeomFromText</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">'POLYGON((0 0,0 3,3 3,3 0,0 0))'</span> <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	coord
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #999900; font-weight: bold;">geometry</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12147/working-with-spatial-data-in-mysql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Calculating Distance Between Points In MySQL</title>
		<link>http://maisonbisson.com/blog/post/12146/calculating-distance-between-points-in-mysql/</link>
		<comments>http://maisonbisson.com/blog/post/12146/calculating-distance-between-points-in-mysql/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 02:15:57 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[distance]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL spatial functions]]></category>
		<category><![CDATA[spatial functions]]></category>
		<category><![CDATA[unimplemented]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12146</guid>
		<description><![CDATA[
MySQL has some powerful, and perhaps underused spatial extensions, but the most interesting functions are still unimplemented: “Note: Currently, MySQL does not implement these functions&#8230;”
Among those as-yet unimplemented functions is DISTANCE(). Alternatives can be found here and here, though neither is clean or simple. I wonder if a simple MBRContains() is good enough, though&#8230;
]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12146"><!-- &nbsp; --></abbr>
<p>MySQL has some powerful, and perhaps underused <a href="http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html" title="MySQL :: MySQL 5.0 Reference Manual :: 18 Spatial Extensions">spatial extensions</a>, but the <a href="http://dev.mysql.com/doc/refman/5.0/en/functions-that-test-spatial-relationships-between-geometries.html" title="MySQL :: MySQL 5.0 Reference Manual :: 18.5.6 Functions That Test Spatial Relationships Between Geometries">most interesting functions</a> are still <a href="http://maisonbisson.com/blog/post/12145/mysql-documentation">unimplemented</a>: “Note: Currently, MySQL does not implement these functions&#8230;”</p>
<p>Among those as-yet unimplemented functions is <code>DISTANCE()</code>. Alternatives can be found <a href="http://www.zcentric.com/blog/2007/03/calculate_distance_in_mysql_wi.html" title="Calculate Distance In Mysql with Latitude and Longitude (My Random Blog)">here</a> and <a href="http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL" title="Geo Distance Search with MySQL">here</a>, though neither is clean or simple. I wonder if a simple <a href="http://dev.mysql.com/doc/refman/5.0/en/relations-on-geometry-mbr.html"><code>MBRContains()</code></a> is good enough, though&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12146/calculating-distance-between-points-in-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL Documentation</title>
		<link>http://maisonbisson.com/blog/post/12145/mysql-documentation/</link>
		<comments>http://maisonbisson.com/blog/post/12145/mysql-documentation/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 01:44:03 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Dispatches]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL spatial functions]]></category>
		<category><![CDATA[spatial functions]]></category>
		<category><![CDATA[unimplemented]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12145</guid>
		<description><![CDATA[
Found in the MySQL 5.0 Reference Manual:

Related(g1,g2,pattern_matrix)
Returns 1 or 0 to indicate whether the spatial relationship specified by pattern_matrix exists between g1 and g2. Returns –1 if the arguments are NULL. The pattern matrix is a string. Its specification will be noted here if this function is implemented.

(emphasis mine.)
]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12145"><!-- &nbsp; --></abbr>
<p>Found in the <a href="http://dev.mysql.com/doc/refman/5.0/en/functions-that-test-spatial-relationships-between-geometries.html" title="MySQL :: MySQL 5.0 Reference Manual :: 18.5.6 Functions That Test Spatial Relationships Between Geometries">MySQL 5.0 Reference Manual</a>:</p>
<ul>
<li>Related(g1,g2,pattern_matrix)<br />
Returns 1 or 0 to indicate whether the spatial relationship specified by pattern_matrix exists between g1 and g2. Returns –1 if the arguments are NULL. The pattern matrix is a string. <strong>Its specification will be noted here if this function is implemented</strong>.</li>
</ul>
<p>(emphasis mine.)</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12145/mysql-documentation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>