Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
    Try
        '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
    pAV.Refresh()

    '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.
    pExport.FinishExporting()
    pExport.Cleanup()
End Sub
share|improve this question
2  
Found the answer here: gis.stackexchange.com/questions/9943/… . –  Bryan Jun 12 '12 at 22:35

2 Answers 2

Hello Michael(it sounds like Knigth rider..jejejeje)

You already has the procedure to rotate, it is quite easy...then to scale the map you can use somethig 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;
            p.MapControl.Refresh();
        }

I hope this will be usefull....maybe check the objects before copy and paste...but in escence it will work....by the way...the rotation of the polygon is counterclockwise.

share|improve this answer

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.

share|improve this answer
    
Did this solve the problem or is it another manifestation of the same problem? –  whuber Jun 12 '12 at 21:53
1  
This solved the problem: gis.stackexchange.com/questions/9943/… –  Bryan Jun 13 '12 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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