Select to view content in your preferred language

Placing/Drawing objects in world scale AR from local coordinates

744
6
03-17-2022 05:53 PM
AndrewMcLane
Emerging Contributor

Hi! 

I am using iOS to build an AR map with coordinates from an external API. I am using a AGSGraphicsOverlay with AGSPolygonBuilder and AGSGraphic. I add the graphic objects to the main overlay. Nothing renders though. Any advice? Thanks!

0 Kudos
6 Replies
MarkDostal
Esri Regular Contributor

Hello and thank you for your question!  Are the object coordinates in the same spatial reference as the base map?  Also, are you using an elevation source in your scene and do the coordinates have a `z` (elevation) component?  Those are two common problems when displaying external data.

Are you able to display the base map data OK?  If you're using an elevation source, does the device show you are in the correct vertical position (meaning you're not showing up under the surface of the base data)?

Esri has an open-source Toolkit for use with the iOS Runtime SDK.  The Toolkit has an AR component you can look at for reference.  From the Toolkit doc:

The AR toolkit component is comprised of one class: `ArcGISARView`. This is a subclass of `UIView` that contains the functionality needed to display an AR experience in your application. It uses `ARKit`, Apple's augmented reality framework to display the live camera feed and handle real world tracking and synchronization with the Runtime SDK's `AGSSceneView`. The `ArcGISARView` is responsible for starting and managing an `ARKit` session. It uses a user-provided `AGSLocationDataSource` for getting an initial GPS location and when continuous GPS tracking is required.

One final note: unless you're using an external, high-accuracy GPS, the device (iPhone/iPad) location/elevation can sometimes only be accurate to 40 meters, so your object and device location may not be where you think.  In this case, a calibration step (which is also demonstrated in the Toolkit) may be warranted.

Please let us know if you have more questions!

Mark

 

AndrewMcLane
Emerging Contributor

Hi Mark, Thank you for your quick and detailed reply! 

How could I determine if the coordinates are in the same spacial reference? The coordinates look like this 

ex "long = -122.271870555087". Or does spacial reference refer to the spacial reference like on AGSPolygonBuilder(spacialReference: .wgs84())? I've searched the script and found no other location where spacial reference was set, but I do remember it happening some other place. Perhaps the other spacial reference reference has something to do with the camera? Or does everything that is an AGSPoint have a spacial reference?

 I am familiar with the calibration experience from the ARExample.cs. Are you saying that I need to calibrate the objects separately from calibrating the map even though I'm using the map to anchor the objects? 

I guess that I am basing my efforts on ExtrudeGraphicsViewController.swift but I want the extruded objects to be in world scale AR.

I get a bit confused about the graphics overlays and if I have more than one, do I need to do anything to align them, or if I only have one, can I use it for the map and also have object renderings on it?

 

Thanks so much! 

0 Kudos
MarkDostal
Esri Regular Contributor

If you are using one of the Esri basemaps, the spatial reference should be `.wgs84`, and the coordinate you sent should be fine as-is.  Is there a vertical/altitude component in the data for each point?  Those should be in meters if you are creating points for the polygon (the "z" value below):

let point = AGSPoint(x: -116.5521466667, y: 33.824821666, z: 300.32, spatialReference: .wgs84())

I'm assuming you're creating AGSPoint s to add to the polygon; you should include a spatial reference for those (like above).  So it's just the polygon and points that need the SR specified.

As for calibration, you only need to calibrate the map/scene.  You are correct, the objects are anchored in the map/scene, sorry for the confusion.

For GraphicsOverlays, you don't need to do anything other than create one (or more) of them and add graphics to them.  Because the graphics have a geometry, they know where to be drawn.  You can add any graphics you want to an overlay, so you really only need one, unless you want to organize different graphics in different overlays to make them easy to manage; up to you.

If you want, you can send me some representative data (and which basemap you're using) and I can try placing it in an overlay here.  Are you using an elevation source in the scene?

Thanks,

Mark

MarkDostal
Esri Regular Contributor

I misspoke in my earlier reply.  The spatial reference of the Esri basemaps is `.webMercator`, not `.wgs84`.  Sorry if there was any confusion.

0 Kudos
AndrewMcLane
Emerging Contributor

Oh, really? It seems to be working with .wgs84. So the coordinates I am using will also work with .webMercator? 

0 Kudos
MarkDostal
Esri Regular Contributor

The Runtime will project points in a different SR than the scene to the correct SR.  If it's working with what you have, then all is good.  The important thing is to always specify a SpatialReference when creating geometries.

0 Kudos