How to get linear distance units of a layer?

6261
5
Jump to solution
02-16-2015 11:22 AM
WhereMatters
Occasional Contributor

This must be an easy one, but i am having a hard time with this.

How do i read the linear distance units of a feature layer or a dynamic map service using the javascript API?

for e.g., wkid 4326 it is degrees, 102100 it is meters and for some it is feet etc.,

what about spatial references which have only a WKT (custom) and no WKID?

i  need to display the linear units of a layer (feature/dynamic) programatically to show the units in which the areas and lengths are being displayed in a popup.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

All,

   They have added getUnitValueForSR(sr) ability in 3.13

esri/geometry/scaleUtils | API Reference | ArcGIS API for JavaScript

View solution in original post

5 Replies
OwenEarley
Occasional Contributor III

If you are referring to the feature attributes then the values will be in the coordinate system of the source data.

When working with a map service you can access the spatialReference property. However the SpatialReference class does not contain a property for linear units.

If you need the linear units then you could create a function to lookup the value based on a WKID. The following links contain all supported coordinate systems and includes the linear unit values:

0 Kudos
WhereMatters
Occasional Contributor

Hi Owen, thank you so much for the response, but seriously,

Something as fundamental as this is not provided out of the box in the API?

maybe i dont understand the complexity of the problem that the API team may have in providing this OOTB.

As you say, we'l have to create a function to read the WKT value based on a WKID from the links you posted and then extract the units from the WKT and convert them to esriLinearUnits, correct?

0 Kudos
OwenEarley
Occasional Contributor III

I was also very surprised to see how little information was contained in the JS API SpatialReference object.

0 Kudos
JeffJacobson
Occasional Contributor III
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

All,

   They have added getUnitValueForSR(sr) ability in 3.13

esri/geometry/scaleUtils | API Reference | ArcGIS API for JavaScript