Select to view content in your preferred language

how  to get  the point  of polygon

802
6
10-16-2012 08:15 PM
yanli
by
Emerging Contributor
how  to  get  four  point  of  Rectangle   polygon  with   arcgis server  for  js
0 Kudos
6 Replies
__Rich_
Deactivated User
0 Kudos
__Rich_
Deactivated User
Polygons are made up of rings, rings are made up of points.

This same 'path' can be used following, for example, an Identify operation to get the points of a feature.
0 Kudos
yanli
by
Emerging Contributor
Polygons are made up of rings, rings are made up of points.

This same 'path' can be used following, for example, an Identify operation to get the points of a feature.


thank  you , can  you  give me    a  example  with  code?
thank  you  very  much
0 Kudos
__Rich_
Deactivated User
can  you  give me    a  example  with  code?

I'm not going to do it all for you 🙂

But here's one approach, assume you've got a polygon (thePoly), perhaps it's the geometry property of a Graphic:

for(var i=0;i<thePoly.rings.length;i++){
    console.log("Getting points from ring #" + i);
    for(var j=0;j<thePoly.rings.length;j++){
        console.log("Point #" + j + " x=" + thePoly.rings[0] + " y=" + thePoly.rings[1] + " (using array access)");
        console.log("Point #" + j + " x=" + thePoly.getPoint(i, j).x + " y=" + thePoly.getPoint(i, j).y + " (using getPoint())");
    }
}
//Could replace the  access with a call to thePoly.getPoint(i,j) if you like which would return a copy of the Point rather than a reference to the actual Point


(haven't tested the code, just typed straight into this post, should be roughly right though)
0 Kudos
yanli
by
Emerging Contributor
I'm not going to do it all for you 🙂

But here's one approach, assume you've got a polygon (thePoly), perhaps it's the geometry property of a Graphic:

for(var i=0;i<thePoly.rings.length;i++){
    console.log("Getting points from ring #" + i);
    for(var j=0;j<thePoly.rings.length;j++){
        console.log("Point #" + j + " x=" + thePoly.rings.x + " y=" + thePoly.rings.y);
    }
}
//Could replace the  access with a call to thePoly.getPoint(i,j) if you like which would return a copy of the Point rather than a reference to the actual Point


(haven't tested the code, just typed straight into this post, should be roughly right though)


thank you ,
i have test the code 
it  is  failse  to get  x =thePoly.rings.x

it is ok  like  var pt=thePoly.getPoint(i,j); var x=pt.x;
0 Kudos
__Rich_
Deactivated User

it  is  failse  to get  x =thePoly.rings.x

Told you I hadn't tested it 🙂

I assumed that the points in the ring would be stored as Point objects whereas they're actually stored internally as simple arrays - have changed the code above.

Presumably this has answered your question?
0 Kudos