Skip to content

Commit

Permalink
[Fix]修复GDAL_DATA和PROJ_DATA错误
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Apr 7, 2022
1 parent bbf55ab commit d558793
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 599 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ out
.vs
.idea
.gitignore
.gitattributes
.gitattributes
cmake-build*
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ if(MSVC)
add_definitions(-DNOMINMAX)
endif()

option(ENABLE_TEST "Enable test" ON)

find_package(GDAL REQUIRED)
find_package(PROJ REQUIRED)
find_package(Qt5
REQUIRED
COMPONENTS Core Xml Test)
Expand All @@ -30,5 +33,18 @@ set(CMAKE_AUTORCC ON)

add_subdirectory(src)

enable_testing(true)
add_subdirectory(test)
if(ENABLE_TEST)
enable_testing(true)
add_subdirectory(test)
add_custom_target(CopyResources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/src/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/test/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/src/gdal_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/test/gdal_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/test/data)

else()
add_custom_target(CopyResources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/proj_data ${PROJECT_BINARY_DIR}/src/proj_data
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/gdal_data ${PROJECT_BINARY_DIR}/src/gdal_data)
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ Converter.exe --format gdal --input <GDB Path> --output <DIR> --field height --
1. 通过Qt官网安装
2. vcpkg install "qt5[all]"
3. VS2019选择CMakeLists.txt,导入工程,编译
4. 把OSGPlugins文件夹复制到编译目录下
4. 将OSGPlugins-${Version}文件夹复制到编译目录下
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 13 additions & 9 deletions include/CoordinateConvert.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <GDALWrapper.h>
#include <OGRException.h>
#include <osg/Math>

namespace scially {

class CoordinateConvert : QObject {
Expand All @@ -18,22 +19,25 @@ namespace scially {
WKT,
EPSG,
Proj4,
Esri,
};
Q_ENUM(SrsType);

CoordinateConvert(double x, double y) : sourceX(x), sourceY(y), targetX(0), targetY(0) {}
CoordinateConvert() : CoordinateConvert(0, 0) {}

void setSourceSrs(const QString& srs, SrsType t) noexcept(false);
void setTargetSrs(const QString& srs, SrsType t) noexcept(false);
void transform() noexcept(false);
CoordinateConvert(double x, double y) : sourceX(x), sourceY(y), targetX(0), targetY(0) {
static internal::GDALDriverWrapper init;
}
CoordinateConvert() : CoordinateConvert(0, 0) { }


void setSourceSrs(const QString& srs, SrsType t) ;
void setTargetSrs(const QString& srs, SrsType t);
void transform() ;

private:
void setSrs(OGRSpatialReference& srs, const QString& describe, SrsType t) ;
OGRCoordinateTransformationPtr createCoordinateTransformation();
void init() const {
const char* projResource = "proj_data";
proj_context_set_search_paths(nullptr, 1, &projResource);
}
private:
OGRSpatialReference sourceSrs;
OGRSpatialReference targetSrs;
Expand Down
8 changes: 8 additions & 0 deletions include/GDALWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
#include <OGRException.h>
#include <QSharedPointer>
#include <ogrsf_frmts.h>
#include <proj.h>

namespace scially {
namespace internal {
class GDALDriverWrapper {
public:
GDALDriverWrapper() {
init();
}
private:
void init() const {
CPLSetConfigOption("GDAL_DATA","gdal_data");
const char* projResource = "proj_data";
proj_context_set_search_paths(nullptr, 1, &projResource);
GDALAllRegister();
}
};
Expand Down
40 changes: 13 additions & 27 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ add_library(Core STATIC
"../include/tiny_gltf.h"
"../include/TilesParseException.h"
"../include/TilesConvertException.h"
"../include/OSGBConvertJob.h"
"../include/OSGBConvertJob.h"
"../include/ShpConvertJob.h"
"../include/ModelMetadata.h"
"../include/QuadTree.h"
"../include/ShpConvert.h"
"../include/GeometryMesh.h"
"../include/GDALWrapper.h"
"../include/ModelMetadata.h"
"../include/QuadTree.h"
"../include/ShpConvert.h"
"../include/GeometryMesh.h"
"../include/GDALWrapper.h"
"../include/Batched3DModel.h"
"../include/Utils.h"
"../include/earcut.hpp"
"../include/earcut.hpp"

"CoordinateConvert.cpp"
"OSGBPageLodVisitor.cpp"
Expand All @@ -47,37 +47,23 @@ add_library(Core STATIC
"OSGBuildState.cpp"
"OSGBLevel.cpp"
"OSGBConvert.cpp"
"OSGBConvertJob.cpp"
"ModelMetadata.cpp"
"QuadTree.cpp"
"GeometryMesh.cpp"
"GDALWrapper.cpp"
"OSGBConvertJob.cpp"
"ModelMetadata.cpp"
"QuadTree.cpp"
"GeometryMesh.cpp"
"Batched3DModel.cpp"
"ShpConvert.cpp"
"ShpConvertJob.cpp")


target_link_libraries(Core
${GDAL_LIBRARY}
${PROJ_LIBRARIES}
${OPENSCENEGRAPH_LIBRARIES}
Qt5::Core
Qt5::Xml)


add_executable(Converter "main.cpp")
target_link_libraries(Converter
${GDAL_LIBRARY}
${OPENSCENEGRAPH_LIBRARIES}
Qt5::Core
Qt5::Xml
Core)

add_custom_command(
TARGET Converter PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/proj_data/proj.db
${CMAKE_BINARY_DIR}/src/proj.db
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/proj_data/proj.ini
${CMAKE_BINARY_DIR}/src/proj.ini)
target_link_libraries(Converter Core)

6 changes: 3 additions & 3 deletions src/CoordinateConvert.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <CoordinateConvert.h>

namespace scially {
void CoordinateConvert::setSourceSrs(const QString& srs, SrsType t) noexcept(false) {
void CoordinateConvert::setSourceSrs(const QString& srs, SrsType t) {
setSrs(sourceSrs, srs, t);
}

void CoordinateConvert::setTargetSrs(const QString& srs, SrsType t) noexcept(false) {
void CoordinateConvert::setTargetSrs(const QString& srs, SrsType t) {
setSrs(targetSrs, srs, t);
}

void CoordinateConvert::transform() noexcept(false) {
void CoordinateConvert::transform() {
auto transform = createCoordinateTransformation();
double x = sourceX, y = sourceY;
bool succeed = transform->Transform(1, &x, &y);
Expand Down
1 change: 0 additions & 1 deletion src/GDALWrapper.cpp

This file was deleted.

8 changes: 2 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#include <OSGBConvertJob.h>
#include <ShpConvertJob.h>
#include <TilesConvertException.h>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QProcessEnvironment>
#include <QDebug>
#include <QTime>

int main(int argc, char** argv){
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("Cesium3DTilesConverter");
QCoreApplication::setApplicationVersion("0.1");
QCoreApplication::setApplicationVersion("0.2");
QTime beginTime = QTime::currentTime();
QCommandLineParser parser;
parser.setApplicationDescription("Convert osgb,shp to Cesium 3dtiles");
parser.setApplicationDescription("Convert OSGB, GDAL to Cesium 3DTiles");
parser.addHelpOption();
parser.addVersionOption();
const QCommandLineOption inputOption("input", "input path", "input");
Expand All @@ -35,7 +32,6 @@ int main(int argc, char** argv){
const QCommandLineOption yUpAxis("yUpAxis", "y up axis", "yUpAxis");
parser.addOption(yUpAxis);


parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.process(app);

Expand Down
30 changes: 1 addition & 29 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# TestGDAL
add_executable(TestGDAL "TestGDAL.cpp")
target_link_libraries(TestGDAL Qt5::Test Core)
Expand All @@ -12,31 +11,4 @@ add_test(name Test3DTiles command Test3DTiles)
# TestOSGBConvert
add_executable(TestOSGBConvert "TestOSGBConvert.cpp")
target_link_libraries(TestOSGBConvert Qt5::Test Core)
add_test(name TestOSGBConvert command TestOSGBConvert)

# TestOSGBLevel
add_executable(TestOSGBLevel "TestOSGBLevel.cpp")
target_link_libraries(TestOSGBLevel Qt5::Test Core)
add_test(name TestOSGBLevel command TestOSGBLevel)

# TestOSGBLevel
add_executable(TestOSGBConvertJob "TestOSGBConvertJob.cpp")
target_link_libraries(TestOSGBConvertJob Qt5::Test Core)
add_test(name TestOSGBConvertJob command TestOSGBConvertJob)

#add_custom_command(
# TARGET CopyTestResources PRE_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# ${CMAKE_CURRENT_SOURCE_DIR}/data
# ${CMAKE_BINARY_DIR}/test/data)

add_custom_target(CopyTestResources ALL)
add_custom_command(
TARGET CopyTestResources PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/proj_data/proj.db
${CMAKE_BINARY_DIR}/test/proj.db
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/proj_data/proj.ini
${CMAKE_BINARY_DIR}/test/proj.ini)

add_test(name TestOSGBConvert command TestOSGBConvert)
Loading

0 comments on commit d558793

Please sign in to comment.