PROJ4 compilation and use (Windows platform) - 32-bit library

Recently, I have been busy working on projects and coding every day, so there is no programming contact every day. At present, the major framework of the project has been written. Here is a summary of some things in the project.

What I am doing is the project of remote sensing images, and the coordinate conversion to be used. I am not a remote sensing professional, so my understanding of some concepts is not so accurate. Because the big frame uses the GDAL library, after searching for the data, the coordinate conversion, that is, the conversion between geographic coordinates and projected coordinates, is determined, and the proj.4 library to be used.

The Proj.4 library is the most famous map projection library for open source GIS. The projection conversion function in the famous open source image library gdal also dynamically calls the library function. The latest version is proj-4.9.2. The download address of the proj4 library is: https://github.com/OSGeo/proj.4

After downloading and decompressing, the compilation method is basically the same as that of the GDAL library. For the selection of the command line, please refer to the special instructions in the previous article.

1. Library directory settings

In the proj4 directory, edit the nmake.opt file and modify the value of INSTDIR. If you do not modify the build path of the library. After compiling, the PROJ folder will be created by default in the root directory of the C drive. There are four folders in it, namely bin, lib, include and share. Among them, include and lib are used for the second For secondary development use, bin stores dll and exe files, and share stores some projection files defined by PROJ4, etc. When publishing the program, the share folder needs to be published together, otherwise when doing projection conversion, it may be because of The conversion failed because the files in it could not be found.
2. Compile according to the local situation.
First configure vs to the user environment variable
write picture description here
. Enter cmd at the beginning
write picture description here
write picture description here
and then press the readme in the compressed package to execute the command:
execute the script in\VCVARS32.BAT (this is very important, otherwise the compilation will fail and cannot be found Corresponding function analysis)
nmake /f makefile.vc
nmake /f makefile.vc install-all

2. Compilation of the 32-bit RELEASE version of the proj4 library

Open the 32-bit command line tool for VS, then change its working directory to the directory of proj4, then enter
nmake /f makefile.vc
nmake /f makefile.vc install-all

3. Compilation of the 32-bit DEBUG version of the proj4 library

Open the x86 command line tool for VS, then change its working directory to the directory of proj4, then enter
nmake /f makefile.vc
nmake /f makefile.vc install-all DEBUG=1

4. Compilation of 64-bit proj4 library

Open the 64-bit command line tool for VS, then change its working directory to the directory of proj4, then enter
nmake /f makefile.vc
nmake /f makefile.vc install-all

5. Call in VS

Include the include and lib libraries in the generated file into the project file, add proj.lib and proj_i.lib, and copy the dll file under bin to the project directory.

6. Test chestnuts

#include <proj_api.h>
#include <iostream>

int main(int argc, char **argv)
{
    projPJ pj_merc, pj_latlong;
    double x, y;

    if (!(pj_merc = pj_init_plus("+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")))
    exit(1);
    if (!(pj_latlong = pj_init_plus("+proj=longlat +datum=WGS84 +no_defs")))
    exit(1);

    x = -9.866554;
    y = 7.454779;
    x *= DEG_TO_RAD;
    y *= DEG_TO_RAD;
    pj_transform(pj_latlong, pj_merc, 1, 1, &x, &y, NULL);

    std::cout.precision(12);
    std::cout << "(" << x << " , " << y << ")" << std::endl;

    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325459824&siteId=291194637