How to get coordinates of each vertex of a polygon?

76
4
Jump to solution
06-23-2020 11:20 PM
Highlighted
New Contributor III

Hi All

I am trying to get the coordinates of each vertex and separate they by putting all the latitudes on one field and all the longitudes on one field. This is who I tried to do it but it is not dong what I want it to do:

for (var i = 0; i < gra.geometry.rings.length; i++){
for (var p = 0; p < gra.geometry.rings.length; p++){
crmLatitude = String(gra.geometry.rings);
crmLongitude = String(gra.geometry.rings

);
var LatLon = String(gra.geometry.rings

);
console.log(LatLon);
latlon = LatLon;

}

How can I do it? Please assist.

Kind Regards

Siyabonga Kubeka

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor
crmLatitude = String(gra.geometry.rings[i][p].getLatitude());
crmLongitude = String(gra.geometry.rings[i][p].getLongittude());

View solution in original post

4 Replies
Highlighted
MVP Esteemed Contributor
crmLatitude = String(gra.geometry.rings[i][p].getLatitude());
crmLongitude = String(gra.geometry.rings[i][p].getLongittude());

View solution in original post

Highlighted
New Contributor III

Hi Robert, 

Thank you very much. One last question, is it possible to use those stored coordinates to recreate the polygon? The idea is to save a map and the polygon, so that it can be opened at another stage. If there is a way, how do I do it?

Regards

Siyabonga Kubeka

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

https://developers.arcgis.com/javascript/3/jsapi/polygon-amd.html#polygon3

Build the polygon using the coordinates saved.

var singleRingPolygon = new Polygon([[50, 0], [150, 20], [150, -20], [50,0]]);
Highlighted
New Contributor III

Hi Robert,

When I use the suggestion above I get the following error saying that getLatitude and getLongitude are not functions.

Reply
0 Kudos