Select to view content in your preferred language

GeometryService: Measuring area and length of a polygon

3149
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
KristianEkenes
Esri Regular Contributor

Tyrone,

The length operation should return a value that is not zero, but I'm not sure how useful it would be since it is expected to be twice the length of the line (the perimeter of the invalid polygon). If you simplify the geometry prior to inputting it to the lengths function then you will get a result of 0 for the length.

Is there a scenario when you would want a polygon with two vertices as opposed to a line?

0 Kudos
TyroneBiggums
Deactivated User

Not a legitimate scenario, but even the default draw tool example allows you to.

http://developers.arcgis.com/javascript/samples/toolbar_draw/

As a work around, on draw complete, if the graphic isn't an actual polygon, I cancel the draw and do not add the graphic.

0 Kudos