Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CRS give the wrong result on Proj4Dart. #10

Closed
pbrobo opened this issue Jul 4, 2022 · 1 comment
Closed

Custom CRS give the wrong result on Proj4Dart. #10

pbrobo opened this issue Jul 4, 2022 · 1 comment

Comments

@pbrobo
Copy link

pbrobo commented Jul 4, 2022

Now I am using Proj4Dart V2.0.0 & Flutter 3.0.4, found some big different of transform coordinates from my custom CRS. This is my code:

`import 'package:proj4dart/proj4dart.dart';

void main() {
var n1 = 1657193.5292;
var e1 = 834934.4417;
var ptSrc = Point(x: e1, y: n1);
var projSrc =
Projection.parse('+proj=utm +zone=47 +datum=WGS84 +units=m +no_defs');
var projDst = Projection.parse(
'+proj=tmerc +lat_0=0.0 +lon_0=102.25 +k_0=1.0 +x_0=500000 +y_0=0 +a=6378297.0 +b=6356911.77779 +towgs84=0.0,0.0,0.0,0,0,0,0 +units=m +no_defs type=crs');
var tuple = ProjectionTuple(fromProj: projSrc, toProj: projDst);
var ptDst = tuple.forward(ptSrc);
print(
'FORWARD: Transform point ${ptSrc.toArray()} from EPSG:32647 to custom projection: ${ptDst.toArray()}');
}
`
The console printed:
FORWARD: Transform point [834934.4417, 1657193.5292] from EPSG:32647 to custom projection: [485333.96880976285, 1655549.4642448912]

The correct answer must be [485333.9690, 1655549.7316].
This is very strange due to I used pyproj version of Python that derived from PROJ4 also but gave the correct coordinates.
This is my Python code with the same Proj4 strings:
`from pyproj import CRS, Transformer

projsrc = CRS.from_proj4('+proj=utm +zone=47 +datum=WGS84 +units=m +no_defs')
projdst = CRS.from_proj4('+proj=tmerc +lat_0=0.0 +lon_0=102.25 +k_0=1.0 +x_0=500000 +y_0=0 +a=6378297.0 +b=6356911.77779 +towgs84=0.0,0.0,0.0,0,0,0,0 +units=m +no_defs type=crs');
xx, yy = 834934.4417, 1657193.5292
transformer = Transformer.from_crs(projsrc, projdst)
ptdst = transformer.transform(xx=xx, yy=yy)
print(f'Source point x,y: {xx} {yy}')
print(f'Dest point x,y: {ptdst[0]} {ptdst[1]}')`

The console of Python printed:
Source point x,y: 834934.4417 1657193.5292
Dest point x,y: 485333.9689740725 1655549.7315796772

I am new to Dart/Flutter what I am doing wrong or is it Proj4Dart's bug? Please help me. I run this code on Windows 11.

@maRci002
Copy link
Owner

maRci002 commented Jul 4, 2022

I'm sorry to inform you but this is the correct result since this project is based on proj4js which results the same.

var script = document.createElement("script");
var scriptPath = "https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.8.0/proj4.js";
script.setAttribute("src", scriptPath);
document.head.appendChild(script);

script.onload = function() {
    proj4.defs('projSrc', '+proj=utm +zone=47 +datum=WGS84 +units=m +no_defs');
    proj4.defs('projDst', '+proj=tmerc +lat_0=0.0 +lon_0=102.25 +k_0=1.0 +x_0=500000 +y_0=0 +a=6378297.0 +b=6356911.77779 +towgs84=0.0,0.0,0.0,0,0,0,0 +units=m +no_defs type=crs');
    var result = proj4('projSrc', 'projDst').forward([834934.4417, 1657193.5292]);
    console.log(result);
}

output: [485333.96880976285, 1655549.4642448917]

You can run the above script in your browser's console (note: you cannot run on every site since this is script injection and some sites like github prevents it, so go for example to http://proj4js.org/ and press F12 and paste / run the above code snippet)

Anyway Python might use slightly different projection algorithm or Python might use higher/lower precision while calculating, the results almost the same I think the difference is still lower than 5mm which is insignificant if you think about it, it's a much bigger problem that the continents move from year to year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants