Calculate distance in meters of polyline

3154
4
09-17-2012 07:42 PM
alessandroferrucci
New Contributor
Hello I have a simple question,
I'm creating a polyline on a map and when I'm done creating it I would like to display the distance in meters.

I have this code:

distanceSeg=new Polyline();
....
double  len1=distanceSeg.calculateLength2D();

I would like to convert len1 to meter units.. I tried this:

double m_len=Unit.convertUnits(len1, Unit.create(AngularUnit.Code.DEGREE) ,Unit.create(LinearUnit.Code.METER));

but I get an exception with GeometryException: invalid_call

Any help would be appreciated.

Thanks
0 Kudos
4 Replies
PhilipKnight1
Occasional Contributor
I have the same issue, ever find a solution?
0 Kudos
PuneetPrakash
Esri Contributor
convertUnits(double valueIn, Unit unitFrom, Unit unitTo)

The convertUnits method converts the input values to new units of the same UnitType. We currently do not support conversions from angular units to linear units.

double m_len=Unit.convertUnits(len1, Unit.create(AngularUnit.Code.DEGREE) ,Unit.create(LinearUnit.Code.METER));

We will update out javadoc to explicitly mention this limitation for convertUnits.

-Puneet
0 Kudos
PuneetPrakash
Esri Contributor
The convertUnits(double valueIn, Unit unitFrom, Unit unitTo) method converts the input values to new units of the same UnitType.

We currently do not support conversion from angular units to linear units

double m_len=Unit.convertUnits(len1, Unit.create(AngularUnit.Code.DEGREE) ,Unit.create(LinearUnit.Code.METER));

We will update our javadoc to explicitly state this for convertUnits.

-Puneet
0 Kudos
PhilipKnight1
Occasional Contributor
0 Kudos