locationtech / proj4j

Java port of the Proj.4 library for coordinate reprojection
Other
181 stars 71 forks source link

Fix the inverse Krovak transformation (#80) #97

Closed rhuitl closed 1 year ago

rhuitl commented 1 year ago

As @davidklika suggested in #80, the x and y values have to be used instead of the ones in the out parameter.

I also implemented his suggestion to extract the common constants into a method, although the constructor can't be used - the values projectionLatitude and scaleFactor are set only after the constructor has been called.

With this fix, I get the correct result when projecting from EPSG:2065 to EPSG:4326.

pomadchin commented 1 year ago

Hey @rhuitl thanks for a fix! May I ask you to add a manual hand written test at least for the case from https://github.com/locationtech/proj4j/issues/80? (Or any other test that has been incorrect before and fixed by this PR)

rhuitl commented 1 year ago

There you go :smiley:

Before

EPSG:4326(LongLat/WGS84) => EPSG:2065(Krovak/User)
[14.3954134, 50.0596485] -> [-745064.3097223851, -1045825.2153938366, -45.27371696382761] (expected: [-745064.3097223851, -1045825.2153938366] tol: 0.001 diff: 0.0 )

EPSG:2065(Krovak/User) => EPSG:4326(LongLat/WGS84)
[-745064.3097223851, -1045825.2153938366] -> [24.834224452584788, -59.948289081920876, -790.6618332201615] (expected: [14.3954134, 50.0596485] tol: 1.2E-8 diff: 110.00793758192088 )
FAIL
Src CRS: +proj=krovak +lat_0=49.5 +lon_0=42.5 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +pm=ferro +units=m +no_defs 
Tgt CRS: +proj=longlat +datum=WGS84 +no_defs 

EPSG:4326(LongLat/WGS84) => EPSG:5514(Krovak/User)
[14.42, 50.075] -> [-743093.7321490769, -1044381.7725184687, -45.5603481689468] (expected: [-743093.7321490766, -1044381.7725184687] tol: 0.001 diff: 2.3283064365386963E-10 )

EPSG:5514(Krovak/User) => EPSG:4326(LongLat/WGS84)
[-743093.7321490766, -1044381.7725184687] -> [24.82998756399294, -59.94829824087518, -821.9058605181053] (expected: [14.42, 50.075] tol: 8.0E-9 diff: 110.02329824087519 )
FAIL
Src CRS: +proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=589,76,480,0,0,0,0 +units=m +no_defs 
Tgt CRS: +proj=longlat +datum=WGS84 +no_defs 

After

EPSG:4326(LongLat/WGS84) => EPSG:2065(Krovak/User)
[14.3954134, 50.0596485] -> [-745064.3097223851, -1045825.2153938366, -45.27371696382761] (expected: [-745064.3097223851, -1045825.2153938366] tol: 0.001 diff: 0.0 )

EPSG:2065(Krovak/User) => EPSG:4326(LongLat/WGS84)
[-745064.3097223851, -1045825.2153938366] -> [14.395413401193823, 50.05964851105308, 45.273949450813234] (expected: [14.3954134, 50.0596485] tol: 1.2E-8 diff: 1.1053074899791682E-8 )

EPSG:4326(LongLat/WGS84) => EPSG:5514(Krovak/User)
[14.42, 50.075] -> [-743093.7321490769, -1044381.7725184687, -45.5603481689468] (expected: [-743093.7321490766, -1044381.7725184687] tol: 0.001 diff: 2.3283064365386963E-10 )

EPSG:5514(Krovak/User) => EPSG:4326(LongLat/WGS84)
[-743093.7321490766, -1044381.7725184687] -> [14.420000007278146, 50.075000005041574, 45.5603481605649] (expected: [14.42, 50.075] tol: 8.0E-9 diff: 7.278146085809567E-9 )
rhuitl commented 1 year ago

@pomadchin can you already give an indication when a version with this fix will be available on Maven Central?

pomadchin commented 1 year ago

@rhuitl oh, if you need it, I'll try ASAP this week; Hopefully today evening (EST time). I'll leave a mention in the release notes!

rhuitl commented 1 year ago

That would be perfect! I have a copy of that file in my code base which does the job but an official release would simplify the work on my end a bit. Thanks!

pomadchin commented 1 year ago

@rhuitl 1.2.3 is on maven central!

rhuitl commented 1 year ago

Awesome, thank you!