georust / proj

Rust bindings for the latest stable release of PROJ
https://docs.rs/proj
Apache License 2.0
137 stars 43 forks source link

Inconsistent transformations of coords between OSX and ubuntu #162

Closed gmmorris closed 1 year ago

gmmorris commented 1 year ago

I'm transforming geometries received in EPSG::27700 to OGC:1.3:CRS84.

I'm encountering some inconsistencies between my local environment (OSX) and my CI (ubuntu-latest on Github Actions).

Given this geometry:

{ "type": "Point", "coordinates": [492941.3929127551,144592.2391630347] }

Locally on OSX and transform these coords are transformed into:

{ "type": "Point", "coordinates": [-0.6713249654966993, 51.19300053717864] }

But then on CI they are transformed into:

{ "type": "Point", "coordinates": [-0.6713438264761399, 51.193003894930584] }

Any thoughts on why this inconsistency might be happening and how I can avoid it?

I'm happy to compromise on resolution (cm would be ideal, but meter could work if that helps), but mostly I want to understand if this is a rounding or configuration issue.

Cheers

urschrei commented 1 year ago

I suspect it's a rounding issue or something related to the installed libproj versions if you aren't using the bundled proj option, since database updates can affect transforms. Is the inconsistency still present if you build with the bundled-proj feature?

gmmorris commented 1 year ago

Thanks for the quick response. I got a quick reply from Proj too - https://github.com/OSGeo/PROJ/issues/3773

Seems it's about having the network off. Would using the bundles proj work by including these resources? Or should I switch network on (about to try that on CI... I'll update here on whether it work 😅 )

urschrei commented 1 year ago

I'd try the network feature first!

gmmorris commented 1 year ago

Waiting on CI :) I'll confirm if it sorts it out for posterity's sake

gmmorris commented 1 year ago

Sadly, this doesn't seem to solved the issue, but I tried toggling the enable_network to both the on and off states locally. In both cases, I got the same transformed coordinates - which I wouldn't have expected to happen. I also set grid_cache_enable(false) to make sure it wasn't just the cache playing tricks on me.

Is there a way for me to check if the network is being used or not?

urschrei commented 1 year ago

Ah. The transform won't automatically use the network if you've only activated the feature — as you say, you have to use the enable_network method on ProjBuilder to use it (if it's available for a given transform). You can check whether it's enabled by using https://docs.rs/proj/0.27.0/proj/struct.ProjBuilder.html#method.network_enabled to check.

If you don't use enable_network, the network will never be used. Activating the feature only allows you to call that method, it won't do anything on its own.

gmmorris commented 1 year ago

No sure I follow. If I have done the following:

  1. enabled the feature flag
  2. called enable_network(true) and it returned OK

You'd expect it to use the network, right? Does calling netwrok_enabled() just verify that it's switched on? Is there a way to actually check whether a transformation was made using the resource or not? 🤔

gmmorris commented 1 year ago

Ah, it's an issue with my CI server - it fails with: Network error when accessing a remote resource. I'll update if sorting out the connectivity fixes it 👍

gmmorris commented 1 year ago

Sorting out the network issues solved the issue.

For posterity, make sure:

  1. your CI job can reach https://cdn.proj.org/
  2. You have the env variable set PROJ_NETWORK=ON
  3. You call the enable_network(true) API on the Proj instance

Simples ;)