302 lines
8.8 KiB
Diff
302 lines
8.8 KiB
Diff
reference: https://github.com/opengribs/XyGrib/pull/289
|
|
|
|
diff a/CMakeLists.txt b/CMakeLists.txt
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -124,11 +124,11 @@
|
|
include_directories(${OPENJPEG_INCLUDE_DIR})
|
|
|
|
if(NOT WIN32)
|
|
- include(cmake/FindPROJ4.cmake)
|
|
- if(NOT PROJ4_FOUND)
|
|
- message(FATAL_ERROR "PROJ.4 library not found!")
|
|
+ include(cmake/FindPROJ.cmake)
|
|
+ if(NOT PROJ_FOUND)
|
|
+ message(FATAL_ERROR "PROJ library not found!")
|
|
endif()
|
|
- include_directories(${PROJ4_INCLUDE_DIRS})
|
|
+ include_directories(${PROJ_INCLUDE_DIRS})
|
|
endif()
|
|
if(WIN32)
|
|
find_library(PROJ4_LIBRARIES
|
|
diff a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -122,7 +122,7 @@
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/map ${MAP_GENERATED_HEADERS})
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/GUI ${GUI_GENERATED_HEADERS})
|
|
|
|
-target_link_libraries(${CMAKE_PROJECT_NAME} g2clib gui util map ${LIBNOVA_LIBRARY} ${OPENJPEG_LIBRARIES} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} ${BZIP2_LIBRARIES} ${ZLIB_LIBRARIES} ${PROJ4_LIBRARIES} ${PNG_LIBRARIES})
|
|
+target_link_libraries(${CMAKE_PROJECT_NAME} g2clib gui util map ${LIBNOVA_LIBRARY} ${OPENJPEG_LIBRARIES} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} ${BZIP2_LIBRARIES} ${ZLIB_LIBRARIES} ${PROJ_LIBRARIES} ${PNG_LIBRARIES})
|
|
|
|
# Sanitizers, part 2/2
|
|
if ( CMAKE_VERSION VERSION_GREATER 3.4 )
|
|
diff a/src/map/Projection.h b/src/map/Projection.h
|
|
--- a/src/map/Projection.h
|
|
+++ b/src/map/Projection.h
|
|
@@ -21,10 +21,7 @@
|
|
#include <QObject>
|
|
#include <cstdio>
|
|
|
|
-#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
|
|
-#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
|
|
-#endif
|
|
-#include "proj_api.h"
|
|
+#include "proj.h"
|
|
|
|
class Projection : public QObject
|
|
{
|
|
@@ -141,7 +138,7 @@
|
|
int getProjection() {return currentProj;}
|
|
|
|
private :
|
|
- projPJ libProj;
|
|
+ PJ * libProj;
|
|
int currentProj;
|
|
};
|
|
|
|
diff a/src/map/Projection_libproj.cpp b/src/map/Projection_libproj.cpp
|
|
--- a/src/map/Projection_libproj.cpp
|
|
+++ b/src/map/Projection_libproj.cpp
|
|
@@ -92,10 +92,9 @@
|
|
params[nbpar++] = "ellps=WGS84";
|
|
params[nbpar++] = "no_defs";
|
|
params[nbpar++] = "over"; // allow longitude > 180°
|
|
- // XXX ouch pj_init
|
|
- libProj = pj_init(nbpar, (char **)params);
|
|
+ libProj = proj_create_argv(PJ_DEFAULT_CTX, nbpar, (char **)params);
|
|
if (!libProj)
|
|
- printf("proj error: %s\n", pj_strerrno(pj_errno));
|
|
+ printf("proj error: %s\n", proj_errno_string(proj_errno(libProj)));
|
|
assert(libProj);
|
|
currentProj = code;
|
|
// libProj->over = 1; // allow longitude > 180°
|
|
@@ -106,23 +105,23 @@
|
|
Projection_libproj::~Projection_libproj()
|
|
{
|
|
if (libProj != nullptr) {
|
|
- pj_free(libProj);
|
|
+ proj_destroy(libProj);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
void Projection_libproj::map2screen(double x, double y, int *i, int *j) const
|
|
{
|
|
- projUV data, res;
|
|
+ PJ_COORD data, res;
|
|
if (y <= -90.0)
|
|
y = -90.0+1e-5;
|
|
if (y >= 90.0)
|
|
y = 90.0-1e-5;
|
|
- data.v = y * DEG_TO_RAD;
|
|
- data.u = x * DEG_TO_RAD;
|
|
- res = pj_fwd(data, libProj);
|
|
- *i = (int) (W/2.0 + scale * (res.u/111319.0-CX) + 0.5);
|
|
- *j = (int) (H/2.0 - scale * (res.v/111319.0-CY) + 0.5);
|
|
+ data.uv.v = y;
|
|
+ data.uv.u = x;
|
|
+ res = proj_trans(libProj, PJ_FWD, data);
|
|
+ *i = (int) (W/2.0 + scale * (res.uv.u/111319.0-CX) + 0.5);
|
|
+ *j = (int) (H/2.0 - scale * (res.uv.v/111319.0-CY) + 0.5);
|
|
//printf("PROJ map2screen (%f %f) -> (%3d %3d)\n", x,y, *i,*j);
|
|
}
|
|
|
|
@@ -130,12 +129,12 @@
|
|
//-------------------------------------------------------------------------------
|
|
void Projection_libproj::screen2map(int i, int j, double *x, double *y) const
|
|
{
|
|
- projUV data, res;
|
|
- data.u = ((i-W/2.0)/scale+ CX)*111319.0 ;
|
|
- data.v = ((H/2.0-j)/scale+ CY)*111319.0 ;
|
|
- res = pj_inv(data, libProj);
|
|
- *x = (double)(res.u*RAD_TO_DEG);
|
|
- *y = (double)(res.v*RAD_TO_DEG);
|
|
+ PJ_COORD data, res;
|
|
+ data.uv.u = ((i-W/2.0)/scale+ CX)*111319.0 ;
|
|
+ data.uv.v = ((H/2.0-j)/scale+ CY)*111319.0 ;
|
|
+ res = proj_trans(libProj, PJ_INV, data);
|
|
+ *x = (double)(res.uv.u);
|
|
+ *y = (double)(res.uv.v);
|
|
//printf("PROJ screen2map (%3d %3d) -> (%f %f)\n", i,j, *x,*y);
|
|
}
|
|
//--------------------------------------------------------------
|
|
--- a/cmake/FindPROJ4.cmake
|
|
+++ /dev/null
|
|
@@ -1,76 +0,0 @@
|
|
-# - Find PROJ4
|
|
-# Find the PROJ4 includes and library
|
|
-#
|
|
-# PROJ4_INCLUDE_DIR - Where to find PROJ4 includes
|
|
-# PROJ4_LIBRARIES - List of libraries when using PROJ4
|
|
-# PROJ4_FOUND - True if PROJ4 was found
|
|
-
|
|
-IF(PROJ4_INCLUDE_DIR)
|
|
- SET(PROJ4_FIND_QUIETLY TRUE)
|
|
-ENDIF(PROJ4_INCLUDE_DIR)
|
|
-
|
|
-FIND_PATH(PROJ4_INCLUDE_DIR "proj_api.h"
|
|
- PATHS
|
|
- $ENV{EXTERNLIBS}/include
|
|
- $ENV{EXTERNLIBS}/proj4/include
|
|
- ~/Library/Frameworks/include
|
|
- /Library/Frameworks/include
|
|
- /usr/local/include
|
|
- /usr/include
|
|
- /sw/include # Fink
|
|
- /opt/local/include # DarwinPorts
|
|
- /opt/csw/include # Blastwave
|
|
- /opt/include
|
|
- DOC "PROJ4 - Headers"
|
|
-)
|
|
-
|
|
-SET(PROJ4_NAMES Proj4 proj proj_4_9)
|
|
-SET(PROJ4_DBG_NAMES Proj4D projD proj_4_9_D)
|
|
-
|
|
-FIND_LIBRARY(PROJ4_LIBRARY NAMES ${PROJ4_NAMES}
|
|
- PATHS
|
|
- $ENV{EXTERNLIBS}
|
|
- $ENV{EXTERNLIBS}/proj4
|
|
- ~/Library/Frameworks
|
|
- /Library/Frameworks
|
|
- /usr/local
|
|
- /usr
|
|
- /sw
|
|
- /opt/local
|
|
- /opt/csw
|
|
- /opt
|
|
- PATH_SUFFIXES lib lib64
|
|
- DOC "PROJ4 - Library"
|
|
-)
|
|
-
|
|
-INCLUDE(FindPackageHandleStandardArgs)
|
|
-
|
|
-IF(MSVC)
|
|
- # VisualStudio needs a debug version
|
|
- FIND_LIBRARY(PROJ4_LIBRARY_DEBUG NAMES ${PROJ4_DBG_NAMES}
|
|
- PATHS
|
|
- $ENV{EXTERNLIBS}/proj4/lib
|
|
- DOC "PROJ4 - Library (Debug)"
|
|
- )
|
|
-
|
|
- IF(PROJ4_LIBRARY_DEBUG AND PROJ4_LIBRARY)
|
|
- SET(PROJ4_LIBRARIES optimized ${PROJ4_LIBRARY} debug ${PROJ4_LIBRARY_DEBUG})
|
|
- ENDIF(PROJ4_LIBRARY_DEBUG AND PROJ4_LIBRARY)
|
|
-
|
|
- FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ4 DEFAULT_MSG PROJ4_LIBRARY PROJ4_LIBRARY_DEBUG PROJ4_INCLUDE_DIR)
|
|
-
|
|
- MARK_AS_ADVANCED(PROJ4_LIBRARY PROJ4_LIBRARY_DEBUG PROJ4_INCLUDE_DIR)
|
|
-
|
|
-ELSE(MSVC)
|
|
- # rest of the world
|
|
- SET(PROJ4_LIBRARIES ${PROJ4_LIBRARY})
|
|
-
|
|
- FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ4 DEFAULT_MSG PROJ4_LIBRARY PROJ4_INCLUDE_DIR)
|
|
-
|
|
- MARK_AS_ADVANCED(PROJ4_LIBRARY PROJ4_INCLUDE_DIR)
|
|
-
|
|
-ENDIF(MSVC)
|
|
-
|
|
-IF(PROJ4_FOUND)
|
|
- SET(PROJ4_INCLUDE_DIRS ${PROJ4_INCLUDE_DIR})
|
|
-ENDIF(PROJ4_FOUND)
|
|
--- /dev/null
|
|
+++ b/cmake/FindPROJ.cmake
|
|
@@ -0,0 +1,96 @@
|
|
+# - Find PROJ
|
|
+# Find the PROJ includes and library
|
|
+#
|
|
+# PROJ_INCLUDE_DIR - Where to find PROJ includes
|
|
+# PROJ_LIBRARIES - List of libraries when using PROJ
|
|
+# PROJ_FOUND - True if PROJ was found
|
|
+
|
|
+IF(PROJ_INCLUDE_DIR)
|
|
+ SET(PROJ_FIND_QUIETLY TRUE)
|
|
+ENDIF(PROJ_INCLUDE_DIR)
|
|
+
|
|
+FIND_PATH(PROJ_INCLUDE_DIR "proj.h"
|
|
+ PATHS
|
|
+ $ENV{EXTERNLIBS}/include
|
|
+ $ENV{EXTERNLIBS}/PROJ/include
|
|
+ ~/Library/Frameworks/include
|
|
+ /Library/Frameworks/include
|
|
+ /usr/local/include
|
|
+ /usr/include
|
|
+ /sw/include # Fink
|
|
+ /opt/local/include # DarwinPorts
|
|
+ /opt/csw/include # Blastwave
|
|
+ /opt/include
|
|
+ DOC "PROJ - Headers"
|
|
+)
|
|
+
|
|
+IF(PROJ_INCLUDE_DIR)
|
|
+ SET(PROJ_NAMES PROJ proj proj_8_0)
|
|
+ SET(PROJ_DBG_NAMES PROJD projD proj_8_0_1)
|
|
+ELSE(PROJ_INCLUDE_DIR)
|
|
+ FIND_PATH(PROJ_INCLUDE_DIR "proj_api.h"
|
|
+ PATHS
|
|
+ $ENV{EXTERNLIBS}/include
|
|
+ $ENV{EXTERNLIBS}/PROJ/include
|
|
+ ~/Library/Frameworks/include
|
|
+ /Library/Frameworks/include
|
|
+ /usr/local/include
|
|
+ /usr/include
|
|
+ /sw/include # Fink
|
|
+ /opt/local/include # DarwinPorts
|
|
+ /opt/csw/include # Blastwave
|
|
+ /opt/include
|
|
+ DOC "PROJ - Headers"
|
|
+ )
|
|
+ ADD_DEFINITIONS(-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1)
|
|
+ SET(PROJ_NAMES PROJ proj proj_4_9)
|
|
+ SET(PROJ_DBG_NAMES PROJD projD proj_4_9_D)
|
|
+ENDIF(PROJ_INCLUDE_DIR)
|
|
+
|
|
+FIND_LIBRARY(PROJ_LIBRARY NAMES ${PROJ_NAMES}
|
|
+ PATHS
|
|
+ $ENV{EXTERNLIBS}
|
|
+ $ENV{EXTERNLIBS}/PROJ
|
|
+ ~/Library/Frameworks
|
|
+ /Library/Frameworks
|
|
+ /usr/local
|
|
+ /usr
|
|
+ /sw
|
|
+ /opt/local
|
|
+ /opt/csw
|
|
+ /opt
|
|
+ PATH_SUFFIXES lib lib64
|
|
+ DOC "PROJ - Library"
|
|
+)
|
|
+
|
|
+INCLUDE(FindPackageHandleStandardArgs)
|
|
+
|
|
+IF(MSVC)
|
|
+ # VisualStudio needs a debug version
|
|
+ FIND_LIBRARY(PROJ_LIBRARY_DEBUG NAMES ${PROJ_DBG_NAMES}
|
|
+ PATHS
|
|
+ $ENV{EXTERNLIBS}/PROJ/lib
|
|
+ DOC "PROJ - Library (Debug)"
|
|
+ )
|
|
+
|
|
+ IF(PROJ_LIBRARY_DEBUG AND PROJ_LIBRARY)
|
|
+ SET(PROJ_LIBRARIES optimized ${PROJ_LIBRARY} debug ${PROJ_LIBRARY_DEBUG})
|
|
+ ENDIF(PROJ_LIBRARY_DEBUG AND PROJ_LIBRARY)
|
|
+
|
|
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ DEFAULT_MSG PROJ_LIBRARY PROJ_LIBRARY_DEBUG PROJ_INCLUDE_DIR)
|
|
+
|
|
+ MARK_AS_ADVANCED(PROJ_LIBRARY PROJ_LIBRARY_DEBUG PROJ_INCLUDE_DIR)
|
|
+
|
|
+ELSE(MSVC)
|
|
+ # rest of the world
|
|
+ SET(PROJ_LIBRARIES ${PROJ_LIBRARY})
|
|
+
|
|
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROJ DEFAULT_MSG PROJ_LIBRARY PROJ_INCLUDE_DIR)
|
|
+
|
|
+ MARK_AS_ADVANCED(PROJ_LIBRARY PROJ_INCLUDE_DIR)
|
|
+
|
|
+ENDIF(MSVC)
|
|
+
|
|
+IF(PROJ_FOUND)
|
|
+ SET(PROJ_INCLUDE_DIRS ${PROJ_INCLUDE_DIR})
|
|
+ENDIF(PROJ_FOUND)
|