Solved

Find if a geographical point lies within a set of points making a polygon

Posted on 2014-01-22
8
544 Views
Last Modified: 2014-02-11
Given a set of geographical coordinates making up a polygon, how would I determine if another geographical point (x-latitude, y-longitude) lies either within the polygon, or outside the polygon. The set of coordinates is stored in a table in an SQL server database.
0
Comment
Question by:websss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:Paul 1
ID: 39802256
The first process is to create a virtual box around the polygon. This gives you a top, bottom, left and right value to see if the target point is close ( T > bottom, T < Top, T > Left and T < Right)

If the value is confirmed then you work out the 3 nearest point to form a triangle and then calculate - check this to see the theory - http://www.blackpawn.com/texts/pointinpoly/

also this explains - http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-triangle
0
 
LVL 16

Expert Comment

by:gurutc
ID: 39803078
Are you using  LatLon, UTM, UPS, MGRS, MGRS Polar, USNG (identical to MGRS), Georef, or State Plane coordinate systems?  Depending on the coordinate format, it'll be an algebraic equation.

- gurutc
0
 
LVL 16

Expert Comment

by:gurutc
ID: 39803081
Also, what type of polygon?  How many points?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 200 total points
ID: 39803680
I used a nice algorithm favorised in raytraycing for this. It counts the number of intersections with a line drawn from the test point and any polygon borders. If that's odd the test point is inside, if it's even the point is not.

Sounds complicated, but if you draw a line exactly in x or latitude direction the determination of intersections gets very simple, also considering you only need to find out, whether there is an intersection with a polygon border, not the point of the intersection.

The algorithm is in the book "An Introduction to Ray Tracing".  Simple logic:

If both y positions of start and end point of a line are below your test point y position, that  means no intersection. Dito, if both y positions are above the test point y position. If one is above and one below, there also is no intersection, if that line crosses the test point y position at an x position before the test point x position. You only need to calculate this, if one of  the x positions is lower and one higher than your test point x position, if both are lower, there is no intersection, as you only want to count intersections in x directions higher than the test point.

You get the idea:  Mostly this is just comparsions, no intersection point calculations. This is used for fast ray traycing and can be applied to your case, too.

Bye, Olaf.

By the way: If you thought there was a simple INSIDEPOLYGON T-SQL Function or system stored proc, I fear that's not the case.
0
 

Author Comment

by:websss
ID: 39805705
@gurutc, I am using LatLon
0
 
LVL 16

Expert Comment

by:gurutc
ID: 39806255
Degree-Decimal?
0
 

Author Comment

by:websss
ID: 39806264
Decimal..
0
 
LVL 16

Accepted Solution

by:
gurutc earned 300 total points
ID: 39806289
The OpenLayers Project has a library of javascript code to perform this function as well as many more.

Their repository and library are here:

OpenLayers Code Collection

This type of function is pretty complex.  But that collection contains the code to do it.

- gurutc
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question