iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
606 stars 210 forks source link

Issue converting latitude and longitude to spatial coordinates #4901

Closed DRHoltman closed 1 year ago

DRHoltman commented 1 year ago

I'm creating a "Locate Me" function and I have the lat/longs but I'm seeing inconsistent results when converting them to spatial coordinates.

For testing I'm using the lat/longs for the Bentley's Austin Texas office for all tests: Lat: 30.36936664900865 Long: -97.74329476841908

I can only get it to work in the following sandbox: https://www.itwinjs.org/sandbox/DerekHoltman/Derek%20Testing Using cartographicToSpatialFromEcef and the Metrostation model I get the correct results: 1134495.7502543565, -1951322.9502983307 Using cartographicToSpatialFromGcs and the Metrostation model I get the wrong results: 1198251.9361718288, -2025549.2996983863
This is north of San Antonio and affects the current sessions orientation of the model which is seen when selecting Top of the cube. Note: I do not know how to check the itwin version in the sandbox.

I also have the following test app that has the same code: https://dev.azure.com/bentleycs/AssetWise%20-%20Energy%20Infrastructure/_git/powerbi-report-grouping?version=GBUpgraded-grouping-mapping-widget-to-0.8.2-package-lock It is using itwin 3.2.8 but I have seen the following results with itwin 3.5.1 in another app. Using cartographicToSpatialFromEcef and the QA-RockyMountCircuits-LatestChangeset model I get the wrong results: -1155569.9807568148, -202005.6185020086 South Carolina Using cartographicToSpatialFromGcs and the QA-RockyMountCircuits-LatestChangeset model I get the wrong results: -1187585.3929570804, -205278.5211527112 Pacific Ocean

To start test app: npm install npm start

To test in both sandbox and test app: A decorator tab has been added to the right side panel. select decorate to run the code above and watch debug output for coordinates. There is a useEcef constant that is used to control which code it hits.

Note: the imodels are geolocated. Does this have something to do with the imodels? my environment? or something else?

markschlosseratbentley commented 1 year ago

@mdastous-bentley do you have any suggestions?

mdastous-bentley commented 1 year ago

Couple of points:

DRHoltman commented 1 year ago

Using hard coded NC Englewood Recreation Park location: Lat: 35.954177 Long: -77.829353 Which is in the same area as the data. cartographicToSpatialFromEcef and cartographicToSpatialFromGcs both return the correct location: 715204.1659459114, 245139.30506102668

I also tried using cartographicToSpatialFromGcs going to the Austin Office on the following model that was generated from the MicroStation Connector: http://localhost:3000/?iTwinId=cb6b9001-96ff-4af8-aa4d-8571973a6e45&iModelId=cb64c9a2-8296-4aef-bcd3-787912e91aa1 It is using the same area and GCS. It also returned the coordinates in the Pacific: -1187585.3929570804, -205278.5211527112

mdastous-bentley commented 1 year ago

IModelConnection.cartographicToSpatialFromGcs is mostly a wrapper on top of getIModelCoordinatesFromGeoCoordinates RPC.

@pmconne Who maintains this API?

pmconne commented 1 year ago

@mdastous-bentley it has no dedicated maintainer.

DRHoltman commented 1 year ago

Any idea on when this will be worked?

markschlosseratbentley commented 1 year ago

@DRHoltman Not 100% sure on the timing -- but we are now internally aware of the issue you are seeing and are asking around. We'll update this item with findings.

mdastous-bentley commented 1 year ago

Hey Derek,

Myself and @AlainRobertAtBentley looked into this.

First thing: Your iModel's GCS is set to EPSG:3404, which domain of validity look like this: image

You cannot expect a point located in Texas to be accurate with this GCS. In my tests, the point was located near Austin, but not exactly where it should be. You might consider setting your iModel's GCS to something like EPSG:5070 which cover the United States: image

Another point, I noticed some display issues with decorations when the Globe mode of your view was set to 'Ellipsoid' you might consider using 'Plane' for now by using something like this: activeViewport?.view.displayStyle.changeBackgroundMapProps({globeMode: GlobeMode.Plane});

DRHoltman commented 1 year ago

Thanks guys for looking into this... I'm not sure if we can require our users to use this GCS so we are going to add a check to see if the lat/long is within the GCS extents (converted to lat/longs) and error out only if outside the area. I guess what is still confusing, is why this worked in v2. Here is a link to V2 working on the same area: https://openutilities-dts.qa.aw-au.bentley.com/852f17d6-5a8b-423b-9ee9-d2cb17722de4/viewer/https%3A%2F%2Fopenutilities.qa.aw-au.bentley.com%2F%3Fproject%3D852f17d6-5a8b-423b-9ee9-d2cb17722de4%26isEmbedded%3Dtrue%26resultId%3D425ba9f6-7b81-40d7-99ec-cc0182e0cee5 Locate Me is in the upper right corner by the navigation cube...

mdastous-bentley commented 1 year ago

Do you know which method you were using to translate your lat,long coords? I cannot see any request to the backend.

DRHoltman commented 1 year ago

I just ran it. 8:10AM Central time. It should be using cartographicToSpatialFromEcef.

DRHoltman commented 1 year ago

While investigating another issue I found a way to zoom to a lat/long without converting to spatial coordinates: new ViewGlobeLocationTool(vp).parseAndRun(${latitude}, ${longitude}); So regardless of the GCS of the iModel, this will still work.

mdastous-bentley commented 1 year ago

That's interesting, this tool uses Bing services... and calls ViewState3d.lookAtGlobalLocationFromGcs to adjust the view, would be interesting to see if call directly this method would work too.

markschlosseratbentley commented 1 year ago

Can this item be closed?

DRHoltman commented 1 year ago

Yes as I found a work around.