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;
}