[Gdal-dev] plotting data

Chapman, Martin MChapman at sanz.com
Sun Sep 19 18:19:52 EDT 2004


Roger,

Ok, good question.  The first thing you need to understand is that when using a 3D graphics package like OpenGL, you need only be concerned with rendering the desired (x, y, z) to opengl with function calls like glVertex3d(x, y, z);.  OpenGL's graphics pipeline will then handle all transformation needed to transform your points to 2D screen coordinates for rendering.  That's one of the benefits of using 3D OpenGL compared with the 2D device context.  

Here are the steps you need to do to render points from a shape file.  

1.  Open the shape file and read points (z, y) into an array(s), or into your geometry class (like polygon, point, etc) with OGR.  Usually the points are stored in the shape file as lon, lat (angular units). 

2.  Use the OGR api to create a spatial reference system and then transform all x, y points using the OGRCoordinateTransformation class.  There is a tutorial on how to do this at http://www.remotesensing.org:16080/ogr/osr_tutorial.html .  The OGR api will load the projection information for a shape file if there is a file named the same as the shape file but with a .prj extension.   

3. Once you have your new transformed points, then loop through the points and draw them to the screen with OpenGL's glVertex() functions.  There are functions that take both x,y and x,y,z.  OpenGL takes care of all the math to project the points into 3D world coordinates and then to 2D screen coordinates.  I've attached a screen shot to show you the output. 

If you want to make it easy the first time you render the points, just send them to OpenGL with the values you read in out of the shape file (lon is x, lat is y, set z = 0.0).  It will draw the map as you expect even if it's decimal degrees.  Then, as you project points to other values (x,y) the map will just look different.  All the projection is doing is warping the way your map looks like.

See attached screens shots from my app.

Martin



-----Original Message-----
From:	Roger Persson [mailto:rogper at bredband.net]
Sent:	Sun 9/19/2004 3:49 AM
To:	gdal-dev at xserve.flids.com
Cc:	
Subject:	Re: [Gdal-dev] plotting data
Hello,

Thanks for the hint. But what projection are am suppose to use? If I 
project the (lat, long, height)-coordinate onto a "Oblique 
Stereographic" (x, y, z)-surface, then I must project a second time 
onto a graphics device coordinate system (or OpenGL coordinate system) 
before rendering. Is it up to me to calculate the latter (affine) 
transformation, or is there an utility to do that ?

/Rogper

2004-09-19 kl. 00.00 skrev Chapman, Martin:

> Roger,
>
> There are several ways to draw your points in a window.  All the ones 
> I know, at a minimum, use the "graphics device context".  The DC 
> (device context) or objects that derive from it, have methods to draw 
> to a window that take x, y as parameters.  It also lets you control 
> things like line width, fill color, etc.  In addition to that, the 
> device context can also be used to pass control of the rendering to a 
> third party graphics library like OpenGL.  There is a lot of good code 
> on the internet that shows how to do this for your specific platform.
>
> With that said, I would search google for how to draw points in a 
> window using the device context or opengl on Mac OSX.  Once you get 
> that plumbing hooked up it will be obvious how to feed the points to 
> your screen from OGR.
>
> I would strongly recommend using OpenGL for vector, not for raster 
> though...always use the device context for rasters unless you want to 
> project the image into a vector map.  Go to http://nehe.gamedev.net/ 
> and try some of the cross-platform examples for OpenGL as well.
>

_______________________________________________
Gdal-dev mailing list
Gdal-dev at xserve.flids.com
http://xserve.flids.com/mailman/listinfo/gdal-dev




-------------- next part --------------
A non-text attachment was scrubbed...
Name: ortho_proj.jpg
Type: image/jpeg
Size: 160980 bytes
Desc: ortho_proj.jpg
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040919/1048ccb6/ortho_proj.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: merc_proj.jpg
Type: image/jpeg
Size: 217224 bytes
Desc: merc_proj.jpg
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040919/1048ccb6/merc_proj.jpg


More information about the Gdal-dev mailing list