I'm using a GeometryService to measure the length and area of a polygon. Everything is fine unless my polygon is a single line (here me out). I start to draw a polygon by clicking the map then double click the map after just forming a line. There become two line segments and the geometry.ring has 3 coordinates ([-3184781.0569155607,5458796.020593386,1746324.5118164345,4813056.005640387,-3184781.0569155607,5458796.020593386]).
The results of areas-and-lengths-complete are that area and length are 0. Area, sure. Makes sense. But length is 0?
And yes, I know that no user SHOULD do that. They should just use a polyline if they want a line. But, is this a normal/expected result?
Thanks.
a wild guess is that at least 3 different points are needed since in most of Arc* world a triangle (aka 3 distinct points) needs 4 points to complete with the first and last duplicates and with the points in clockwise order.
I understand that is a requirement to make a polygon, but there is still something to measure in length, right?
Tyrone,
Ya, I would kind of figure that it would bomb on the fact that there is not a valid polygon. If it was just a polyline then you would be using GeometryService.lengths not areasAndLengths.
And that's exactly the problem. I am using just lengths for a polyline. If the user intends on using that polygon as a polyline, they won't understand why there is no length. On the back end, I'm using length if the geometry.type is a polyline. And of course, fake polygon or not, the geometry.type is still polygon on this one line 'polygon'.
Tyrone,
How about using Polygon.getExtent and check for a zero width or length as a check?
Polygon.getExtent().getWidth() is well over 0 and Polygon.getExtent.getHeight() is just over 0. miny and maxy are so close to being the same number, but since they are different, we don't have any 0 values.
Tyrone,
Well that was not what I was expecting. Would that small difference in the miny and maxy (or in other cases the minx and maxx) be enough for you to setup a coding check against? Short of that you would need to report this to tech support and see if you can get someone to escalate it to the dev team to be addressed.
The difference in min/max is relative to the map scale, and spatial reference. It would have to be a pretty smart checker just to see if a polygon with 1 line should actually be a line. I'll have this issue brought up to someone in Esri.
sadly Arc* stuff often defaults to 0 when either creating objects (ie a null point still has coordinates of 0,0) or measuring parameters. Do what Robert says...check the properties of the expected geometries.