Select to view content in your preferred language

How to convert polygon vertex to lat/lon

1179
3
10-13-2022 02:04 PM
GeraldRowe
New Contributor

I am aware how to iterate through the graphic.geometry.rings to get each x/y coordinate. However, this yields massive numbers that are obviously not lat/lon values. I have found quite a few examples of people asking the same or very similar questions, but none seem to yield an actual lat/lon result. I only get something like the below for each vertex:

 

Array [ -12390508.031742427, 3819480.562610634 ]

 

0 Kudos
3 Replies
ReneRubalcava
Esri Frequent Contributor

Assume those are WebMercator, so you can run the polygon through the webmercatorUtils first.

https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-webMercatorUtils...

0 Kudos
GeraldRowe
New Contributor

Thanks a million for this!

I spent an entire trying to figure out how to get these converted.

var geo = webMercatorUtils.xyToLngLat(graphic.geometry.rings[i][p][0], graphic.geometry.rings[i][p][1]);

console.log("Lon: "+ geo[0] +", Lat: "+ geo[1]);

0 Kudos
ReneRubalcava
Esri Frequent Contributor

 

You could do the whole thing first too

 

const latLonPolygonGeometry = webMercatorUtils.webMercatorToGeographic(graphic.goemetry);

 

Then go over the rings.

Lots of options!

0 Kudos