<?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>Artem&#039;s blog &#187; search</title>
	<atom:link href="http://artemgolubev.com/tag/search/feed/" rel="self" type="application/rss+xml" />
	<link>http://artemgolubev.com</link>
	<description>Thoughts on software</description>
	<lastBuildDate>Sat, 17 Dec 2011 01:52:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Approaches to search ZIP codes within given radius</title>
		<link>http://artemgolubev.com/approaches-to-search-zip-codes-within-given-radius/</link>
		<comments>http://artemgolubev.com/approaches-to-search-zip-codes-within-given-radius/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 03:10:26 +0000</pubDate>
		<dc:creator>Artem</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[zip code]]></category>

		<guid isPermaLink="false">http://artemgolubev.com/approaches-to-search-zip-codes-within-given-radius/</guid>
		<description><![CDATA[There are several approaches to get zip codes within given radius from given zip:

Round circle by square if zips given by points;
Exact 3D geometry calculate if zips given by points;
Exact GIS calculate if zips given by polygons.

Approximation by square
We approximate circle by square on surface, where:

latitude +- radius/EARTH_RADUIS
longitude +- radius/(EARTH_RADUIS*cos(latitude))

cos here is because longitudes distances [...]]]></description>
			<content:encoded><![CDATA[<p>There are several approaches to get zip codes within given radius from given zip:</p>
<ol>
<li>Round circle by square if zips given by points;</li>
<li>Exact 3D geometry calculate if zips given by points;</li>
<li>Exact GIS calculate if zips given by polygons.</li>
</ol>
<h4>Approximation by square</h4>
<p>We approximate circle by square on surface, where:</p>
<ol>
<li>latitude +- radius/EARTH_RADUIS</li>
<li>longitude +- radius/(EARTH_RADUIS*cos(latitude))</li>
</ol>
<p>cos here is because longitudes distances differ depending on latitudes (say, in polar it is 0).</p>
<p>The databases for 1999 is an accessible open source, but up to date database costs money. Free database:<br />
<a href="http://svn.baconbear.com/rails_plugins/acts_as_locateable/trunk/data/zip_code_data.csv">http://svn.baconbear.com/rails_plugins/acts_as_locateable/trunk/data/zip_code_data.csv</a></p>
<p>Open source database is about 42 000 records. Up to date is about 72 000. See, for instance:</p>
<ol>
<li><a href="http://www.zip-codes.com/">http://www.zip-codes.com/</a></li>
<li><a href="http://www.zip-code-database.org/">http://www.zip-code-database.org/</a>?</li>
<li><a href="http://www.google.com/search?q=zip+codes+database">http://www.google.com/search?q=zip+codes+database</a>?</li>
</ol>
<h4>Exact 3D calculations</h4>
<p>3D coordinates:</p>
<ol>
<li>x= EARTH_RADIUS*sin(latitude)*cos(longitude)</li>
<li>y= EARTH_RADIUS*sin(latitude)*sin(longitude)</li>
<li>z= EARTH_RADIUS*cos(latitude)</li>
</ol>
<p>Search points must be within sphere:</p>
<p>x*x + y*y + z*z &lt;= radius*radius</p>
<p>It is non-efficient table full-scan implementation.</p>
<p>See <a href="http://en.wikipedia.org/wiki/Spherical_coordinate_system">http://en.wikipedia.org/wiki/Spherical_coordinate_system</a></p>
<h4>Exact zip polygon databases</h4>
<p>Here you have to install open-source PostGIS (<a href="http://postgis.refractions.net/">http://postgis.refractions.net/</a>) system on your PostgreSQL and buy zip codes polygon database.<br />
After installing PostGIS you can query zip codes within given radius the next way (<a href="http://postgis.refractions.net/pipermail/postgis-users/2007-February/014760.html">http://postgis.refractions.net/pipermail/postgis-users/2007-February/014760.html</a>):</p>
<p><code>SELECT z.zipcode FROM zipcode z, zipcode z2 WHERE z2.zipcode = '02109' AND expand(z2.the_geom, "whatever radius you want goes here but your spatial ref needs to be in that metric or you need to convert the radius") &amp;&amp; z.the_geom AND distance(z.the_geom, z2.the_geom) &lt;= "radius"</code></p>
<p>Zip codes polygon databases:</p>
<ol>
<li><a href="http://maps.huge.info/blog/2007/04/zip_code_polygon_databases.html">http://maps.huge.info/blog/2007/04/zip_code_polygon_databases.html</a></li>
<li><a href="http://www.google.com/search?q=zip+codes+poligon+database">http://www.google.com/search?q=zip+codes+poligon+database</a></li>
</ol>
<p>Or, if you use RoR, you can use the following plugins:</p>
<ul>
<li>YM4R/GM (<a href="http://agilewebdevelopment.com/plugins/ym4r_gm">http://agilewebdevelopment.com/plugins/ym4r_gm</a>),</li>
<li>GeoKit (<a href="http://geokit.rubyforge.org/">http://geokit.rubyforge.org/</a>).</li>
</ul>
<p>As far as I understand they use Google API, so they have some restrictions.</p>
]]></content:encoded>
			<wfw:commentRss>http://artemgolubev.com/approaches-to-search-zip-codes-within-given-radius/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

