UTM Coordinate System projection

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

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.

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…

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.

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…

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.

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…

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

OK! The screen coordinates to m_projection_type system conversion.

Inverse transformation. It is also OK, but you can also store, as you called “XY”, coordinates together with “projection” coordinates, to avoid frequent conversions.

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)
 
}

Well, i guess that part i have done… :slight_smile: 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.

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

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

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. :slight_smile:

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…

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. :slight_smile:

Although I’ve been developing GIS applications for more than a decade, I haven’t made even one GIS tutorial. :frowning:
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/)

I must admit that I didn’t understand this…

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

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.

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.

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… :slight_smile:

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…??

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	%0.2f
",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.???

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.

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#Post264120

Thanks

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? :slight_smile:
And you cannot deal with only one UTM zone… :slight_smile:

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. :slight_smile:

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).

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