Select to view content in your preferred language

How to convert high precision location values to coordinates?

920
4
05-09-2023 07:43 AM
navintc
New Contributor

I'm using the SampleArcGisRayCast component and I'm trying to get the coordinates (lats and longs) of the specific building that's clicked on. I managed to get their high-precision location values of them but, I don't understand how to convert them to lats and longs. Any suggestions on how to update the code in the sample to achieve this?

0 Kudos
4 Replies
Jade
by Esri Contributor
Esri Contributor

updated:

var geoPosition = arcGISMapComponent.EngineToGeographic(hit.point);
0 Kudos
navintc
New Contributor

This code kind of boosted how I understood arcGis SDK. But I have a follow-up question @Jade. I used your suggestion in the sampleArcGisRayCast component to get the coordinates of buildings. It seems the code line doesn't support both hit.point and location.Position. Any suggestion to get it working?

 

if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0))
		{
			RaycastHit hit;
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

			if (Physics.Raycast(ray, out hit))
			{
				var arcGISRaycastHit = arcGISMapComponent.GetArcGISRaycastHit(hit);
				var layer = arcGISRaycastHit.layer;
				var featureId = arcGISRaycastHit.featureId;
				
				DumpToConsole(arcGISRaycastHit.layer);
				DumpToConsole(arcGISRaycastHit);

				if (layer != null && featureId != -1)
				{
					var geoPosition = arcGISMapComponent.EngineToGeographic(hit.point);
					
					var offsetPosition = new ArcGISPoint(geoPosition.X, geoPosition.Y, geoPosition.Z + 200, geoPosition.SpatialReference);
					var rotation = arcGISCamera.GetComponent<ArcGISLocationComponent>().Rotation;
					var location = canvas.GetComponent<ArcGISLocationComponent>();
					location.Position = offsetPosition;
					location.Rotation = rotation;

// Your code snip
					ArcGISPoint latLong = arcGISMapComponent.View.WorldToGeographic(hit.point);
				}
				else
				{
					popUp.SetActive(false);
				}
            }
            

		}

 

 

0 Kudos
Jade
by Esri Contributor
Esri Contributor

hi! So with your line of code 

var geoPosition = arcGISMapComponent.EngineToGeographic(hit.point);

you should be able to get lat long (if you're in global mode, if you're in local mode, you get large x,y,z value which is on the projected coordinate system). 

var worldPosition = math.inverse(arcGISMapComponent.WorldMatrix).HomogeneousTransformPoint(hit.point.ToDouble3());
ArcGISPoint latLong = arcGISMapComponent.View.WorldToGeographic(worldPosition)

is another way of getting lat long, but you need to use double3 which is why hit.point doesn't work. 

 

0 Kudos
Deivydas24
Emerging Contributor

If I'm using a local mode. Is there a way to convert a large x,y,z values to normal lat and long?

0 Kudos