Skip to content

Commit d3ca229

Browse files
authored
Merge pull request #1509 from lesserwhirls/gh-1500
Set centerLon when creating LatLonProjection for GRIB
2 parents a5ead0b + b2b2dd5 commit d3ca229

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

cdm/core/src/main/java/ucar/unidata/geoloc/LatLonPoints.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
2-
* Copyright (c) 1998-2020 John Caron and University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
5+
56
package ucar.unidata.geoloc;
67

78
import java.util.Formatter;
@@ -77,7 +78,7 @@ public static double lonNormalFrom(double lon, double start) {
7778
/**
7879
* Normalize the longitude to lie between +/-180
7980
*
80-
* @param lon east latitude in degrees
81+
* @param lon east longitude in degrees
8182
* @return normalized lon
8283
*/
8384
public static double lonNormal(double lon) {

cdm/core/src/test/java/ucar/unidata/geoloc/TestLatLonProjection.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
/*
2-
* Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
5+
56
package ucar.unidata.geoloc;
67

78
import org.junit.Assert;
9+
import org.junit.Before;
10+
import org.junit.Test;
811
import org.slf4j.Logger;
912
import org.slf4j.LoggerFactory;
1013
import ucar.unidata.geoloc.projection.*;
11-
import junit.framework.*;
1214
import java.lang.invoke.MethodHandles;
1315

1416
/**
1517
*
1618
* @author John Caron
1719
*/
18-
public class TestLatLonProjection extends TestCase {
20+
public class TestLatLonProjection {
1921
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
2022

2123
private LatLonProjection p;
2224

23-
public TestLatLonProjection(String name) {
24-
super(name);
25-
}
26-
25+
@Before
2726
public void setUp() {
2827
p = new LatLonProjection();
2928
}
@@ -66,6 +65,7 @@ void runCenter(double center) {
6665
}
6766
}
6867

68+
@Test
6969
public void testLatLonToProjBB() {
7070
runCenter();
7171
runCenter(110.45454545454547);
@@ -82,6 +82,7 @@ public LatLonRect testIntersection(LatLonRect bbox, LatLonRect bbox2) {
8282
return result;
8383
}
8484

85+
@Test
8586
public void testIntersection() {
8687
LatLonRect bbox = new LatLonRect(LatLonPoint.create(40.0, -100.0), 10.0, 20.0);
8788
LatLonRect bbox2 = new LatLonRect(LatLonPoint.create(-40.0, -180.0), 120.0, 300.0);
@@ -108,6 +109,7 @@ private LatLonRect testExtend(LatLonRect bbox, LatLonRect bbox2) {
108109
return bbox;
109110
}
110111

112+
@Test
111113
public void testExtend() {
112114
LatLonRect bbox;
113115

grib/src/main/java/ucar/nc2/grib/grib1/Grib1Gds.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

@@ -556,6 +556,9 @@ public String toString() {
556556
@Override
557557
public GdsHorizCoordSys makeHorizCoordSys() {
558558
LatLonProjection proj = new LatLonProjection(getEarth());
559+
double centerLon = ((int) ((lo2 - lo1 + deltaLon) / 2 / scale3)) * scale3;
560+
proj.setCenterLon(centerLon);
561+
559562
// ProjectionPoint startP = proj.latLonToProj(LatLonPoint.create(la1, lo1));
560563
double startx = lo1; // startP.getX();
561564
double starty = la1; // startP.getY();

grib/src/main/java/ucar/nc2/grib/grib2/Grib2Gds.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

@@ -518,6 +518,8 @@ public int[] getOptionalPoints() {
518518

519519
public GdsHorizCoordSys makeHorizCoordSys() {
520520
LatLonProjection proj = new LatLonProjection(getEarth());
521+
double centerLon = ((int) ((lo2 - lo1 + deltaLon) / 2 / getScale())) * getScale();
522+
proj.setCenterLon(centerLon);
521523
// ProjectionPoint startP = proj.latLonToProj(LatLonPoint.create(la1, lo1));
522524
double startx = lo1; // startP.getX();
523525
double starty = la1; // startP.getY();

0 commit comments

Comments
 (0)