Qt+GDAL development notes (1): compile GDAL library, build development environment and basic Demo in mingw32 of windows system

If the article is an original article, please indicate the source of the original article when reprinting.
The blog address of this article: https://hpzwl.blog.csdn.net/article/details/131931309

Red Fatty Network Technology Blog Encyclopedia: Development technology collection (including Qt practical technology, Raspberry Pi, 3D, OpenCV, OpenGL, ffmpeg, OSG, single-chip microcomputer, combination of software and hardware, etc.) is continuously updated...

Qt development column: Three-party library development technology

Previous: No more
Next: Stay tuned...


foreword

  The global Beidou positioning terminal development is done on the Kirin system, and the debugging tool needs to be a windows version for easy proofreading. The Beidou GPS sends the geodetic coordinates, and the application needs the latitude and longitude coordinates, so it needs to be converted. You can use the formula to convert, but it involved mountains before. He intelligently used WG for a project, and finally chose the GDAL library for conversion.

Notice

  If the reader does not require mingw32, it is recommended not to use the mingw32 version of dgal. The compilation process is very tortuous.


related blog

  " Kylin System Development Notes (12): Compile the GDAL library on the domestic Kylin system, build a basic development environment and a basic demo" "Qt +
  GDAL Development Notes (1): Compile the GDAL library on the windows system mingw32, build a development environment and foundation Demo


Introduction to Geodetic Coordinates

overview

  Geodetic coordinates are the coordinates of the reference ellipsoid in geodetic surveying. The position of the ground point P is expressed by the longitude L of the earth, the latitude B of the earth and the height H of the earth.

principle

  When the point is on the reference ellipsoid, it is only represented by geodetic longitude and geodetic latitude. The geodetic longitude is the angle between the geodetic plane passing through the point and the origin geodetic plane (the meridian plane passing through the Greenwich Observatory). It is stipulated that counting from the starting meridian plane, the east longitude from 0° to 180° is called east longitude; the west longitude from 0° to 180° is called west longitude. Geodetic latitude is the angle between the normal line passing through the point and the equatorial plane. It is stipulated that starting from the equatorial plane, the north latitude from 0° to 90° from the equatorial plane is called north latitude; the south latitude from 0° to 90° is called south latitude. The geodetic height is the distance from the ground point along the normal to the reference ellipsoid.

Beijing 54 coordinate system: BJZ54

  The Beijing 54 coordinate system (BJZ54) means that the Beijing 54 coordinate system is the ginseng geodetic coordinate system. A point on the earth can be located by longitude L54, latitude M54 and geodetic height H54. It is based on the Krasovsky ellipsoid. The resulting coordinate system after the local adjustment.

  • Semi-major axis a = 6378245m
  • Semi-minor axis b = 6356863.0188m
  • First eccentricity squared e2 = 0.006693421622
  • Flatness α =1/298.3

World Geodetic Coordinate System: WGS-84

  The WGS-84 coordinate system is the world geodetic coordinate system, its coordinate origin is at the center of the earth, and the WGS-84 ellipsoid (1984 world geodetic coordinate system) is adopted.
  The WGS-84 coordinate system is a geodetic coordinate system developed and determined by the US Department of Defense, and it is a protocol earth coordinate system.
  The definition of the WGS-84 coordinate system is: the origin is the center of mass of the earth, and the Z-axis of the space rectangular coordinate system points to the direction of the earth pole (CTP) defined by BIH (1984.0), which is the origin of the international agreement CIO, which is jointly recommended by IAU and IUGG. The X-axis points to the intersection of the zero-degree meridian defined by the BIH and the CTP equator, and the Y-axis and Z-axis form a right-handed coordinate system.
  The WGS-84 ellipsoid adopts the recommended values ​​of the measurement constants of the 17th Congress of the International Union of Geodesy and Geophysics, and uses two commonly used basic geometric parameters:

  • Semi-major axis a = 6378137m
  • Semi-minor axis b = 6356752.3142m
  • First eccentricity squared e2 = 0.00669437999013
  • Flatness α= 1/298.257223563

National Geodetic Coordinate System: CGCS2000

  The 2000 National Geodetic Coordinate System is the latest national geodetic coordinate system in my country. The English name is China Geodetic Coordinate System 2000, and the English abbreviation is CGCS2000.
  The origin of the 2000 national geodetic coordinate system is the center of mass of the entire earth including the ocean and atmosphere; the Z-axis of the 2000 national geodetic coordinate system points from the origin to the direction of the earth reference pole of epoch 2000.0, and the direction of this epoch is given by the International Time Bureau The fixed epoch is the initial orientation calculation of 1984.0, and the time evolution of the orientation ensures that there will be no residual global rotation relative to the crust. Axis and X axis form a right-handed orthogonal coordinate system. Use the scale in the sense of general relativity.

  • Semi-major axis a = 6378137m
  • Semi-minor axis b = 6356752.314m
  • First eccentricity squared e2 = 0.00669438002290
  • Flatness α = 1/298.257222101

GDAL library

overview

  GDAL (Geospatial Data Abstraction Library) is an open source raster spatial data conversion library under the X/MIT license agreement. It utilizes an abstract data model to express the various supported file formats. It also has a collection of command-line tools for data transformation and manipulation. OGR is a fork of the GDAL project that provides support for vector data. There are many well-known GIS products that use the GDAL/OGR library, including ESRI's ARCGIS 9.3, Google Earth and the cross-platform GRASS GIS system. Using the GDAL/OGR library, the Linux-based geospatial data management system can provide support for vector and raster file data.

Features

  • GDAL provides support for a variety of raster data, including Arc/Info ASCII Grid (asc), GeoTiff (tiff), Erdas Imagine Images (img), ASCII DEM (dem) and other formats.
  • GDAL uses an abstract data model (abstract data model) to parse the data formats it supports. The abstract data model includes datasets, coordinate systems, affine geographic coordinate transformation (Affine Geo Transform), and geodetic control points (GCPs). Metadata, Raster Band, Color Table, Subdatasets Domain, Image_Structure Domain, XML Domains.
  • GDALMajorObject class: an object with metadata.
  • GDALDdataset class: usually a collection of associated raster bands extracted from a raster file and the metadata of these bands;
  • GDALDdataset is also responsible for the georeferencing transform and coordinate system definition of all raster bands.
  • GDALDriver class: file format driver class, GDAL will create an entity of this class for each supported file format to manage the file format.
  • GDALDriverManager class: file format driver management class, used to manage the GDALDriver class.

OGR Architecture

  • Geometry class: Geometry (including OGRGeometry and other classes) encapsulates the vector data model of OpenGIS, and provides some geometric operations, mutual conversion between WKB (Well Knows Binary) and WKT (Well Known Text) formats, and spatial reference system ( projection).
  • Spatial Reference class: OGRSpatialReference encapsulates the definition of projection and datum.
  • Feature class: OGRFeature encapsulates the definition of a complete feature, and a complete feature includes a geometry and a series of attributes of the geometry.
  • Feature Definition class: OGRFeatureDefn encapsulates feature attributes, type, name and its default spatial reference system. An OGRFeatureDefn object usually corresponds to a layer.
  • Layer class: OGRLayer is an abstract base class that represents a layer of features in the data source class OGRDataSource.
  • Data Source class: OGRDataSource is an abstract base class representing a file or a database containing OGRLayer objects.
  • Drivers class: OGRSFDriver corresponds to each supported vector file format. Class OGRSFDriver is registered and managed by class OGRSFDriverRegistrar.

download link

  Home: https://gdal.org/download.html
 select version 3.2.1


Prepare the MSYS2 compilation environment

  (Here, when using mysy1.0 first, the system enumeration is unknown, so change to msys2).
  (Here msys2 has stepped on the pit for a few days, and the dependent libraries depend on glibc, libtool, pkg-config and other issues, and they go around each other. After finally being able to compile, the system logo cannot be recognized at the end. I am still insisting, so I changed it again Download msys642, do it again, remove all paths, install directly into msys642, and then start using the path prefix to configure and then compile and install the extracted library file) This is the environment where the Linux library is compiled above windows
  .
  Download it yourself and unzip it:
  insert image description here

  Click "msys2.bat" to start:
  insert image description here

  Here we need to use the mingw32 development of Qt5.9.3, so we need to copy the mingw32 compiler of Qt to this root directory, so that it can be introduced in the qualified msys environment:
  insert image description here

  Then:
  insert image description here

  The path is imported under:

export PATH=$PATH:/mingw530_32/bin

  insert image description here


compile GDAL

Step 1: Download and decompress

export PATH=$PATH:/mingw530_32/bin
cd /home/21497/compile
mkdir gdal

  insert image description here

  Then copy the gdal package to the main directory of msys:
  insert image description here

cd gdal
tar xvf gdal-3.2.1.tar.gz
ls -l

  insert image description here

Step 2: Configure configure

  Here, the prefix parameter is set in order to let the library be generated to the specified directory:

cd /home/21497/compile/gdal/gdal-3.2.1
./configure --prefix=/home/21497/compile/gdal/install
./configure --prefix=/home/21497/compile/gdal/install --without-libtool

  insert image description here

  Error "configure: error: PROJ 6 symbols not found", need to compile PROJ6:
  insert image description here

  Please refer to the following chapter "Compile PROJ6". After the compilation is complete, go back here to continue the configuration:

cd gdal-3.2.1
./configure

  It still reports an error, but you can know that there are already header files and library files, and then start to force:
  insert image description here

  insert image description here

  Still can't find the header file, here's another one:
  insert image description here

  Not enough, just comment it out for him:
  insert image description here

  Directly force the comments to be read, and force the definition of HAVA_PROJ_H (every folder is placed, and the test is also forced to be shielded, so it will not pass, the final result of the source code method:
  insert image description here

  Configure via:
  insert image description here

  Proj6 is also yes.

Step 3: Compile mak

  (PS: For this library, mingw32-make has an error or exception, and make can pass. Basically, if the former cannot pass, use make. Anyway, when it is compiled, it is pure gcc, and gcc is introduced into the gcc of mingw32 of Qt5.9.3)

make -j4

  Start compiling, this gdal library compiles, it takes some time, and an error occurs:
  insert image description here

  This msys642 does have some problems with the header files, or the old way, you can copy all the headers directly to this "geo_keyp.h" folder, so theoretically you can:
  insert image description here

  After compiling, it has indeed passed (PS: why msys642 does not load the path of the header file by itself, and the additional environment variable does not work, so I will not study it carefully), continue compiling:

make

  insert image description here

  After compiling:
  insert image description here

  Continue to make without j to make sure that it has been compiled correctly:
  insert image description here

  insert image description here

Step 4: Install make install

  Install

make install

  insert image description here

  insert image description here

Step 5: Import the compiled library into the project

  (PS: The project here is based on the Kirin system v1.0.0, upgraded to v1.1.0, and integrated with the mingw32 version of the windows platform Qt5.9.3) The
  previous installations are all installed in the system path, so the library of the system path is first introduced here.
  insert image description here

  So far, success.


Compile PROJ6

Step 1: Download and decompress

  Download address: https://proj.org
  Select version 6.2.0
  to download and copy to MSYS2:

cd /home/21497/compile
mkdir proj
cd proj

  

tar xfv proj-6.2.0.tar.gz

  

Step 2: Configure configure

  Here, the prefix parameter is set in order to let the library be generated to the specified directory:

cd /home/21497/compile/proj/proj-6.2.0/
./configure --prefix=/home/21497/compile/proj/install
./configure --without-libtool

  
  Configuration error "SQLITE3", as shown in the figure below:
  
  Please refer to the following chapter "Compile SQLITE3". After the compilation is completed, return here to continue the configuration:

cd /home/21497/compile/proj/proj-6.2.0/

  At this time, there is still an error when compiling. The error may be a pkgconfig problem. Install "compile pkgconfig" and change to mingw642 to solve it. Continue:
  

Step 3: Compile make

make -j4

  Start compiling:
  insert image description here

  insert image description here

  Here, the header file is not found:
  insert image description here

  Adding the header file path still reports an error, force it directly, and then continue:
  insert image description here

  insert image description here

  Adding the library path still reports an error, force it directly, and then continue:
  insert image description here

  Finally compiled the past:
  insert image description here

  insert image description here

  Back to the "gdal" library.

Step 4: Install make install

  To use administrator privileges, otherwise the installation will fail and the system directory cannot be created:

sudo make install

  Test, you can rely on it without ldconfig, so far the proj6 library has been compiled.


Compile SQLITE3

Step 1: Download and decompress

  https://www.sqlite.org/download.html
  insert image description here

  insert image description here

tar xvf sqlite-autoconf-3420000.tar.gz

  insert image description here

Step 2: Configure configure

  Here, the prefix parameter is set in order to let the library be generated to the specified directory:

cd /home/21497/compile/sqlite3/sqlite-autoconf-3420000
./configure --prefix=/home/21497/compile/sqlite3/install

  insert image description here

  Configuration error:
  insert image description here

  (PS: Don’t panic in everything, slowly open your eyes to see the error line by line)
  Modify the configuration:

./configure --prefix=/home/21497/compile/sqlite3/install --disable-dependency-tracking

  Then continue to configure:
  insert image description here

  The configuration was successful:
  insert image description here

Step 3: Compile make

  insert image description here

  Compilation here will cause libtool to make an error, and there is no solution, so try to reverse sqlite by one version, and it will pass. Repeat the steps:
  insert image description here

cd sqlite-snapshot-202101271915
./configure --prefix=/home/21497/compile/sqlite3/install
mingw32-make.exe -j4

  insert image description here
  insert image description here

Step 4: Install make install

mingw32-make install

  It failed, as shown below:
  insert image description here

  Because make is different, modify the Makefile directly:
  insert image description here

  You can pass:
  insert image description here

Step 5: Check that the compilation is successful

  insert image description here

  The above is to extract the path, and there is a problem with the compilation of the library that relies on it:
  insert image description here

  For one-size-fits-all, reconfigure directly without a path and deploy to msys:

cd /home/21497/compile/sqlite3/sqlite-snapshot-202101271915/
./configure
mingw32-make.exe
mingw32-make install

  (Install remember to modify the CC of Makefile to mingw32-make)
  insert image description here

  Change msys642 and 3.42, use make (not use mingw32-make) successfully:
  insert image description here
  insert image description here
  insert image description here


Compile pkgconfig (obsolete, but keep step)

Step 1: Download and decompress

  Download address: https://www.freedesktop.org/wiki/Software/pkg-config/
  insert image description here

tar xvf pkgconfig-0.6.0.tar.gz

  insert image description here

Step 2: Configure configure

cd pkgconfig-0.6.0/
./configure

  insert image description here

  insert image description here

  For version 0.29:
  insert image description here

  Modify the configuration:

./configure –with-internal-glib

  There are various errors, but there is no solution. Later, the mingw32-make configuration proj6 will not have this error.


end

  There are many attempts to solve the problem in this article. After the final compilation, there is no need to introduce the module, because the solution process takes about three days. Trial and error in various msys environments, various open source library versions, path source code adjustments, and finally this article just finished.
  If the reader does not require mingw32, it is recommended not to use the mingw32 version of dgal.


Previous: No more
Next: Stay tuned...


If the article is an original article, please indicate the source of the original article when reprinting.
The blog address of this article: https://hpzwl.blog.csdn.net/article/details/131931309

Guess you like

Origin blog.csdn.net/qq21497936/article/details/131931309