Gdal is a well-known open source GIS data manipulation library that is used by software including ArcGIS.
The website address is as follows: http://www.gdal.org/
There are a number of supported formats. Including the underlying picture png,gif,jpg,tiff,bmp
Remote sensing image data of Pci,erdas,arcinfo
Vector files such as shp,tab,mif
Oracle Spatial,postsql's Spatial database
intends to combine QT to do some related learning development, walked a lot of bend. It's a lot of trouble because it's going to be developed in the same set of Microsoft.
The compiler uses MINGW, I use the version is 4.5, download the address as follows: http://sourceforge.net/projects/mingw/files/
Gdal the latest version of the source code is 1.7.3, download the address as follows: Http://trac.osgeo.org/gdal/wiki/DownloadSource
After the installation of MinGW, through the MinGW shell into the gdal source root directory
Run
./configure--prefix= $PATH _to_install_gdal_root--without-libtool--without-python
Explain:
Path_to_install_gdal_root is a variable that represents which directory to build GDAL to
--without-libtool indicates that no. a file is generated (if you want to cross-compile a static library under Linux, you can do this without adding this)
--without-python indicates that Python-usable files are not generated
The complete command is./configure--prefix=/d/gis/gdal
This generates a makefile, and if there is no error, continue running
Make
I have been in the process of error, tossing a day, check a lot of information, only to know that the path in the gnumakefile.opt file is wrong,
You need to replace "$ (gdal_root)" Before 12 lines with a period "."
Make again, finally generated a bunch of O files (equivalent to the win platform obj file), a little bit longer (this compile efficiency, than the. NET difference)
If all goes well, continue running
Make install
Will generate some files in the D:\gis\gdal directory, including some header files and a libgdal.dll (more than 20 m, it may be the compile-time mess is added, a large DLL)
The gdal-1.7.3 directory itself generated a lot of intermediate files, making the original folder of several m into hundreds of M.
Do not understand GCC, also do not understand configure, so that the intermediate files are all left there.
In this, we can finally use the Gdal in Qt.
I am using the QT Library 4.6.2 version, the latest is 4.7.1, the new version includes some Meego things.
The IDE uses its own QT creator, the latest version is 2.0
To create a new console project, the code in Main.cpp is as follows:
#include < qtcore/qcoreapplication >
#include < iostream >
#include "Include/gdal/ogrsf_frmts.h"
using namespace Std;
int main (int argc, char * argv[])
{
Qcoreapplication A (argc, argv);
Ogrregisterall ();
Ogrdatasource * PoDS;
PoDS = Ogrsfdriverregistrar::open ("zw0817p.shp", FALSE);
if (PoDS = = NULL)
{
printf ("Open failed.\n");
Exit (1);
}
Ogrlayer * Polayer;
Polayer = PoDS, Getlayerbyname ("point");
Ogrfeature * pofeature;
Polayer, resetreading ();
while ((Pofeature = Polayer, getnextfeature ()) = NULL)
{
Ogrfeaturedefn * Pofdefn = Polayer, Getlayerdefn ();
int Ifield;
for (Ifield = 0; Ifield < pofdefn-GetFieldCount (); Ifield + +)
{
Ogrfielddefn * Pofielddefn = Pofdefn, Getfielddefn (Ifield);
if (Pofielddefn-GetType () = = Oftinteger)
printf ("%d,", Pofeature-Getfieldasinteger (Ifield));
else if (Pofielddefn-GetType () = = Oftreal)
printf ("%.3f,", Pofeature-getfieldasdouble (Ifield));
else if (Pofielddefn-GetType () = = oftstring)
printf ("%s,", Pofeature-getfieldasstring (Ifield));
Else
printf ("%s,", Pofeature-getfieldasstring (Ifield));
}
Ogrgeometry * POGEOMETRY;
Pogeometry = Pofeature, Getgeometryref ();
if (pogeometry! = NULL
&& Wkbflatten (Pogeometry, Getgeometrytype ()) = = Wkbpoint)
{
Ogrpoint * Popoint = (Ogrpoint *) pogeometry;
printf ("%.3f,%3.f\n", Popoint-GetX (), Popoint-GetY ());
}
Else
{
printf ("no point geometry\n");
}
Ogrfeature::D estroyfeature (pofeature);
}
Ogrdatasource::D estroydatasource (PoDS);
return A.exec ();
}
Explain:
#include "Include/gdal/ogrsf_frmts.h"
I copy the include and Lib files under the gdal generated by the previous make install compilation to the project folder
In addition to the Include header file, add a line to the project's Pro file
LIBS + = D:\\gis\\gdal\\lib\\libgdal.dll
This is to tell the compiler to link to this DLL. So you can build it.
The generated EXE defaults to Proname-build-desktop\debug
However, the operation will not be reported to Libstdc++-6.dll,libgcc_s_dw2-1.dll, these two files in the MinGW installation directory of the bin directory,
And then we'll report Libgdal, and I can't find it.
And then there's Qtcore4.dll,qtcored4.dll,mingw10.dll, and these files are in the Qt\bin directory of the QT installation directory
To copy all of the above 6 DLLs to the running directory.
If a line of Config + = static is added to the project's pro file, the compiler compiles the libgdal into the exe file
and MinGW and QT dll, because not too familiar with the makefile, I have not found the way to statically compile to exe file, otherwise it is not installed MinGW and QT machine run on the need to copy these DLLs in the past
。 One solution is to use the VC's depends tool to see exactly which DLLs are needed, so they are all copied to the running directory.
In this way, the Gdal library used to really tnnd the effort, on the VC compiled a bit, to be more convenient: (
And the process of their own exploration of a lot of information, but also spent a lot of time, want to say is the efficiency of self-study is really not high, and now also not thoroughly understand. C + + compiles the exact.
Summarize:
MinGW is a compiled environment for porting gcc,gdb to Windows, and Cygwin,msys is simulating Linux, UNIX's operating environment on Windows.
The use of configure,make is not yet ripe.
The static, dynamic compilation method is not enough to understand, so that the Def,lib,a,dll,so and other documents are not clear understanding.
Next, we will continue to do some study on the ogr part of Gdal to understand the storage model of GIS data.
Reference Documentation:
Use of the Configure command: http://topic.csdn.net/t/20030607/01/1886493.html
The role and usage of Libtool: http://socol.javaeye.com/blog/576506
MinGW how to compile Gdal: http://cache.baidu.com/c?m= 9f65cb4a8c8507ed4fece763104687270e54f73e7d82814f2488c05f93130601127bb0fb76784b40848561215af95e5c9cfa3d73200357eddd97d65e9 8e6d27e20d77c682559914163c469acdc3127d656904d9edf0ee6cae742e0b9a3d2c85523dd23026df1f69c5b70419c3cae&p= 882a93408b8600dd42be9b7e0f4fc9&user=baidu
Http://trac.osgeo.org/gdal/wiki/FAQInstallationAndBuilding#CanIbuildGDALwithCygwinorMinGW
http://www.qtcn.org/bbs/read.php?tid=22937
The common parameters of the QT Creator Engineering file Pro are explained:
http://blog.163.com/yandong_8212/blog/static/132153914201072101642792/
Qt dynamic compilation generates the dependency of the executable file http://bonfire.blogbus.com/tag/Qt/
The method of re-statically compiling QT http://www.qtcn.org/bbs/read.php?tid=17173
Gdal for C + + API Getting Started sample http://www.gdal.org/ogr/ogr_apitut.html