Sorry but this is NOT the way UNIX.com forums work. We do encourage people to add their efforts which they have put in order to solve their own problems, so please do add your efforts in your question and let us know then. Your question is also NOT having clear information about how you want to achieve your goal, so kindly do add the rules, conditions and logic by which you want to achieve your goal.
interesting puzzle!
Are you saying one has to "draw" an imaginary rectangle frame given the input coordinates?
I'm saying "imaginary", because the desired output coordinates are not in your input file.
Very interesting puzzle, but I'm not sure of the algorithm - it's definitely not what you tried.
I was thinking the same thing; but refrained from commenting .....
But I had trouble seeing any tangible relationship between the "attempt" and the original post.
I think better we tag this thread amber again and ask the OP to perform a "real attempt" to solve his problem, and add the output or error messages in reply before offering more answers.
sorry, I don't think I can help - not sure of the algorithm and you're not providing any hints.
Maybe other did better in their trigonometry in school.
Would be interesting to see the attempts/solutions.
Assuming you are using Longitude and Latitude WRT Earth as a __sphere__ then it is not possible to create a rectangle as Euclidean geometry does not apply.
IF, however you just want the Longitude to change but have matching Latitudes and vice versa and those listing out then please confirm...
I pretty sure it is possible to take latitudes and longitudes and construct a 2D geometric shape (like a rectangle) if we know the distance from the center of the coordinate system (commonly called "the elevation" above mean sea level of the earth). Otherwise, land surveying would not be possible since surveying is based on longitude and latitude (coordinates) with the elevation (on the Earth this is the distance above MSL).
Latitude and longitude, along with distance from the center of the earth, form polar coordinates, as I fondly remember from "the good ole days" when I worked as a land surveyor (actually I had my own land surveying business for many years),
The problem I have with this question is that the OP is not providing his algorithm as vbe mentioned in post #8.
So, let's ask the OP to post his formulas (algorithms) he is using to do the calculations.
The short answer is "to select a rectangle frame from longitude and latitude" is that you need to know the distance from the center of the coordinate system for each coordinate. This is simply a problem in converting polar to rectangular coordinates, and back.
Of course, you know me, I have done this kind of calculation countless times (in my youth) and never did it with awk . I used to do these calculations (almost daily) on the Tandy TRS 80 which I programmed in Basic and also the Atari / Amiga, back in the "day".
awk '
function triangle_area(x1, y1, x2, y2, x3, y3) {
#
# determine area of triangle with the 3 points given
#
area=((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
#
# return absolute value of area. area value should be positive. unless you are on drugs.
#
return area < 0 ? -area : area;
}
FILENAME ~ /rectangle/ {
if (! repeat_line[$0]++) {
#
# load points of rectangle in x, y arrays.
#
x[NR]=$1;
y[NR]=$2;
} else {
#
# repeat line found so rectangle is closed. that is nice.
# calculate area of rectangle by adding area of two triangles that make up rectangle
#
Rectangle_area=triangle_area(x[1], y[1], x[2], y[2], x[3], y[3]) + triangle_area(x[1], y[1], x[3], y[3], x[4], y[4]);
}
}
FILENAME ~ /positions/ {
#
# determine area of 4 triangles made up of latitude, longitude point and each side of rectangle
#
triangle1=triangle_area(x[1], y[1], $1, $2, x[2], y[2]);
triangle2=triangle_area(x[2], y[2], $1, $2, x[3], y[3]);
triangle3=triangle_area(x[3], y[3], $1, $2, x[4], y[4]);
triangle4=triangle_area(x[1], y[1], $1, $2, x[4], y[4]);
#
# if rectangle area equals to total area of 4 triangles then point is inside rectangle. it is obvious if you think about it.
#
if (Rectangle_area==triangle1+triangle2+triangle3+triangle4) print $0;
}
' rectangle positions
note, example posted uses format of input/output files shown (not csv, as stated).