<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
This may be more complicated than is desired, but this algorithm is one I will keep in my tool box for ascertaining if a point is in a polygon:<br>http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/<br>I modified this to be a function in a php object, but the concept is great.<br><br>-Daniel<br><br><hr id="stopSpelling">Date: Tue, 30 Mar 2010 13:39:24 -0700<br>From: strebe@aol.com<br>To: proj@lists.maptools.org<br>Subject: Re: [Proj] Coordinate within an area ?<br><br>
<div><span class="ecxApple-style-span"><br></span></div><div id="ecxreplyPrefaceElement">On Mar 30, 2010, at 9:49:39 AM, "Karl Swartz" <karl@kls2.com> wrote:</div><br><blockquote style="border-left: 2px solid blue; padding-left: 5px; margin-left: 5px; color: blue;"><span class="ecxApple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="ecxApple-style-span" style="font-family: monospace; font-size: 11px;">For the azimuth calculations, you can use Vincenty or similar if you<br>want high accuracy, or but you said small errors are acceptable so<br>basic spherical geometry may suffice.<br></span></span></blockquote><div><span class="ecxApple-style-span">The accuracy is not important, since the value of the azimuth does not matter; only its relative geometry does. The geometry is the same on the sphere and the ellipsoid except when the polygon include antipodes. If the polygon is that large then you need to consider more. You need to consider the very definition of "inside", since this is a closed surface we're talking about. None of the responses so far have addressed this problem.<br><div><span class="ecxApple-style-span" style=""><br></span></div><div><span class="ecxApple-style-span" style="">Regards,<div><span class="ecxApple-style-span" style="">— daan Strebe<div><span class="ecxApple-style-span" style=""><br></span></div></span></div></span></div><div><span class="ecxApple-style-span" style=""><br></span></div><div><div id="ecxreplyPrefaceElement">On Mar 30, 2010, at 9:49:39 AM, "Karl Swartz" <karl@kls2.com> wrote:</div><br><blockquote style="border-left: 2px solid blue; padding-left: 5px; margin-left: 5px; color: blue;"><span class="ecxApple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div id="ecxfelix-mail-header-block" style="border-bottom: 1px solid silver; color: black; background-color: white; padding-bottom: 1em; margin-bottom: 1em; width: 749px;"><table border="0" cellpadding="1" cellspacing="1" width="100%"><tbody><tr><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: gray; text-align: right; vertical-align: top; font-weight: bold;" width="70px"><span>From:</span></td><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: black; text-align: left; vertical-align: top; padding-left: 5px;"><span title=""Karl Swartz" <karl@kls2.com>">"Karl Swartz" <karl@kls2.com></span></td></tr><tr><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: gray; text-align: right; vertical-align: top; font-weight: bold;" width="70px"><span>Subject:</span></td><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: black; text-align: left; vertical-align: top; padding-left: 5px;"><span style="font-weight: bold;">Re: [Proj] Coordinate within an area ?</span></td></tr><tr><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: gray; text-align: right; vertical-align: top; font-weight: bold;" width="70px"><span>Date:</span></td><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: black; text-align: left; vertical-align: top; padding-left: 5px;"><span>March 30, 2010 9:49:39 AM PDT</span></td></tr><tr><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: gray; text-align: right; vertical-align: top; font-weight: bold;" width="70px"><span>To:</span></td><td style="font-family: 'Lucida Grande'; font-size: 8pt; color: black; text-align: left; vertical-align: top; padding-left: 5px;"><span title=""PROJ.4 and general Projections Discussions" <proj@lists.maptools.org>">"PROJ.4 and general Projections Discussions" <proj@lists.maptools.org></span></td></tr></tbody></table></div><div id="ecxfelix-mail-content-block" style="color: black; background-color: white; width: 749px;"><div style="font-family: monospace; color: black; background-color: white; font-size: 8pt;">> > My next questions would be: (1) how accurate does it need to be? and (2)<br>> > If it is done everywhere in the world, what projection to use to reduce<br>> > error?<br><br>> 2/ We use global data, so it is everywhere in the world. I thought<br>> about using Lambert azimuthal equal-area projection.<br><br>If you're working with lat/lon coordinates why would you be using a<br>projection at all?<br><br>For a point and a simple polygon that's not enormous, I'd calculate<br>paths and compare angles. Consider triangle ABC as the polygon and<br>you want to determine if point P is inside the triangle. Compute the<br>initial azimuth paths AB, AC, and AP. Then, determine if P lies within<br>angle A:<br><br>if azim(AB) < azim(AC)<br>within(B) = azim(AP) > azim(AB) && azim(AP) < azim(AC)<br>else<br>within(B) = azim(AP) > azim(AC) && azim(AP) < azim(AB)<br><br>Repeat from angles B and C and if P is within all three angles then P<br>is within the triangle, otherwise it is not.<br><br>Note that the comparisons I used treat the boundaries of the triangle<br>as "not within" -- change the "within" comparisons to >= and <= to<br>include the boundaries of the polygon.<br><br>This algorithm can be trivially generalized to any convex n-sided<br>polygon.<br><br>For the azimuth calculations, you can use Vincenty or similar if you<br>want high accuracy, or but you said small errors are acceptable so<br>basic spherical geometry may suffice.<br><br>-- Karl</div><div><font class="ecxApple-style-span" face="monospace" size="3"><span class="ecxApple-style-span" style="font-size: 11px;"><br></span></font></div></div></span></blockquote></div></span></div><div class="ecxaol_ad_footer" id="ecxu98F17E3903DF41488ECD6F483E70D74D"></div> <br /><hr />Hotmail: Trusted email with Microsoft’s powerful SPAM protection. <a href='http://clk.atdmt.com/GBL/go/210850552/direct/01/' target='_new'>Sign up now.</a></body>
</html>