Using GDAL / OGR api to read vector data (shapefile) - How?

I am working on an application that includes some gis stuff. There would be some .shp files to be read and plotted by opengl. The current opengl screen uses the spelling projection as set from glOrtho()

and already displays the map using coordinates from a plain text file.

The rendered image should now be read from the shapefile.

I have the following doubts:

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

  • My application needs to be configured so that I can find out the exact lat / long value of a point on the map. For example, if I am on an X city, it can be fixed with lat / long. I know it can be done using opensource utils / apis like GDAL / OGR, but I am screwed up since the documentation of these apis does not make it into my chapter. I tried to find some C ++ programs but couldn't find them.

  • I've already written my own logic to read coordinates from a shapefile containing either points / polyline / polygon (using C-shapelib) and built on my opengl screen. I found OGR sample code in document for reading POINTS shapefile, but not for shapefile OF POLYGON. And the problem is that this application has to be so dynamic that when loading the shapefile, it has to correctly adjust the opengl screen projection depending on the projection of the .shp file read. for example WGS84, LCC, EVEREST MODIFIED ... etc. how to achieve this from the OGR api?

Please give your materials on this issue. I am very interested in making this work, but I do not start right away.

+1


source to share


3 answers


  • Sending formats to OpenGL is pretty straight forward. You can require "shapelib", a free C parsing library (Google it). Use GL_POINTS for a point shape file, GL_LINES for a line shape file, and GL_LINE_LOOP for a polygon shape file. Set your bounding boxes to Ortho.

  • What you read from the .prj file is projection information. WGS84 gives you lat / long coords (Spherical). But your display system is 2D (Rectangular). So you need to convert 3D spherical coordinates to 2D rectangular coordinates (this is the Projection value). The types of projects are numerous, depending on the area of ​​interest on the globe (remember that projection distorts the area / shape / size of functions) .Projection types range from Polyconic, Modified Everest, NAD, UTM, etc.

  • If you just need WGS84 then read the coordinates of the bounding boxes of your .sh file and assign them to glOrtho. If you have a projection (ex: -UTM), then you convert your frame to projection coordinates and then assign the newly projected coordinates to glOrtho. To convert lat / long to any projection you may need projection libraries such as "Projlib" or "GeotransEngine" etc.



For more clarification, you can contact me at dgplinux @yaho o. com

+2


source


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



+2


source


GDAL / OGR has everything you need to load a vector file and then convert any coordinates. I understand your frustration with GDAL as the documentation is not great. If you want a good introduction to the API, take a look at gdalinfo.c and ogrinfo.cpp in the GDAL spoof tree. The source can be seen at https://svn.osgeo.org/gdal/trunk/gdal .

If that doesn't help, I have two main examples that I use to analyze vector information and transform coordinates. They are very bad, but they can help you understand the point.

Loading images

Coordinate transformation

Finally, if you are not familiar with GIS formats, I would consider reading an introduction to ArcGIS here under Guide Books

/ Map Projections

. I can compete with the experts despite the lack of cartography training because of these tutorials. Another good source is Wikipedia.

When in doubt, just select the UTM grid you want to stick to and use the UTM as your coordinate system. It uses X (East), Y (North), and Z (Height). The only clue is to choose a single UTM grid and make sure all coordinates use that as a reference. UTM code is easy to test as there are many tutorials on the internet. You can also find conversion code using OGR / GDAL or other resources. Other projected coordinate systems are noteworthy and could be better, but I would look at this from the beginning.

Finally, if all else fails, check out NGA GeoTrans. It's a great testing tool.

0


source







All Articles