View Full Version : UTM Coordinate System projection

rakesh_thp

09-08-2009, 03:14 AM

hello there..

I am developing application using wxWidgets and OpenGL using C++.. I want the functionality where in, when a mouse is moved on GLCanvas, on the status bar of the application, x and y coordinates has to be displayed..

I am able to do this, by writing a code for mouse move event of GLCanvas.. Now, according to geography, there are various Coordinate Systems (CS).. e.g. UTM CS, Geographic CS etc.

Again for this CS, there are various ellipsoid.. The most commonly used ellipsoid is WGS84.. Now, i have an interface where in user can set the coordinate system either to Local, Geagraphic or UTM... And the ellipsoid is WGS84..

And also i have an interface, to convert Geographic CS to UTM CS.. Now, once the conversion is done, the projection changes.. I wanted to know how this change in projection can be acheived using OPENGL...

I found out one library on the internet called, PROJ.4... It can be integrated with C++, and i have used this library for conversion of CS.. But i'm failing to project the objects accordingly..

I dont know whether proj.4 can be integrated with OpenGL or not.. Any one kindly help me to get this problem solved...

Thanks in advance..

With Regards

Rakesh Patil

Aleksandar

09-08-2009, 08:18 AM

I dont know whether proj.4 can be integrated with OpenGL or not..

What type of integration are you intended? If you want to define coordinates in one system and GL to display them in another, using Proj.4 - FORGET IT!

I suggest you to transform your data into the coordinate system in which they will be displayed, and then send them to GL for displaying.

There is another very interesting topic... To port Proj.4 lib to CUDA or OpenCL. Such library will be brilliant solution for massive coordinates transformations.

rakesh_thp

09-08-2009, 11:55 PM

hey..

Thanks for your quick reply... Actually, i am transforming the coordinates using proj.4 library... Now i'm facing difficulty in displaying the objects in OpenGL.. Coz, For UTM CS, the display type is somewhat a 2D in comparison with GIS CS, where it is somewhat spherical shape.. So in case of GIS, angle, radius everything will come into picture.. That's why, projection changes from on CS to another..

Conversion of values i'm able to do without any problem.. But only displaying is a problem for me.. any comments or suggestions on this...???

Thanks in advance..

Aleksandar

09-09-2009, 03:19 AM

Now i'm facing difficulty in displaying the objects in OpenGL.. Coz, For UTM CS, the display type is somewhat a 2D in comparison with GIS CS, where it is somewhat spherical shape.. So in case of GIS, angle, radius everything will come into picture.. That's why, projection changes from on CS to another..

I still don't understand what is the problem? Yes, WGS84 is a spheroid, and UTM is as it name implies a Transverse Mercator projection. Displaying object on the WGS84 ellipsoid requires ground to be curved. Terrain can be displayed only in 3D. UTM is a 2D projection. If you want to draw objects in UTM, draw it on the flat surface. If you want to display Earth as in Google Earth, for example, you have to deal with WGS84 (don't convert to UTM), and unproject all data you have to WGS84 (if they are in UTM).

The only thing you should take care of is a finite precision of the Z-buffer. This is the problem with both WGS and UTM systems. In the WGS84 you have to be at least few kilometer away from the Earth surface to avoid Z-fighting.

Maybe I'll be able to focus the whole story if you tell me what exactly you want to achieve.

rakesh_thp

09-09-2009, 03:47 AM

Thanks for the concern..

See i got one user interface where user will set the coordinate system. This user interface includes, the following input to be given...

1. Horizontal system (HS)

HS may take any one of the values from,

a. Local

b. Geographic

c. UTM

2. Ellipsoid

As far as my knowledge is concerned, there are various ellipsoids like, Clarke96, WGS84, Airy, Everest etc.. I have kept all the available options, but presently concentrating on WGS84 ellipsoid only.

3. Units (for horizontal system)

Default i have kept to meters.

4. If HS is Geographic, user has to set Latitude and Longitude

If HS is UTM, user has to set Zone and Hemisphere (north/south).

After setting these things, later on user must be able to convert from one coordinate system to another coordinate system..

In my case, user can initially set CS to geographic HS, with WGS84 ellipsoid, latitude towards north direction and long towards east direction, and later on convert the CS to UTM HS, with ellipsoid remaining same. Zone I set to 44, and hemisphere (northern). (Or vice-a-versa)

Now suppose there is a rectangle on OpenGL canvas.. And i converted CS from UTM to Geographic. That time the orientation of box will change.

i hope till this it is clear from my side and what i wrote is correct according to the theory.. Please correct me if i'm wrong theoretically...

Now let me tell you how i do the conversion. On mouse move event of Canvas class, i have written a code that will display x, y pixel values of the canvas on the status bar..

My center (origin) is at the bottom left corner. I keep this projection same, and only convert the xy values to lat/long and display it on the status bar. I dont really change the

glOrtho projection.. I dont know whether its the correct way..

Similarly if i want to convert from lat/long to UTM, i just convert lat/long to UTM and display it on the status bar.. whereas my glOrtho projection remains same..

Now here i dont know how to handle, coz simply converting values and displaying wont work.. Orientation and projection should also change i feel...

Where am i wrong and what do i need to do more..??

Thanks in advance..

Aleksandar

09-09-2009, 05:49 AM

I think I get the point. It is OK to leave to the user to decide in which coordinate system he/she wants to see coordinates on mouse move, but the displaying should/need not be in the same system. You can also let users choose, or hardcode to some coordinate system (UTM44 for example, if application is for your region only, or more general in WGS). All spatial coordinates of the vertices should be in that system (e.g. WGS).

glOrtho gives an orthographic projection, which means it is not suitable in most cases (because the lack of perspective), except you are building a CAD application (don't mix meaning of glOrtho with geographical projection). If it is a CAD, distances generally are not such that geographic projections can make dramatical change. In that case confine your work only on coordinates conversion for displaying in the status bar.

More general case is to convert coordinates of your objects to displaying coordinate system, and draw all polygons. When mouse is over each pixel of the window, do the unprojection in OpenGL. (The function gluUnProject can do the stuff, but it uses deprecated functions, so if you intend to use GL 3.x core functionality it won't be available)

After the unprojection you will know where in 3D space the mouse is pointing to (that is in displaying coordinate system, e.g. WGS). Then convert those coordinates using Proj.4 lib to chosen coordinate system and display them in status bar.

Try to distinguish coordinates in which your scene is rendered and coordinates that are displayed in the status bar.

rakesh_thp

09-09-2009, 11:31 PM

at present what i am doing is that, when user draws a line, of a point, each object is having a property called m_projection_type.. The current ellipsoid value( either Geographic or UTM) is stored in this member (m_projection_type).

when storing x,y data in the object, i check for the current ellipsoid.. If it is Geographic, i convert x,y data to Lat/lon data and store it.. Else if ellipsoid is UTM, i convert x,y data into Northing and Easting (UTM coordinates) and save it in object..

And later on when it comes to display the objects, I check the value of m_projection_type.. If value is UTM, i convert UTM to xy pixel values, and if it is Geographic, i convert Lat/lon to xy pixel values.. Is this the correct way, what i am doing..??

I am sorry but I didnt get the solution what you explained.. It will be grateful of you if you kindly provide me with a small example of a point.. i.e. creating, and displaying a point, and displaying it after conversion.. If possible, no compulsion..

Anyways, thanks a lot..

Aleksandar

09-10-2009, 03:50 AM

at present what i am doing is that, when user draws a line, of a point, each object is having a property called m_projection_type.. The current ellipsoid value( either Geographic or UTM) is stored in this member (m_projection_type).

That's OK! (Only a minor syntactic correction: UTM is not an ellipsoid. :) )

when storing x,y data in the object, i check for the current ellipsoid.. If it is Geographic, i convert x,y data to Lat/lon data and store it.. Else if ellipsoid is UTM, i convert x,y data into Northing and Easting (UTM coordinates) and save it in object..

OK! The screen coordinates to m_projection_type system conversion.

And later on when it comes to display the objects, I check the value of m_projection_type.. If value is UTM, i convert UTM to xy pixel values, and if it is Geographic, i convert Lat/lon to xy pixel values.. Is this the correct way, what i am doing..??Inverse transformation. It is also OK, but you can also store, as you called "XY", coordinates together with "projection" coordinates, to avoid frequent conversions.

I am sorry but I didnt get the solution what you explained..Can you be precise which part you didn't understand? It is hard (and time consuming) to write a complete GIS tutorial.

This is a short example (pseudo-code) how to retrieve "world" coordinates of the pixel you have clicked on:

MouseClick()

{

[screen_X screen_Y] <- GetMousePosition()

screen_Z <- ReadPixelDepth(screen_X, screen_Y)

[scene_X scene_Y scene_Z] <- UnProject(screen_X, screen_Y, screen_Z, ModelViewMatrix, ProjMatrix, Viewport)

[world_X world_Y world_Z] <- SceneToWorld(scene_X, scene_Y, scene_Z)

}

rakesh_thp

09-10-2009, 04:52 AM

Well, i guess that part i have done.. :-) Tell me one thing.. Currently my setting is as follows..

Horizontal system is Geographic (which uses lat/lon values).

Ellipsoid is WGS84.

Units is meters.

Now suppose i convert this system into

Horizontal system: UTM

Ellipsoid WGS84

Units: meters

Zone = 44

I'll get a pair of values after conversion.. Now if i try to convert the original lat/lon values to OpenGL xy coordinates, and also if i convert UTM coordinates to OpenGL xy coordinates, then will i get same OpenGL xy values of there will be any variation in them..??

I feel, anyhow both conversion must point to same OpenGL XY coordinates.. Coz, i came across a software, where the projection changes a little bit when changed from one CS to another...

Thanks.

Aleksandar

09-10-2009, 09:21 AM

Horizontal system is Geographic (which uses lat/lon values).

Ellipsoid is WGS84.

Units is meters.

Units cannot be meters if system is Geographic. They can be: degrees, minutes, seconds, radians, or something like that.

I'll get a pair of values after conversion.. Now if i try to convert the original lat/lon values to OpenGL xy coordinates, and also if i convert UTM coordinates to OpenGL xy coordinates, then will i get same OpenGL xy values of there will be any variation in them..??

Depends on the precision, but should be approximately the same.

I feel, anyhow both conversion must point to same OpenGL XY coordinates.. Coz, i came across a software, where the projection changes a little bit when changed from one CS to another...

The finite precision of the arithmetic operations is the cause of that. Whenever you need a calculation use double precision. That is the reason you cannot calculate geographic projections in shaders (if you plan to use them). Order of operations and trigonometric functions calculations are also important, but you will probably use Proj.4, so leave the calculation to the library. :)

rakesh_thp

09-10-2009, 10:04 PM

Units cannot be meters if system is Geographic. They can be: degrees, minutes, seconds, radians, or something like that.

Thanks for that information.. I didn't knew that..

Whenever you need a calculation use double precision.

That is what exactly I have done..

Order of operations and trigonometric functions calculations are also important, but you will probably use Proj.4, so leave the calculation to the library.

Ya.. I have used the proj.4 library.. And as said by you, i get a small change in the fractional part.. That too after 5 or 6 digits from the decimal point.. I guess that must not make any difference.. Right..?? May be in that software, they might be slightly changing the window size, to show some variation, or they might be neglecting the fractional part or something..?? I don't know.. I mean I'm new to this world... If you have a cool good link to learn all these stuff (development of GIS app), then can you provide me some..??

But before that, let me know whether I asked is correct or not...

Thanks in advance...

Aleksandar

09-11-2009, 10:13 AM

Ya.. I have used the proj.4 library.. And as said by you, i get a small change in the fractional part.. That too after 5 or 6 digits from the decimal point.. I guess that must not make any difference.. Right..??

The 5th digit after decimal point if value represents degrees has a resolution of a meter. But you've probably meant something else, because such error is not negligible. If number represents UTM coordinates, they are expressed in meters, so make a conclusion by your own. :)

If you have a cool good link to learn all these stuff (development of GIS app), then can you provide me some..??

Although I've been developing GIS applications for more than a decade, I haven't made even one GIS tutorial. :(

Probably because of lack of time and also lack of interest of broad audiences for that. On the faculty we also have a course for GIS, but those links means nothing to you, because they are not in English.

What I suggest is: to download some serious software with good support (forget ArcGIS, I hardly prevent myself of writing what I intended to...). I think that Ilwis is the best for that purpose. (http://www.ilwis.org/)

But before that, let me know whether I asked is correct or not...I must admit that I didn't understand this...

rakesh_thp

09-13-2009, 11:34 PM

Hey,

My boss got to say that for a small area u wont find a change when u convert the coordinate system.. If the area is bigger, then there will be a sufficient amount of change that can be observed...

Tell me one thing.?? Does Proj.4 returns the value considering the type of projection ..?? I mean Mercator Projection, it considers and then calculates or do we need to do the projection manually in OPenGL..???

Thanks

Aleksandar

09-14-2009, 08:07 AM

My boss got to say that for a small area u wont find a change when u convert the coordinate system.. If the area is bigger, then there will be a sufficient amount of change that can be observed...

The error comes from the finite precision of the calculation, not from the size of the area. Maybe your boss though the shape of the area will changed if you change the projection, and that is true. The bigger the area, the bigger the distortion.

Tell me one thing.?? Does Proj.4 returns the value considering the type of projection ..?? I mean Mercator Projection, it considers and then calculates or do we need to do the projection manually in OPenGL..???

You set the projection parameters when you initialize the projection. What else the library should return to you? I don't understand the last question.

rakesh_thp

09-14-2009, 09:50 PM

Hi..

You set the projection parameters when you initialize the projection. What else the library should return to you? I don't understand the last question.

Actually, i got the library, which converts from lat/lon to utm and utm to lat/lon using proj.4 library.. And i dont know what projection they have used.. It accepts lat/lon and produces northing, easting and zone... and on the other hand, when supplied northing, easting and zone, produces lat/lon values... :-)

So, i guess now i need to learn how to use proj.4.. Anyways, I have used glOrtho() for displaying things.. so the technique what i mentioned in me previous post of converting is correct na..?? i just need to directly integrate Proj.4 with my application.. corect..??

rakesh_thp

09-14-2009, 11:43 PM

hi...

i found this code here..

double x[] = {72.56, 74.37, 76.66, 77.00};

double y[] = {8.83, 8.97, 10.23, 10.9};

projPJ pj_utm, pj_latlong;

if( !(pj_utm = pj_init_plus("+proj=utm +ellps=WGS84 +zone=43")))

exit(1);

if( !(pj_latlong = pj_init_plus("+proj=latlong +ellps=WGS84")))

exit(1);

for( int i = 0; i < 4; i++ )

{

x[i] *= DEG_TO_RAD;

y[i] *= DEG_TO_RAD;

}

int p = pj_transform(pj_latlong, pj_utm, 4, 1, x, y, NULL);

for( int i = 0; i < 4; i++ )

printf("%0.2f\t%0.2f\n",x[i],y[i]);

This piece of code will convert lat lon to UTM... (as per my requirement)

Now the final set of xy values have to be converted into openGL pixel coordinates and unprojected and should be displayed right.????

Aleksandar

09-17-2009, 04:26 AM

Now the final set of xy values have to be converted into openGL pixel coordinates and unprojected and should be displayed right.????

I guess you would like to display data in UTM coordinate system. So, unprojection is unnecessary. Coordiantes returned from proj.4 translate (let's center of your region be a coordinate system center, i.e. have GL coordinates (0,0,0)) and display.

rakesh_thp

09-21-2009, 02:48 AM

Hey hi...

I guess you would like to display data in UTM coordinate system. So, unprojection is unnecessary.

I didnt get this point... U mean to say that if i display things in UTM coordinates then no need to unproject..?? Why is that so..?? Coz, I got UTM values having 6 digits.. i mean the projected values which i get is having 6 digits ... So if i project it directly, it will be displayed somewhere out of the screen..

den what do i do to get them back to the center screen..?? I hope u might have gone through my other thread.. facing difficulty in rendering the projected objects...

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=264120#Post2641 20

Thanks

Aleksandar

09-21-2009, 10:05 AM

I didnt get this point... U mean to say that if i display things in UTM coordinates then no need to unproject..?? Why is that so..?? Coz, I got UTM values having 6 digits.. i mean the projected values which i get is having 6 digits ... So if i project it directly, it will be displayed somewhere out of the screen..

And how do you think all of those space-games are made, with planets and civilizations that are spaced with thousands of light-years, and everything can be displayed on the screen? :)

And you cannot deal with only one UTM zone... :)

Please, take a Red Book (OpenGL Programming Guide). The edition is totally irrelevant. Read the third chapter, and everything will be crystal-clear. Or I hope it will be. :)

In the meanwhile, subtract center or your UTM zone from the coordinates you have calculated. Doing this you'll lose one or two highest digits, which is very important for the precision. Than translate whole scene so that your POI is right in front of you (e.g. on the negative Z-axis).

rakesh_thp

10-01-2009, 12:23 AM

hey hi...

Sorry for late reply.. I was out of station for official work.. Actually, i've got the RedBook, and i refer that book and OpenGL bible..

I don't know but am still struggling with when to project the points and when not to... By the way, will gluLookAt() function be of any use here to project..??

If so, can it be used for zooming and panning, or only panning..??

And can it be used with glOrtho projection..??

Thanks again

Aleksandar

10-02-2009, 05:57 AM

By the way, will gluLookAt() function be of any use here to project..??

gluLookAt() serves as a viewing transformation. You have to clarify differences between viewing and projecting.

If so, can it be used for zooming and panning, or only panning..??Yes. It can be used for both, if you are using gluPerspective(). glOrtho() does not reflect changes in the distance, so "zooming" is excluded. At least on that way. But you can implement zooming by changing glOrtho parameters.

And can it be used with glOrtho projection..??Of course that it can, but refer to the previous answer.

rakesh_thp

10-05-2009, 05:47 AM

Hi friend..

Thanks for sharing knowledge with me... Now its my turn to give a test.. and its your turn to tell me whether i'm pass or fail.. Probably this will be my last post.. Whatever i have written here is according to my understanding..

First and foremost, there is a difference between, computer monitor pixel and OpenGL coodinates. So in order to convert from Monitor pixel coordinate to OpenGL coordinates is called the process UnProject. And the reverse process is called Project. And in order to do so, we make use of gluUnProject and gluProject... Am i correct..??

Secondly, When user clicks on the canvas, we UnProject the mouse (x,y) values and process it... Now little bit more practical explaination.. I run my application, and the interface is standing in front of me.. First thing i need to do is the set the coordinate system.. So suppose as an example, i Set the coordinate system, with

projection = UTM, ellipsoid = WGS84, zone=44, northern hemisphere..

Now coming to the storing of values, i am using two different variables.. One to store the actual pixel value, and another to store the converted values (values converted to the current coordinate system..) So suppose i want to display a line.. I make use of variables having actual value to display on the canvas and converted values to display in property grid...

Now, suppose i want to convert the coordinate system.. From UTM projection to the Geographic (lat/lon) projection. For this conversion i make use of PROJ.4 library.. So i take each and every point from the list. I read the converted value and pass them as an argument to PROJ.4 library.. I get the converted value and store them into the same variable(which is used to store into the converted variables)..

So basically, the actual stored values will remain same, only the converted values will be changing.. This is what i have implemented till now.. Am i correct..?? Please dont fail me.. :-)

Thanks in advance..

Aleksandar

10-06-2009, 11:48 AM

Hi!

Thanks for sharing knowledge with me...No problem. The pleasure is mine. :)

Now its my turn to give a test.. and its your turn to tell me whether i'm pass or fail.. Probably this will be my last post..I don't like grading students. It is the worst part of the education process. I would be much happier if I could only teach and not prepare exams and evaluate students' knowledge, but ... And never say it is the last time... Who knows... :)

First and foremost, there is a difference between, computer monitor pixel and OpenGL coodinates. So in order to convert from Monitor pixel coordinate to OpenGL coordinates is called the process UnProject. And the reverse process is called Project. And in order to do so, we make use of gluUnProject and gluProject... Am i correct..??Yes! To be more precise, the gluProject() function transforms the specified object coordinates into window coordinates using modelMatrix, projMatrix, and viewport matrices specified as a parameters of the function. The gluUnProject() function maps the specified window coordinates into object coordinates.

Secondly, When user clicks on the canvas, we UnProject the mouse (x,y) values and process it...That is OK!

Now coming to the storing of values, i am using two different variables..

...

So basically, the actual stored values will remain same, only the converted values will be changing.. This is what i have implemented till now.. Am i correct..??Uhhh... Depends on what you are intending to achieve. The Coordinates which you call "Monitor pixels" should be coordinates in your OpenGL scene, and in order to be properly displayed must be a geographic (map) projection. I suppose that UTM is most suitable for your purpose. But as you have already said, UTM coordinates are large. For example, Y-coordinate is a distance from the Equator. Who cares about thousands of kilometers if your displayed region is just a few dozen square kilometers large?! So, subtract center of your area from the UTM coordinates and let's that be coordinates you will use to display data (first pair of coordinates you are storing for each entity). Besides, you can store also original UTM coordinates to avoid two additions before calculating coordinates in another geographic coordinate system.

Everything you display should be in that (native) coordinate system. Second pair of coordinates can be in another (chosen) coordinate system. And that is the place where Proj.4 does its job. If that coordinates servers only for displaying in a grid control, nothing in the OpenGL scene is changed when you choose another coordinate system. But if you want the data to be displayed in the chosen coordinate system, then everything is much different. In that case, you should recalculate all coordinates and display objects in a new system. For example, choosing LatLon (i.e. Geographic) projection, everything will be stretched along the X-axis, and the stretching will be more and more apparent as you go north. In that case, first pair of coordinate will be translated version of the second pair, and you don't need to store dual coordinates, because you can easily calculate another by just adding/subtracting certain values (usually center of your area of interest).

rakesh_thp

10-07-2009, 02:18 AM

Hi,

But if you want the data to be displayed in the chosen coordinate system, then everything is much different.

Yes.. The requirement for my application is the same as u mentioned in the above statement..

In that case, you should recalculate all coordinates and display objects in a new system.

All coordinates means..?? only the coordinates of the objects or also my glcanvas projection area coordinates..?? (i mean to say here that near, far, left, right, top and bottom) all should be recalculated..??

For example, choosing LatLon (i.e. Geographic) projection, everything will be stretched along the X-axis, and the stretching will be more and more apparent as you go north.

How much it has to be stretched..?? or will the proj.4 will give the stretched value..??

In that case, first pair of coordinate will be translated version of the second pair, and you don't need to store dual coordinates, because you can easily calculate another by just adding/subtracting certain values (usually center of your area of interest).

I'm not clear with this point.. How exactly can be the second pair calculated..??

Thanks again..

Aleksandar

10-08-2009, 12:00 PM

When you change coordinate system, recalculate OpenGL display coordinates in three steps:

1. If displayed feature is not a point, maybe you should subdivide feature into smaller peaces. (For example, a quad in one projection is a distorted rhombus, or parallelogram, or trapeze in another). If the feature covers small area, skip subdividing and just perform recalculation of its vertices.

2. Use Proj.4 to calculate position in a chosen projection.

3. (optionally) subtract coordinates of the center of your area in order to "localize" coordinates.

You don't need to store multiple values for the coordinates (each in different system), because you can display coordinates in the actual (chosen) coordinate system. My advice is to use step 3, especially in the case of UTM and similar projections.

The parameters of the glOrtho() must also be changed, because we are now in different coordinate-system, and viewing area cannot be the same.

Proj.4 will do everything (according to geographic projections) for you, so don't bother with stretching. Only be aware that some primitives must be subdivided before reprojection.

I hope that this time I have succeeded to formalize my advices. :)

rakesh_thp

10-09-2009, 04:15 AM

Hi..

When you change coordinate system, recalculate OpenGL display coordinates in three steps:

1. If displayed feature is not a point, maybe you should subdivide feature into smaller peaces. (For example, a quad in one projection is a distorted rhombus, or parallelogram, or trapeze in another). If the feature covers small area, skip subdividing and just perform recalculation of its vertices.

2. Use Proj.4 to calculate position in a chosen projection.

Till here i understood...

3. (optionally) subtract coordinates of the center of your area in order to "localize" coordinates.

This point is optional u said.. Why is that so..?? I think this point works fine only if the coordinates are in UTM system, right..?

Secondly, suppose i read in a file which contains lat/lon values (long in range of 71-72 and lat in the range of 0 - 1.5), then in this case, there is no need to use proj.4... Just directly read the values and display on the canvas.. But if i plot these values, then it will be visible very small compared to the actual screen.. coz my glcanvas size is 0 to 800 along x and 0 to 450 along y... So basically how do i take care of such situations where in the range of x and y axis are much smaller (or much bigger) compared to my display canvas size..??

You don't need to store multiple values for the coordinates (each in different system), because you can display coordinates in the actual (chosen) coordinate system. My advice is to use step 3, especially in the case of UTM and similar projections.

I also want the coordinates to be displayed below on the status bar as the mouse moves.. So i think keeping the converted values will help for this purpose instead of spending time to convert each coordinate.. What say..??

The parameters of the glOrtho() must also be changed, because we are now in different coordinate-system, and viewing area cannot be the same.

Proj.4 will do everything (according to geographic projections) for you, so don't bother with stretching. Only be aware that some primitives must be subdivided before reprojection.

This is fine..

I hope that this time I have succeeded to formalize my advices.

Yes you have.. But that adjustment.. :-) And also please go through my new post on help requirement of optimizing the display techniques..

Thanks

Aleksandar

10-09-2009, 12:08 PM

This point is optional u said.. Why is that so..?? I think this point works fine only if the coordinates are in UTM system, right..?

When you start to have difficulties with a large numbers, than you can understand why "the third step" is important. :)

If everything works fine, just skip it.

Secondly, suppose i read in a file which contains lat/lon values (long in range of 71-72 and lat in the range of 0 - 1.5), then in this case, there is no need to use proj.4...

That's right!

But if i plot these values, then it will be visible very small compared to the actual screen.. coz my glcanvas size is 0 to 800 along x and 0 to 450 along y... So basically how do i take care of such situations where in the range of x and y axis are much smaller (or much bigger) compared to my display canvas size..??

The size of the screen in pixels is irrelevant! Stop thinking in pixels and start thinking in logical coordinates. OpenGL is a 3D API. Everything you define is expressed in 3D coordinates in some "virtual" space. Fragments (the "candidates" for pixels) appears after a rasterization step. Some of the fragments survive trip through 3D pipeline and they become pixels. How the process of rasterization converts vector data to a raster depends on the Viewport transformation. Please, please, please, READ AGAIN 3rd CHAPTER OF THE RED BOOK, or 4th chapter of the SuperBible.

I also want the coordinates to be displayed below on the status bar as the mouse moves.. So i think keeping the converted values will help for this purpose instead of spending time to convert each coordinate.. What say..??

That's OK!

Yes you have.. But that adjustment..

Well, if your coordinate system is LatLon and you want to see 2x2 degrees, then (right-left) and (top-bottom) must be 2. If your coordinate system is UTM, and (right-left)=2 and (top-bottom)=2, then you will see just 2x2 meters! Parameters of the glOrtho() are NOT defined in pixels, but in logical coordinates. I think that your way to a success must start with forgetting about pixels at all! :)

rakesh_thp

10-12-2009, 02:46 AM

hi.

Well, if your coordinate system is LatLon and you want to see 2x2 degrees, then (right-left) and (top-bottom) must be 2. If your coordinate system is UTM, and (right-left)=2 and (top-bottom)=2, then you will see just 2x2 meters! Parameters of the glOrtho() are NOT defined in pixels, but in logical coordinates.

Ya i know... It was just an example.. Suppose if i read any other file, there the range may be totally different.. It may be between 78 to 84 (along x) and 8 to 10 (along y).. In this case the range is different.. So in this case the parameters passed to the glOrtho will change.. I'm wondering how these parameters can be set priorly, in order to fit any data, and display it(data) at the center of the screen..

One way what i was doing is finding min and max in both x and y direction and use them as parameters for glOrtho()... I thought this would work... But it isnt giving me the desired output..

THanks again...

rakesh_thp

10-19-2009, 05:01 AM

Hi Alexsandar..

I am trying two cases, one for west coast off Goa and another off Visakhapatanam along East coast.. I'm getting correct desired result for the west coast.. I used the same technique which i explained in my previous post... But the same logic isnt working for east coast..

Any other solution or logic u can give..??

Thanks in advance

Aleksandar

10-19-2009, 11:13 AM

Hi, rakesh_thp!

It may be between 78 to 84 (along x) and 8 to 10 (along y).. In this case the range is different.. So in this case the parameters passed to the glOrtho will change..

For that example parameters can be set like this...

glOrtho(-3,3,-1,1,near,far);

But, be aware that aspect in this case is 3! So, set viewport on adequate way. Or, what I suggest, adjust viewing frustum according to viewport (set the same aspect).

I'm wondering how these parameters can be set priorly, in order to fit any data, and display it(data) at the center of the screen..

Set projection to, for example,

float aspect = (float)window_width / (float)window_height;

glOrtho(-aspect, aspect, -1, 1, near, far);

And in the viewing transformation translate the whole scene so that the center of the scene is in (0,0). For example:

glTranslatef(-81.0f, -9.0f, 0.0f);

Aleksandar

10-19-2009, 11:21 AM

I am trying two cases, one for west coast off Goa and another off Visakhapatanam along East coast.. I'm getting correct desired result for the west coast.. I used the same technique which i explained in my previous post... But the same logic isnt working for east coast..

Can you provide some picture of that? What does it mean "the same logic isn't working"? I guess the aspect is the problem.

It must me the same as in the viewport transformation, or the picture will be stretched.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.