简体   繁体   中英

How to get the extent of a layer in lat long in arcmap in c#

I need to get the extent or bounding box in latitude and longitude of a layer in Arcmap in c#.

I initially used the following code but it does not always give the extent in lat long:

public IEnvelope GetExtent(IFeatureLayer PolygonLayer) {
    return PolygonLayer.AreaOfInterest.Envelope;
}

I have got a work around. The extent has to be projected.

public ISpatialReference CreateSpatialRefGCS(ESRI.ArcGIS.Geometry.esriSRGeoCSType gcsType)
{
    ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();
    IGeographicCoordinateSystem geoCS = spatialRefFactory.CreateGeographicCoordinateSystem((int)gcsType);
    return (ISpatialReference)geoCS;
}

public IEnvelope GetExtent(IFeatureLayer PolygonLayer) {
    IEnvelope envelope = PolygonLayer.AreaOfInterest.Envelope;
    envelope.Project(CreateSpatialRefGCS(esriSRGeoCSType.esriSRGeoCS_WGS1984));
    return PolygonLayer.AreaOfInterest.Envelope;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM