34
34
#include " commonutils.h"
35
35
#include " cpl_conv.h"
36
36
#include " cpl_error.h"
37
+ #include " cpl_float.h"
37
38
#include " cpl_progress.h"
38
39
#include " cpl_string.h"
39
40
#include " cpl_vsi.h"
@@ -64,7 +65,8 @@ typedef enum
64
65
HIGHEST_RESOLUTION,
65
66
AVERAGE_RESOLUTION,
66
67
SAME_RESOLUTION,
67
- USER_RESOLUTION
68
+ USER_RESOLUTION,
69
+ COMMON_RESOLUTION,
68
70
} ResolutionStrategy;
69
71
70
72
struct DatasetProperty
@@ -1016,6 +1018,21 @@ std::string VRTBuilder::AnalyseRaster(GDALDatasetH hDS,
1016
1018
// ns_res is negative, the highest resolution is the max value.
1017
1019
ns_res = std::max (ns_res, padfGeoTransform[GEOTRSFRM_NS_RES]);
1018
1020
}
1021
+ else if (resolutionStrategy == COMMON_RESOLUTION)
1022
+ {
1023
+ we_res = CPLGreatestCommonDivisor (
1024
+ we_res, padfGeoTransform[GEOTRSFRM_WE_RES]);
1025
+ if (we_res == 0 )
1026
+ {
1027
+ return " Failed to get common resolution" ;
1028
+ }
1029
+ ns_res = CPLGreatestCommonDivisor (
1030
+ ns_res, padfGeoTransform[GEOTRSFRM_NS_RES]);
1031
+ if (ns_res == 0 )
1032
+ {
1033
+ return " Failed to get common resolution" ;
1034
+ }
1035
+ }
1019
1036
else
1020
1037
{
1021
1038
we_res = std::max (we_res, padfGeoTransform[GEOTRSFRM_WE_RES]);
@@ -1942,6 +1959,8 @@ GDALDatasetH GDALBuildVRT(const char *pszDest, int nSrcCount,
1942
1959
eStrategy = LOWEST_RESOLUTION;
1943
1960
else if (EQUAL (sOptions .osResolution .c_str (), " same" ))
1944
1961
eStrategy = SAME_RESOLUTION;
1962
+ else if (EQUAL (sOptions .osResolution .c_str (), " common" ))
1963
+ eStrategy = COMMON_RESOLUTION;
1945
1964
1946
1965
/* If -srcnodata is specified, use it as the -vrtnodata if the latter is not
1947
1966
*/
@@ -2075,7 +2094,7 @@ GDALBuildVRTOptionsGetParser(GDALBuildVRTOptions *psOptions,
2075
2094
" the default value which is 'location'." ));
2076
2095
2077
2096
argParser->add_argument (" -resolution" )
2078
- .metavar (" user|average|highest|lowest|same" )
2097
+ .metavar (" user|average|common| highest|lowest|same" )
2079
2098
.action (
2080
2099
[psOptions](const std::string &s)
2081
2100
{
@@ -2084,7 +2103,8 @@ GDALBuildVRTOptionsGetParser(GDALBuildVRTOptions *psOptions,
2084
2103
!EQUAL (psOptions->osResolution .c_str (), " average" ) &&
2085
2104
!EQUAL (psOptions->osResolution .c_str (), " highest" ) &&
2086
2105
!EQUAL (psOptions->osResolution .c_str (), " lowest" ) &&
2087
- !EQUAL (psOptions->osResolution .c_str (), " same" ))
2106
+ !EQUAL (psOptions->osResolution .c_str (), " same" ) &&
2107
+ !EQUAL (psOptions->osResolution .c_str (), " common" ))
2088
2108
{
2089
2109
throw std::invalid_argument (
2090
2110
CPLSPrintf (" Illegal resolution value (%s)." ,
0 commit comments