I started using the GDAL Library in a c++ project. It is a great library, but I am a bit stuck right now with different aspects of it. What is the best way to use gdal_contour in my c++ programm? Should i use the system() function or simply grab the source and use it? I tried to get the contours of a hightmap with gdal_contour as a PNG or SVG(or different vector format, like eps or so) but had no success so far. Is there a list wich output formats are supported. Until now I only got shp and dxf files. Do I have to burn the shp file to a png with gdal_translate? I tried this and had some troubles with the alpha channels. Maybe someone has the commands for me to get a transparent contour as png. Sometimes the contour lines look a bit to pixelated, is there a way to smoothen things up with more antialiasing or so? Is there a way to get a colored contour automatically, or do i have to use a color table txt file?

I tried the following where output.tif was a transparent tif. but had no success.

gdal_contour -i 50 <DEM> contour
gdal_rasterize -burn 0 -l contour contour output.tif

Gdal_contour creates vectors and the supported formats are those which are marked as Creation-Yes in http://gdal.org/ogr_formats.html

Gdal_rasterize does not support anything fancy like setting line widths or line smoothing or transparency. You must look for other tools for advanced rendering. Perhaps you should play first with the data and rendering by opening the contour vectors with QGIS and using the GUI for defining the styles. Later I think that you can control rendering from your c++ code by utilizing for example just QGIS or Mapserver or Mapnik. However, if you are familiar with graphic design programs you can try to convert the contours into PDF vector format http://gdal.org/frmt_pdf.html and continue from that with other tools.

| improve this answer | |
  • Thanks for the Link. That helps a lot. PDF is a good idea. I will try that. I read that gdalwarp can maybe be helpfull with smoothening contours. – mixed_farmer Jun 15 '14 at 16:31
  • Hey there, i tried to export the shape with -f PDF or -f SVG, but got errors. Unable to find format driver named PDF. ERROR 6: CreateDataSource() not supported by this driver. Not sure how to solve this... – mixed_farmer Jun 17 '14 at 21:39
  • You have PDF driver in GDAL? Test with ogrinfo --formats If you have, how did your command look like? Or it may be that you must convert some raster and add vectors on top of it, read gdal.org/frmt_pdf.html. – user30184 Jun 17 '14 at 21:49
  • it seems that the SVG driver can only read and the PDF driver is not there. How can i install or add it? i could not find any infos on that. here is my command: gdal_contour -i 50 -f svg test5.tif contour.svg – mixed_farmer Jun 18 '14 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.