views:

1803

answers:

2

Hi,

I am working on an application that involves some gis stuff. There would be some .shp files to be read and plotted onto an opengl screen. The current opengl screen is using the orthographic projection as set from glOrtho()..and is already displaying a map using coordinates from a simple text file..

now the map to be plotted is to be read from a shapefile.

I have the following doubts:

  1. How to use the WGS84 projection of the .shp file(as read from the .prj file of the shapefile,WKT format) into my existing glOrtho projection..is there any conversion that needs to be done? and how is it different from what the glOrtho() sets up?basically how to use this information?

  2. My application needs to be setup in such a way that i can know the exact lat/long of a point on the map.for eg. if i am hovering on X city,its correct lat/long could be fetched.I know that this can be done by using opensource utils/apis like GDAL/OGR but i am messed up as the documentation of these apis are not getting into my head. I tried to find some sample c++ progs but couldnt find one.

  3. I have already written my own logic to read the coordinates from a shapefile containing either points/polyline/polygon(using C-shapelib) and plotted over my opengl screen.I found a OGR sample code in doc to read a POINTS shapefile but none for POLYGON shapefile.And the problem is that this application has to be so dynamic that upon loading the shapefile,it should correctly setup the projection of the opengl screen depending upon the projection of the .shp file being read..eg WGS84,LCC,EVEREST MODIFIED...etc. how to achieve this from OGR api?

Kindly give your inputs on this problem..i am really keen to make this work but im not getting the right start..

Please help.

Thanks & Regards.

+2  A: 

Hi,

1.Shapefile rendering is quite straight forward in OpenGL.You may require "shapelib",a free shapefile parsing library in C(google for it).Use GL_POINTS for point shapefile, GL_LINES for line shapefile and GL_LINE_LOOP for polygon shapefile.Set your bounding box coods to the Ortho.

2.What u read from .prj file is projection info.WGS84 gives u lat/long coods(Spherical). But ur display system is 2D(Rectangular).So,u need to convert 3D Spherical coods to 2D Rectangular coods(This is the meaning of Projection).Projection types are numerous,depending on the area of interest on the globe(remeber projection distorts area/shape/size of features).Projection types range from Polyconic,Modified Everest,NAD,UTM etc.,

3.If u simly need WGS84 ,then read bounding box coods of ur sh file and assign them to glOrtho.If u have any projection(eg:-UTM) ,then u convert ur bounding box coods into Projection coods and then assign the newly projected coods to glOrtho.For converting lat/long into any Projection,u may require projection libraries like "Projlib" or "GeotransEngine" and etc.

For further clarifications u may contact me on dgplinux@ y a h o o . c o m

+2  A: 

Please, read the OGR API Tutorial where you can learn how to read vector data from sources like Shapefile. Next, check the OGR Projections Tutorial where you can learn about how to use information about projection and spatial reference system read from OGR sources.

mloskot