[Gdal-dev] How can i display a map using GDAL ?

Mateusz Loskot mateusz at loskot.net
Thu Sep 28 08:24:27 EDT 2006


ÑÏΰ wrote:
> Hi,
>    I'm a newer about GIS.At the present,i want to use GDAL library to
> display a map by Qt programming.
> I have read the */ESRI Shapefile
> Technical Description /*and the */OGR API Tutorial/* ,but still don't
> know how to display a picture of map .*/OGR API Tutorial/* only tell me
> how to get the information in text format from a sharp file,but doesn't
> show how to display a map.

Hi,

GDAL does not provide anything about GUI toolkits or displaying
maps. GDAL is an implementation of data model and data access providers.
The analogy could be ODBC API providing access to databases but ODBC does
not provide any features to display data on a screen.

> could you give me a simple example about
> browse a map using GDAL by Qt programming .

QGIS is not a simple example but an example. It's written in QT and uses
GDAL/OGR.

http://qgis.org/

I'd try to find out how to do it simplier. The requirement is that
you have to know how to draw vector geometries (point, line, polygon)
using QT API.

If you know how to do it, then iterate through Shapefile features,
read geometry and build QT's representation of point, line or polygon,
depending on the geometry type of Shapefile.

Follow the "Reading From OGR" section of the OGR tutorial.
Here is one of possible schemes to follow:


OGRFeature *poFeature = NULL
poLayer->ResetReading();
while( (poFeature = poLayer->GetNextFeature()) != NULL)
{
   OGRGeometry *poGeometry
   poGeometry = poFeature->GetGeometryRef();

   if( poGeometry != NULL )
   {

      if (wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
      {
          OGRPoint *poPoint = (OGRPoint *) poGeometry;

          // HERE CALL QT API TO DRAW POINT

      }
      else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString)
      {
          OGRLinearString *poLine = (OGRLinearString *) poGeometry;

          // HERE CALL QT API TO DRAW LINE

      }
      else if (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon)
      {
          // ...
      }
   }
}


Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list