I want to set extent of the map into envelope which sizes are defined by user in miles(kilometers, whatever human readable unit). How to make it? I wrote the following code:

static void ZoomToPoint(IActiveView focusMap, ExportJson2Feature.Geometry geom)
    IPoint point = new PointClass();
    point.PutCoords(geom.X, geom.Y);

    IEnvelope newExtentEnvelope = point.Envelope;
    newExtentEnvelope.Expand(1, 1, false);
    ((IGeometry)newExtentEnvelope).Project( ((IMap)focusMap).SpatialReference );
    focusMap.Extent = newExtentEnvelope;

How to make it know that sizeX/sizeY are in miles?


Geometry's coordinates are always specified in its spatial reference's units. Unit conversions are best done by using the UnitConverter class.

If that's any help, you can determine the currently used map units by IMap.MapUnits.

If your point coordinates are in lat/lon (such as the WGS84 spatial reference), you probably want to decide on a projected coordinate system first and use that when working with distances.


If your extent will be covering a large range of latitudes or areas near the poles, you may benefit from calculating the extent using a geodesic distance from the centroid.

You can use IConstructGeodetic.ConstructGeodesicCircle to create a polygon. Then you can invoke IGeometry.Envelope to get an envelope.

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.