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

Project suggested by Claude.ai in a response but resulted in ~ 150m offset due to incomplete solution #126

Open
ramonsmits opened this issue Jan 11, 2025 · 4 comments

Comments

@ramonsmits
Copy link

Never heard of this project but https://claude.ai/ used it in a response.

I have a data set of EPSG:28992 points. The reponse used ProjNet to convert these to WGS 84. It boils down to the following code:

var rdNew = csFactory.CreateFromWkt(
    "PROJCS[\"Amersfoort / RD New\",GEOGCS[\"Amersfoort\",DATUM[\"Amersfoort\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6289\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4289\"]],PROJECTION[\"Oblique_Stereographic\"],PARAMETER[\"latitude_of_origin\",52.15616055555555],PARAMETER[\"central_meridian\",5.38763888888889],PARAMETER[\"scale_factor\",0.9999079],PARAMETER[\"false_easting\",155000],PARAMETER[\"false_northing\",463000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"28992\"]]");

var wgs84 = csFactory.CreateFromWkt(
    "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");

var ctFactory = new CoordinateTransformationFactory();
_rdNewToWgs84 = ctFactory.CreateFromCoordinateSystems(rdNew, wgs84);

I don't know what is wrong with it but it cause the lat/lng coordinates to be roughly 150 meters offset.

Interestingly the solution assumed Postgis and manually modifying it to use ST_Transform(geom, 4326) resulted in correct lat/lng coordinates.

I asked it to reflect on what could be causing the offset and Claude.ai replied with:

PostGIS handles this correctly because it includes the proper transformation grid file (nl_nsgi_rdcorr2018.gsb) and datum shift parameters, while our ProjNet implementation was doing a simpler, less accurate transformation.

It provided a fix (modify the CoordinateTransformer to include these parameters) but stated:

However, even with these parameters, you might still see small differences compared to PostGIS because PostGIS uses a more sophisticated grid-based transformation that accounts for local variations in the datum shift across the Netherlands.

Sharing this here because this wasted several hours of diagnosing an incorrect AI response and I assumed that conversion to be correct because it was a package.

@ff-vin
Copy link

ff-vin commented Mar 3, 2025

@ramonsmits

You were using a wrong WKT definition. You should be using:

var rdNew = csFactory.CreateFromWkt(
	"PROJCS[\"Amersfoort / RD New\",GEOGCS[\"Amersfoort\",DATUM[\"Amersfoort\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],TOWGS84[565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812],AUTHORITY[\"EPSG\",\"6289\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4289\"]],PROJECTION[\"Oblique_Stereographic\"],PARAMETER[\"latitude_of_origin\",52.15616055555555],PARAMETER[\"central_meridian\",5.38763888888889],PARAMETER[\"scale_factor\",0.9999079],PARAMETER[\"false_easting\",155000],PARAMETER[\"false_northing\",463000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],AUTHORITY[\"EPSG\",\"28992\"]]");

Refer to the definitions inside the test project: https://github.com/NetTopologySuite/ProjNet4GeoAPI/blob/develop/test/ProjNet.Tests/SRID.csv (both definitions are in the list (4289 and 28992)

I waisted some time with this issue as well. Putting this information here to help out the next sucker :)

@ramonsmits
Copy link
Author

@ff-vin great find! Still I see Amersfoort listed several times. Don't know how you would know which line to use.

@ff-vin
Copy link

ff-vin commented Mar 4, 2025

@ramonsmits

Indeed, there are multiple versions of the Amersfoort projection. Oorspronkelijk lag het nulpunt van het Rijksdriehoekstelsel in Amersfoort, maar dit is in 1968 verplaatst naar een punt ten zuidoosten van Parijs. (i assume you speak dutch, as you are using this projection)

@ramonsmits
Copy link
Author

ramonsmits commented Mar 4, 2025

@ramonsmits

Indeed, there are multiple versions of the Amersfoort projection. Oorspronkelijk lag het nulpunt van het Rijksdriehoekstelsel in Amersfoort, maar dit is in 1968 verplaatst naar een punt ten zuidoosten van Parijs. (i assume you speak dutch, as you are using this projection)

I do, thanks for that link. Now the data makes more sense!

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