Skip to content

Commit 2991352

Browse files
committed
External GridDefinition read fix
1 parent c856914 commit 2991352

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

core/src/main/java/org/locationtech/proj4j/InvalidValueException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ public class InvalidValueException extends Proj4jException {
2828
public InvalidValueException(String message) {
2929
super(message);
3030
}
31+
32+
public InvalidValueException(String message, Exception cause) {
33+
super(message, cause);
34+
}
3135
}

core/src/main/java/org/locationtech/proj4j/Proj4jException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public Proj4jException() {
3434
public Proj4jException(String message) {
3535
super(message);
3636
}
37+
38+
public Proj4jException(String message, Exception cause) {
39+
super(message, cause);
40+
}
3741
}

core/src/main/java/org/locationtech/proj4j/datum/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ private static DataInputStream resolveGridDefinition(String gridName) throws IOE
376376
// search path for grid definition files, but for now we only check the
377377
// working directory and the classpath (in that order.)
378378
File file = new File(gridName);
379-
if (file.exists()) return new DataInputStream(new FileInputStream(file));
379+
if (file.exists()) return new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
380380
InputStream resource = Grid.class.getResourceAsStream("/proj4/nad/" + gridName);
381381
if (resource != null) return new DataInputStream(new BufferedInputStream(resource));
382382

core/src/main/java/org/locationtech/proj4j/parser/Proj4Parser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void parseDatum(Map params, DatumParameters datumParam) {
205205
try {
206206
datumParam.setGrids(Grid.fromNadGrids(nadgrids));
207207
} catch (IOException e) {
208-
throw new InvalidValueException("Unknown nadgrid: " + nadgrids);
208+
throw new InvalidValueException("Unknown nadgrid: " + nadgrids, e);
209209
}
210210
}
211211
}

core/src/test/java/org/locationtech/proj4j/datum/NTV2Test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.locationtech.proj4j.CoordinateTransformFactory;
2525
import org.locationtech.proj4j.ProjCoordinate;
2626

27+
import java.net.URISyntaxException;
28+
2729
/**
2830
* Using grid shifts for Catalonia
2931
* @see https://geoinquiets.cat/
@@ -77,4 +79,18 @@ public void gridShiftNTV2Inverse() {
7779
Assert.assertTrue(expected2.areXOrdinatesEqual(result2, 0.001) &&
7880
expected2.areYOrdinatesEqual(result2, 0.001));
7981
}
82+
83+
@Test
84+
public void nadGridExternalTest() throws URISyntaxException {
85+
String path = this.getClass().getResource("/proj4/nad/100800401.gsb").toURI().getPath();
86+
CRSFactory crsFactory = new CRSFactory();
87+
88+
CoordinateReferenceSystem tmercWithNadGridV2 =
89+
crsFactory.createFromParameters("EPSG:2100",
90+
"+proj=tmerc +lat_0=0 +lon_0=24 +k=0.9996 +x_0=500000 +y_0=0 +ellps=GRS80 +towgs84=-199.87,74.79,246.62,0,0,0,0 +units=m +nadgrids="
91+
+ path + " +no_defs"
92+
);
93+
94+
Assert.assertEquals(Datum.TYPE_GRIDSHIFT, tmercWithNadGridV2.getDatum().getTransformType());
95+
}
8096
}

0 commit comments

Comments
 (0)