Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ public class InvalidValueException extends Proj4jException {
public InvalidValueException(String message) {
super(message);
}

public InvalidValueException(String message, Exception cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public Proj4jException() {
public Proj4jException(String message) {
super(message);
}

public Proj4jException(String message, Exception cause) {
super(message, cause);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/locationtech/proj4j/datum/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private static DataInputStream resolveGridDefinition(String gridName) throws IOE
// search path for grid definition files, but for now we only check the
// working directory and the classpath (in that order.)
File file = new File(gridName);
if (file.exists()) return new DataInputStream(new FileInputStream(file));
if (file.exists()) return new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the culrprit, apparently only definitions stored in the resources folder were properly loading.

InputStream resource = Grid.class.getResourceAsStream("/proj4/nad/" + gridName);
if (resource != null) return new DataInputStream(new BufferedInputStream(resource));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void parseDatum(Map params, DatumParameters datumParam) {
try {
datumParam.setGrids(Grid.fromNadGrids(nadgrids));
} catch (IOException e) {
throw new InvalidValueException("Unknown nadgrid: " + nadgrids);
throw new InvalidValueException("Unknown nadgrid: " + nadgrids, e);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/org/locationtech/proj4j/datum/NTV2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.locationtech.proj4j.CoordinateTransformFactory;
import org.locationtech.proj4j.ProjCoordinate;

import java.net.URISyntaxException;

/**
* Using grid shifts for Catalonia
* @see https://geoinquiets.cat/
Expand Down Expand Up @@ -77,4 +79,18 @@ public void gridShiftNTV2Inverse() {
Assert.assertTrue(expected2.areXOrdinatesEqual(result2, 0.001) &&
expected2.areYOrdinatesEqual(result2, 0.001));
}

@Test
public void nadGridExternalTest() throws URISyntaxException {
String path = this.getClass().getResource("/proj4/nad/100800401.gsb").toURI().getPath();
CRSFactory crsFactory = new CRSFactory();

CoordinateReferenceSystem tmercWithNadGridV2 =
crsFactory.createFromParameters("EPSG:2100",
"+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="
+ path + " +no_defs"
);

Assert.assertEquals(Datum.TYPE_GRIDSHIFT, tmercWithNadGridV2.getDatum().getTransformType());
}
}