Skip to content

Commit

Permalink
Parsing NTv2 Improvement (#99)
Browse files Browse the repository at this point in the history
* assign grids value to Datum for parsing nadgrid files

* wrap resource stream for nadgrid file in BufferedInput to fix mark/reset not supported exception

Signed-off-by: Elio Alvarado <[email protected]>
  • Loading branch information
ea23del authored May 25, 2023
1 parent 32ceb7b commit 3680d16
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/src/main/java/org/locationtech/proj4j/datum/Datum.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,8 @@ public void shift(ProjCoordinate xy) {
public void inverseShift(ProjCoordinate xy) {
Grid.shift(grids, true, xy);
}

public void setGrids(List<Grid> grids) {
this.grids = grids;
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/locationtech/proj4j/datum/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.Serializable;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -377,7 +378,7 @@ private static DataInputStream resolveGridDefinition(String gridName) throws IOE
File file = new File(gridName);
if (file.exists()) return new DataInputStream(new FileInputStream(file));
InputStream resource = Grid.class.getResourceAsStream("/proj4/nad/" + gridName);
if (resource != null) return new DataInputStream(resource);
if (resource != null) return new DataInputStream(new BufferedInputStream(resource));

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ public double getA() {
public double getES() {
return es;
}

public List<Grid> getGrids() {
return grids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public CoordinateReferenceSystem parse(String name, String[] args) {
parseDatum(params, datumParam);
parseEllipsoid(params, datumParam);
Datum datum = datumParam.getDatum();
datum.setGrids(datumParam.getGrids());
Ellipsoid ellipsoid = datum.getEllipsoid();
// TODO: this makes a difference - why?
// which is better?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,12 @@ public void testEPSG_5514() {
"EPSG:5514", -743093.7321490766, -1044381.7725184687,
0.001, 0.4 * APPROX_METRE_IN_DEGREES);
}

@Test
public void testEPSG_27250() {
checkTransform(
"+proj=latlong +datum=WGS84", 174.7772114, -41.2887953,
"+proj=tmerc +lat_0=-36.87986527777778 +lon_0=174.7643393611111 +k=0.9999 +x_0=300000 +y_0=700000 +datum=nzgd49 +units=m +towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993 +nadgrids=nzgd2kgrid0005.gsb +no_defs", 301062.2010778899, 210376.65974323952,
0.001);
}
}
Binary file not shown.

5 comments on commit 3680d16

@lemontmoon
Copy link

Choose a reason for hiding this comment

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

Hi, i am trying to transform coordinates from ETRS89 to S-JSTK coordinate system for Slovakia,,

could you please explain how to use grid files for transformation ? Where they should be located in project ? It would be great to provide some example code. We need to transform this ...
J +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-485.014055 +y=-169.473618 +z=-483.842943 +rx=7.78625453 +ry=4.39770887 +rz=4.10248899 +s=0 +convention=coordinate_frame +step +inv +proj=cart +ellps=bessel +step +proj=pop +v_3 +step +proj=hgridshift +grids=sk_gku_JTSK03_to_JTSK.tif +step +proj=krovak +lat_0=49.5 +lon_0=24.8333333333333 +alpha=30.2881397527778 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel TSK

@lemontmoon
Copy link

Choose a reason for hiding this comment

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

More detailed, it is transformation from ETRS89-LatLon [EPSG:4258] to S-JSTK(JSTK) [EPSG:5513]

@pomadchin
Copy link
Member

@pomadchin pomadchin commented on 3680d16 May 26, 2023

Choose a reason for hiding this comment

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

@lemontmoon it should live in the resources/proj4/nad/ of the project. However, proj4j is limited in the grid formats support, at this point its only ctable2, ntv1, ntv2.

@lemontmoon
Copy link

@lemontmoon lemontmoon commented on 3680d16 May 26, 2023 via email

Choose a reason for hiding this comment

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

@lemontmoon
Copy link

@lemontmoon lemontmoon commented on 3680d16 May 26, 2023 via email

Choose a reason for hiding this comment

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

Please sign in to comment.