9

How do I get the units (meter/feet) from an ISpatialReference object in ArcObjects?

12

Linear units can be obtained from the spatial reference only if it is a projected coordinate system. So, you need to cast the spatial reference to IProjectedCoordinateSystem and access its IProjectedCoordinateSystem.CoordinateUnit property.

But if the spatial reference is a geographic coordinate system, its units are angular and accessed similarly through IGeographicCoordinateSystem.CoordinateUnit.

  • 1
    +1 The ILinearUnit.MetersPerUnit property can also save you from writing a lot of code. – Kirk Kuykendall Apr 25 '11 at 13:52
0
IFields fields = featureClass.Fields;
        ISpatialReference spatialReference = fields.get_Field(fields.FindField(featureClass.ShapeFieldName)).GeometryDef.SpatialReference;
        if (spatialReference is IProjectedCoordinateSystem)
        {
            IProjectedCoordinateSystem projectedCoordinateSystem = (IProjectedCoordinateSystem)spatialReference;
            return projectedCoordinateSystem.CoordinateUnit.Name;
        }
        if (spatialReference is IGeographicCoordinateSystem)
        {
            IGeographicCoordinateSystem geographicCoordinateSystem = (IGeographicCoordinateSystem)spatialReference;
            return geographicCoordinateSystem.CoordinateUnit.Name;
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.