[Proj] Coordinate within an area ?

` ` teletautala at hotmail.com
Tue Mar 30 14:13:19 PDT 2010


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:
http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
I modified this to be a function in a php object, but the concept is great.

-Daniel

Date: Tue, 30 Mar 2010 13:39:24 -0700
From: strebe at aol.com
To: proj at lists.maptools.org
Subject: Re: [Proj] Coordinate within an area ?




On Mar 30, 2010, at 9:49:39 AM, "Karl Swartz" <karl at kls2.com> wrote:
For the azimuth calculations, you can use Vincenty or similar if you
want high accuracy, or but you said small errors are acceptable so
basic spherical geometry may suffice.
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.

Regards,— daan Strebe

On Mar 30, 2010, at 9:49:39 AM, "Karl Swartz" <karl at kls2.com> wrote:
From:"Karl Swartz" <karl at kls2.com>Subject:Re: [Proj] Coordinate within an area ?Date:March 30, 2010 9:49:39 AM PDTTo:"PROJ.4 and general Projections Discussions" <proj at lists.maptools.org>> > My next questions would be: (1) how accurate does it need to be? and (2)
> > If it is done everywhere in the world, what projection to use to reduce
> > error?

> 2/ We use global data, so it is everywhere in the world. I thought
> about using Lambert azimuthal equal-area projection.

If you're working with lat/lon coordinates why would you be using a
projection at all?

For a point and a simple polygon that's not enormous, I'd calculate
paths and compare angles. Consider triangle ABC as the polygon and
you want to determine if point P is inside the triangle. Compute the
initial azimuth paths AB, AC, and AP. Then, determine if P lies within
angle A:

if azim(AB) < azim(AC)
within(B) = azim(AP) > azim(AB) && azim(AP) < azim(AC)
else
within(B) = azim(AP) > azim(AC) && azim(AP) < azim(AB)

Repeat from angles B and C and if P is within all three angles then P
is within the triangle, otherwise it is not.

Note that the comparisons I used treat the boundaries of the triangle
as "not within" -- change the "within" comparisons to >= and <= to
include the boundaries of the polygon.

This algorithm can be trivially generalized to any convex n-sided
polygon.

For the azimuth calculations, you can use Vincenty or similar if you
want high accuracy, or but you said small errors are acceptable so
basic spherical geometry may suffice.

-- Karl
 		 	   		  
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/210850552/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20100330/f693bce6/attachment.html>


More information about the Proj mailing list