How to get coordinates of each vertex of a polygon?

651
4
Jump to solution
06-23-2020 11:20 PM
SiyabongaKubeka
Occasional Contributor

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)
0 Kudos
1 Solution

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

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus
crmLatitude = String(gra.geometry.rings[i][p].getLatitude());
crmLongitude = String(gra.geometry.rings[i][p].getLongittude());
SiyabongaKubeka
Occasional Contributor

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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]]);
SiyabongaKubeka
Occasional Contributor

Hi Robert,

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

0 Kudos