Select to view content in your preferred language

GeometryService: Measuring area and length of a polygon

3236
11
12-07-2015 11:56 AM
TyroneBiggums
Deactivated User

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.

0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

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.

0 Kudos
TyroneBiggums
Deactivated User

I understand that is a requirement to make a polygon, but there is still something to measure in length, right?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
TyroneBiggums
Deactivated User

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'.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tyrone,

   How about using Polygon.getExtent and check for a zero width or length as a check?

0 Kudos
TyroneBiggums
Deactivated User

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.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
TyroneBiggums
Deactivated User

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.

0 Kudos
DanPatterson_Retired
MVP Emeritus

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.

0 Kudos