I am writing a console application using ArcGIS (engine or desktop). I'm trying to rotate and scale a map based on a polygon, and I'm not having any luck at all. With some tinkering, I can usually do one or the other but not both.

Anybody have any suggestions? I feel as though I've tried every variation in terms of rotating the map and adjusting the scale either using the Imap interface, or the IActiveView interface.

    Private Sub Zoom2AndExportJpgs(mapDocument As IMapDocument, imagePath As String)
    'Get the relevant strip maps for the route
    Dim map As IMap = mapDocument.Map(0) '(assumed that there is only one map in the mxd)
    Dim pageLayout As IPageLayout = mapDocument.PageLayout
    Dim pageAV As IActiveView = pageLayout
    Dim mapAV As IActiveView = map
        'get a list of strip map objects... EF object containing a list of the 4 corners of a polygon
        Dim stripmaps As List(Of MRLAStripMapExtent) = getStripMaps()
        Dim filename As String = ""

        'get all the associated stripmaps for the route  for each scale
        If Not stripmaps Is Nothing Then
            For i = 0 To stripmaps.Count - 1
                Dim pgon As IPolygon = geometryHelper.CreatePGON(stripmaps(i).RectLowerLeftX, stripmaps(i).RectLowerLeftY, _
                                                                                             stripmaps(i).RectLowerRightX, stripmaps(i).RectLowerRightY, _
                                                                                             stripmaps(i).RectUpperLeftX, stripmaps(i).RectUpperLeftY, _
                                                                                            stripmaps(i).RectUpperRightX, stripmaps(i).RectUpperRightY)
                filename = imagePath & stripmaps(i).ZoomScale & stripmaps(i).PageNumber & ".jpg"
                CreateJpgFile(filename, mapAV, pageAV, pgon, stripmaps(i).ANGLE, stripmaps(i).ZoomScale)

            Next i
        End If

    Catch ex As Exception
        publishError.PublishError(publishError.ErrorSeverity.majorStopRouteProcessing, ex)
    End Try

End Sub

Private Sub CreateJpgFile(ByVal sFilename As String, ByVal pAV As ESRI.ArcGIS.Carto.IActiveView, _
                          ByVal pPageActiveView As ESRI.ArcGIS.Carto.IActiveView, _
                          ByVal pgon As IPolygon,
                          rotationAngle As Double, _
                          mapScale As Double)

    Dim pExport As ESRI.ArcGIS.Output.IExport
    pExport = New ESRI.ArcGIS.Output.ExportJPEG

    pAV.Extent = pgon.Envelope
    pAV.ScreenDisplay.DisplayTransformation.ScaleRatio = mapScale
    pAV.ScreenDisplay.DisplayTransformation.Rotation = rotationAngle '0

    'Export Image....
    pExport.ExportFileName = sFilename
    pExport.Resolution = 96
    Dim exportRECT As ESRI.ArcGIS.esriSystem.tagRECT
    exportRECT = pPageActiveView.ExportFrame
    Dim pPixelBoundsEnv As ESRI.ArcGIS.Geometry.IEnvelope
    pPixelBoundsEnv = New ESRI.ArcGIS.Geometry.Envelope
    pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.bottom, exportRECT.right, exportRECT.top)
    pExport.PixelBounds = pPixelBoundsEnv
    Dim hDC As Integer
    hDC = pExport.StartExporting
    pPageActiveView.Output(hDC, pExport.Resolution, exportRECT, Nothing, Nothing)

    'Finish writing the export file and cleanup any intermediate files.
End Sub

2 Answers 2


I'm actually doing something similar. What tinkering did you do? I made an envelope and expanded the envelope based on a ratio of the desired scale and the templateMap's scale.

mapEnvelope.Expand(scale / templateMap.MapScale, scale / templateMap.MapScale, true);
((IActiveView)templateMap).Extent = mapEnvelope;

It loses accuracy though.


You already has the procedure to rotate, it is quite easy...then to scale the map you can use something like this:

var p = this.CurrentContentView;
        if (p != null)
            var currentExtent = new Envelope();
            var newExtent = new Envelope();
            var newPoly = new Polygon();
            newExtent = this.Map.get_Layer(0).AreaOfInterest as Envelope;
            if (this.Map.Rotation != 0)
                newExtent = null;
                currentExtent = this.Map.get_Layer(0).AreaOfInterest as Envelope;

                newPoly.AddPoint(new Point()
                                         X = currentExtent.XMin,
                                         Y = currentExtent.YMin
                newPoly.AddPoint(new Point()
                                         X = currentExtent.XMax,
                                         Y = currentExtent.YMax
                IPoint center = (currentExtent as IArea).Centroid;
                ITransform2D trans = newPoly as ITransform2D;
                trans.Rotate(center, (p.MapControl.Rotation * (Math.PI / 180)));
                newExtent = ((IGeometry)newPoly).Envelope as Envelope;

            newExtent.Expand(1.1, 1.1, true);
            p.MapControl.ActiveView.Extent = newExtent as IEnvelope;

Maybe check the objects before copy and paste...but in essence it will work....by the way...the rotation of the polygon is counterclockwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.