[Proj] Coordinate within an area ?

strebe strebe at aol.com
Tue Mar 30 13:39:24 PDT 2010


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 PDT
To: "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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20100330/20d9ec5b/attachment.html>


More information about the Proj mailing list