从ArcObjects的ISpatialReference获取单位?


Answers:


12

仅当线性参考是投影坐标系时,才能从空间参考获得线性单位。因此,您需要将空间参考投射到IProjectedCoordinateSystem并访问其IProjectedCoordinateSystem.CoordinateUnit属性。

但是,如果空间参考是地理坐标系,则其单位是有角度的,并且可以通过IGeographicCoordinateSystem.CoordinateUnit进行类似访问。


1
+1 ILinearUnit.MetersPerUnit属性还可以避免编写大量代码。
Kirk Kuykendall

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;
        }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.