How to get data only inside polygon using opengl

      Hiii, Help me out..I open a image which is map with points using opengl.The points which are on map is a huge set of data stored in a file.This file has 2 columns which is latitude & longitude of a region. Now Using GL_POINTS & GL_LINE i draw a polygon on this image. Now what i need is i want only points or data related to points from the file which are thier only inside polygon. I mean to say the points which i click on image forms a loop & i join this points using GL_LINE which form a polygon on the entire region of image.I want data of only those pints which are inside this polygon. Please help me out atleast give me few links.

i want a program or small function which takes data from the entire region data file & points clicked by user & then comparing this , it takes data from the file & stores data in another file such that for data which is only in the region of points or for data which is only inside the polygon.
In short i want program which stores the data in another file only polygon region’s data not the entire region of the file.
Please please Help me out.
For exampl:
Few lines of the file data are as follows
a.dat:


   BDA 1908  8 20  9 53  0.00  32.0000N  89.0000E  60.0   0 0.00   0 0.00 0.00  6.60   0  7.00  7.00   0 bbb
   BDA 1915 12  3  2 39 19.00  29.5000N  91.5000E  60.0   0 0.00   0 0.00 0.00  6.70   0  7.10  7.10   0 bbb
   SIG 1927  5 22  0  0  0.00  36.0000N  96.0000E   0.0   0 0.00   0 0.00 0.00  7.50   0  8.00  8.00   0 bbb
   BDA 1934 12 15  1 57 37.00  31.3000N  89.3000E  60.0   0 0.00   0 0.00 0.00  6.70   0  7.10  7.10   0 bbb
   SIG 1937  1  7  0  0  0.00  35.5000N  98.0000E   0.0   0 0.00   0 0.00 0.00  7.10   0  7.60  7.60   0 bbb
   LEE 1937  1  7 13 20 41.00  35.5000N  97.6000E   0.0   0 0.00   0 0.00 0.00  7.10   0  7.60  7.60  10 bbb
   SIG 1947  7 29  0  0  0.00  28.5000N  94.0000E  60.0   0 0.00   0 0.00 0.00  7.30   0  7.80  7.80   0 bbb
   BDA 1947  7 29 13 43 22.00  28.5000N  94.0000E  60.0   0 0.00   0 0.00 0.00  7.40   0  7.90  7.90   0 aaa
   G-R 1950  8 15 14  9 30.00  28.5000N  96.5000E  25.0   0 0.00   0 0.00 0.00  8.10   0  8.70  8.70  10 aaa
   ISS 1950  9 13 11  7 27.00  27.5000N  96.4000E   0.0   0 0.00   0 0.00 0.00  6.60   0  7.00  7.00   7 sss
   G-R 1951 11 18  9 35 47.00  30.5000N  91.0000E  25.0   0 0.00   0 0.00 0.00  7.40   0  7.90  7.90   4 mmm
   LEE 1951 11 18  9 35 50.00  31.1000N  91.4000E   0.0   0 0.00   0 0.00 0.00  7.50   0  8.00  8.00   0 ppp
   G-R 1952  8 17 16  2  7.00  30.5000N  91.5000E   0.0   0 0.00   0 0.00 0.00  7.00   0  7.50  7.50   9 mmm
   BDA 1963  4 19  7 35 24.00  35.8000N  96.9000E  33.0   0 0.00   0 0.00 0.00  6.60   0  7.00  7.00   0 lll
   PDE 2001 11 14  9 26 10.01  35.9500N  90.5400E  10.0   0 0.00   0 0.00 7.80  8.30   0  0.00  8.30   0 ppp

Here the 8 & 9th column is latitude & longitude of a region. Using this columns & 19th column, their are points on the whole image.
Now i click on few points on the image, let it be for example 7 points i click & its values are


29.45, 89.43
32.47, 90.98
27.25, 95.63
27.29, 98.27
36.74, 96.32
31.90, 87.67
29.45, 89.43

Actu this points forms a polygon in the given region of the image which are in the given region of file. Now i want a program in such way that the points or the latitude & longitude only inside the polygon should be stored in another file or just tel me how to get those value on the screen or command promt.
The answer for the above example or the output file using above file a.dat & the 7 points are


   BDA 1908  8 20  9 53  0.00  32.0000N  89.0000E  60.0   0 0.00   0 0.00 0.00  6.60   0  7.00  7.00   0 bbb
   SIG 1927  5 22  0  0  0.00  36.0000N  96.0000E   0.0   0 0.00   0 0.00 0.00  7.50   0  8.00  8.00   0 bbb
   BDA 1934 12 15  1 57 37.00  31.3000N  89.3000E  60.0   0 0.00   0 0.00 0.00  6.70   0  7.10  7.10   0 bbb
   G-R 1950  8 15 14  9 30.00  28.5000N  96.5000E  25.0   0 0.00   0 0.00 0.00  8.10   0  8.70  8.70  10 aaa
   ISS 1950  9 13 11  7 27.00  27.5000N  96.4000E   0.0   0 0.00   0 0.00 0.00  6.60   0  7.00  7.00   7 sss

Now please me out.
Actu i have a region full of data i.e from latitude 0 to 50 & longitude 50 to 120.
Now i am asking for few points & based on how many ever points i am entering the lat & long for those points, this x,y points or lat long form a closed loop or polygon inside the given region 0 to 50 & 50 to 120…Now what i need is only the data which is inside that polygon or points which form a loop…Please help me out with a simple code or send me few links related to it…
I am trying this from past few days…Not getting Help me out

Three steps:

(1)Load all of data into an array. This will be your entire list of points. Lets call it POINTLIST.

(2)Draw the polygon and store it in another array. Lets call it POLYGON.

(3) Create another array. This array will store only the points that are in the polygon. Lets call it MASKEDPOINTS.

(4) For each point in POINTLIST, apply a point-in-polygon test (described below). If it passes the test, add current point to MASKEDPOINTS, otherwise, ignore it.

Point-in-polygon tests:
These tests basically test wether a particular point lies within the bounds of a polygon or not. The ‘easiest’ polygons to test are rectangles and circles(technically an n-gon). If you can, try to limit the polygon to one of these two, since it will make programming easier for you.

(1)Point-in-circle:
Basically, given the center of the circle C1 with a radius R, a point P1 will be inside the circle if the distance between P1 and C1 is less than R. The distance can be found via the pythagoras theorem

(2)Point-in-rectangle:
Basically, for a rectangle between x1,y1 and x2,y2, a point P1 is inside the rectangle is P1.x > x1 and P1.x < x2 and P1.y < y1 and P1.y < y2.
Thats it!

(3)Point-in-polygon
Its more complicated. Have a look:
http://en.wikipedia.org/wiki/Point_in_polygon

I hope that helps.

Thanks …
i got that first 2 methods already i mean
load all the data of file & store it an array & then draw polygon & store that points data which form polygon in one more array…
I just dont know how to do the 3rd & 4th part…
Can you please help me out…
i need to test the point in polygon. Which is too complicated…I checked the link which you gave i understood but i seriously dont know how to use it or code that…Please help me out…I am trying this past 2 weeks not even have a clue how to use it in my opengl program…
My opengl program i use to open the image which has full of points, these points which are stored in one file…Then i click on image & draw a polygon connecting it…This clicked or polygon points are stored in one array.Now Please tell me how write program in opengl which just gives the points from the file which are thier inside the polygon of the image or just tell me the function to check if a point is inside the polygon or outside polygon using the file & polygon points data & print those points which are inside polygon…Help me out with a code.

thanks in advance