Skip to content

Commit 6610925

Browse files
authored
Merge pull request #3993 from mapfish/ghci/backport/3979-to-3.32
[Backport 3.32] Correct geodetic scale denominator calculation
2 parents 93dd745 + 3f02951 commit 6610925

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

core/src/main/java/org/mapfish/print/map/Scale.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public double getGeodeticDenominator(
201201
double width = 1;
202202
double geoWidthInches = getResolutionInInches() * width;
203203
double geoWidth = DistanceUnit.IN.convertTo(geoWidthInches, this.unit);
204-
double minGeoX = position.y - (geoWidth / 2.0);
204+
double minGeoX = position.x - (geoWidth / 2.0);
205205
double maxGeoX = minGeoX + geoWidth;
206206

207207
final GeodeticCalculator calculator = new GeodeticCalculator(projection);

core/src/test/java/org/mapfish/print/map/ScaleTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
public class ScaleTest {
1313
public static final CoordinateReferenceSystem SPHERICAL_MERCATOR;
1414
public static final CoordinateReferenceSystem CH1903;
15+
public static final CoordinateReferenceSystem CH2056;
1516
private static final double DELTA = 0.00001;
1617
private static final double SCALE = 108335.72891406555;
1718
private static final double RESOLUTION = 38.21843770023979;
@@ -20,6 +21,7 @@ public class ScaleTest {
2021
try {
2122
SPHERICAL_MERCATOR = CRS.decode("EPSG:3857");
2223
CH1903 = CRS.decode("EPSG:21781");
24+
CH2056 = CRS.decode("EPSG:2056");
2325
} catch (FactoryException e) {
2426
throw new RuntimeException(e);
2527
}
@@ -47,4 +49,29 @@ public void geodetic() {
4749
10019.0,
4850
1.0);
4951
}
52+
53+
/**
54+
* This test verifies that the geodetic scale calculation correctly uses position.x for the
55+
* horizontal coordinate. In projections like CH2056 (Swiss Oblique Mercator) or UTM, shifting a
56+
* point in X direction while keeping Y constant affects the geodetic distance, unlike EPSG:3857
57+
* where distortion is primarily latitude-dependent.
58+
*
59+
* <p>With some other projection like EPSG:5936 WGS 84 / EPSG Alaska Polar Stereographic The
60+
* defferance will consequant.
61+
*/
62+
@Test
63+
public void geodeticCH2056XPositionDependence() {
64+
final Scale scale = new Scale(25000.0, CH2056, PDF_DPI);
65+
66+
// Calculate geodetic scale at two positions with same Y but different X
67+
// Using coordinates in CH2056 CRS (EPSG:2056)
68+
final Coordinate positionRef = new Coordinate(2600000.0, 1200000.0);
69+
final Coordinate positionLeft = new Coordinate(2484274.0, 1200000.0);
70+
71+
final double geodeticScaleRef = scale.getGeodeticDenominator(CH2056, PDF_DPI, positionRef);
72+
final double geodeticScaleLeft = scale.getGeodeticDenominator(CH2056, PDF_DPI, positionLeft);
73+
74+
assertEquals(24996.77190700038, geodeticScaleRef, 0.0);
75+
assertEquals(24996.76743516703, geodeticScaleLeft, 0.0);
76+
}
5077
}

0 commit comments

Comments
 (0)