# How to get the unit of a Geometry? Or gets the distance in specified units between two geometries

322
3
03-05-2022 04:28 AM
New Contributor II

Hi there. I'm trying to get the distance of two geometries by this api ArcGIS Pro 2.8 API Reference Guide - Distance Method—ArcGIS Pro.

But I found that I will get a result in meter from some .shp files. But when I use another .shp file, it seems to be kilometer...

I'm so confused about it. And I have searched API document, and found that I can set the LinerUnit if I use  GeodesicDistance refers in ArcGIS Pro 2.9 API Reference Guide - GeodesicDistance(Geometry,Geometry,LinearUnit) Method—ArcGIS Pr...

But I have used 2.8 API, there's no this implement...

And I have tried to get the elevation unit format of the map, they're all meter in different .shp file.

So how can I get the unit type of a Geometry? Or can I change the distance result to meter directly?

Thanks a lot!

Tags (1)
1 Solution

Accepted Solutions
New Contributor II

I found that GeodesicDistance  can return the distance in meteres by default

ArcGIS Pro 2.8 API Reference Guide - GeodesicDistance Method—ArcGIS Pro

So I can use it to get the distance in LinearUnit.Meteres

And then convert it to other LinearUnit. It solved my problem.

Thank you so much!

3 Replies
Esri Regular Contributor

use the geometry spatial reference:

https://pro.arcgis.com/en/pro-app/2.8/sdk/api-reference/#topic8178.html

specifically, its Unit property.

https://pro.arcgis.com/en/pro-app/2.8/sdk/api-reference/#topic8797.html

In your case it sounds like it is of type LinearUnit.

New Contributor II

I found that the special reference of my geometry is AngularUnit.Degrees.

And I try to convert it to LinearUnit.Meters.

But there's no such implement that can convert the unit from angular to linear...

So any other methods can I try?

Thank you!

New Contributor II

I found that GeodesicDistance  can return the distance in meteres by default

ArcGIS Pro 2.8 API Reference Guide - GeodesicDistance Method—ArcGIS Pro

So I can use it to get the distance in LinearUnit.Meteres

And then convert it to other LinearUnit. It solved my problem.

Thank you so much!