Answers:
仅当线性参考是投影坐标系时,才能从空间参考获得线性单位。因此,您需要将空间参考投射到IProjectedCoordinateSystem并访问其IProjectedCoordinateSystem.CoordinateUnit属性。
但是,如果空间参考是地理坐标系,则其单位是有角度的,并且可以通过IGeographicCoordinateSystem.CoordinateUnit进行类似访问。
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;
}