Help Understanding Spatial References

184
3
06-21-2021 10:13 AM
johnmarker
New Contributor III

Hello,

I have followed the tutorials that first display a map and then the second to display a point, polyline and polygraph. When they create a point they use the spatial reference of  SpatialReferences.Wgs84. I read that the maps have a default of webMercator. So if I change the spatial references to webMercator, then every time I run the program my startup view point go to just off the coats of Africa. I have tried changing those starting coordinates and no matter what i use the starting center viewpoint never changes.  I know why i would get a different location using a different spatial reference, but i don't understand why the location does not change at all when the coordinates change.

 

 

0 Kudos
3 Replies
Nicholas-Furness
Esri Regular Contributor

If you use WGS84 coordinates with a Web Mercator spatial reference, the point will not move very much and will be close to 0,0 lat/lon (which is off the coast of Africa). Web Mercator units are meters, and WGS84 coordinates are in the range of +/-90º Latitude and +/-180º Longitude. So if you're using x values between -180 and +180 and y values between -90 and +90 (which will be considered as meters from 0,0 when using Web Mercator as the spatial reference), then you can imagine the point will barely move unless you are zoomed in a long way, and will never move far from 0,0.

Fortunately, Runtime will look at the spatial reference property of a geometry as well as the x and y property and project it appropriately for the map's spatial reference (which in most cases is the spatial reference of the basemap, typically Web Mercator).

So, unless you are doing a lot of intensive geometry processing, you can probably just continue to use a WGS84 point.

If you need to project the geometry, you can save Runtime from doing this on the fly by using GeometryEngine to project geometries to other spatial references (in your case, the spatial reference of the map, almost certainly Web Mercator). In fact, there is a screenshot at that link that shows how 45º,-94º lat/lon is about -10503190m, 5653794m x/y.

Hope that makes sense and helps.

johnmarker
New Contributor III

@Nicholas-FurnessThat makes a lot of sense thanks! 

So when I use the built in screenToLocation method it returns a MapPoint value that has X/Y attributes in the form of meters not lat/long with ranges of +-90 and =-180 (Assuming because my basemap is webMercator or because that is always the return value type).  Is there a way to convert this to a lat/long form?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Indeed, and yes 🙂

screenToLocation will return a geometry in the map's spatial reference. I saw that @NathanCastle1 pointed you in the direction of GeometryEngine.Project() to turn that into a WGS84 point that will contain longitude and latitude in its x and y properties.

If you simply want to display the coordinates as Lat/Lon then, as @NathanCastle1 pointed out, CoordinateFormatter should work.

Hope that helps!

0 Kudos