Hi,
I’m trying to save the Map as GeoTIFF. The Function will store a TIF and TFW file.
But the result is stretched and rotated.
The data is projected (EPSG 25832)
This is the Function to store GeoTIFF with TFW:
Public Sub ExportBitmap(filename As String, format As Imaging.ImageFormat, Optional pictureWidth As Integer = 1000, Optional ExportExtent As RectangleShape = Nothing, Optional BackColor As Boolean = False)
Dim bitmap As Bitmap = Nothing
If ExportExtent Is Nothing Then
ExportExtent = theMap.CurrentExtent
End If
Dim MapRect As RectangleShape = GetProjectedShape(ExportExtent.GetBoundingBox).GetBoundingBox
Dim MapWidth As Integer = CInt(MapRect.Width)
Dim MapHeight As Integer = CInt(MapRect.Height)
If pictureWidth > 0 Then
Dim f As Double = pictureWidth / MapRect.Width
MapHeight = f * MapRect.Height
MapWidth = pictureWidth
End If
bitmap = New Bitmap(MapWidth, MapHeight)
Dim g As Graphics = Graphics.FromImage(bitmap)
If BackColor Then
g.FillRectangle(Brushes.White, 0, 0, MapWidth, MapHeight)
End If
Dim gdiPlusPlatformGeoCanvas As New PlatformGeoCanvas
gdiPlusPlatformGeoCanvas.BeginDrawing(bitmap, ExportExtent.GetBoundingBox(), theMap.MapUnit)
gdiPlusPlatformGeoCanvas.DrawingQuality = DrawingQuality.HighQuality
Dim labelsInAllLayers As New Collection(Of SimpleCandidate)()
For Each exportOverlay As LayerOverlay In theMap.Overlays
If IsMapOverlayVisible(exportOverlay.Name) Then
For Each exportLayer As ThinkGeo.MapSuite.Layers.Layer In exportOverlay.Layers
If exportLayer.IsVisible Then
exportLayer.Draw(gdiPlusPlatformGeoCanvas, labelsInAllLayers)
End If
Next
End If
Next
gdiPlusPlatformGeoCanvas.EndDrawing()
Dim MyFile As FileInfo = My.Computer.FileSystem.GetFileInfo(filename)
bitmap.Save(filename, format)
Dim worldFile As String
Dim PixelSizeX As Double = MapRect.Width / MapWidth
Dim PixelSizeY As Double = MapRect.Height / MapHeight
Dim XCoord As Double = MapRect.UpperLeftPoint.X
Dim YCoord As Double = MapRect.UpperLeftPoint.Y
worldFile = PixelSizeX.ToString() & vbNewLine
worldFile &= "0" & vbNewLine
worldFile &= "0" & vbNewLine
worldFile &= "-" & PixelSizeY.ToString() & vbNewLine
worldFile &= XCoord.ToString("0.000") & vbNewLine
worldFile &= YCoord.ToString("0.000")
My.Computer.FileSystem.WriteAllText(MyFile.FullName.Replace(MyFile.Extension, ".tfw"), worldFile.Replace(",", "."), False, Encoding.ASCII)
End Sub
The result looks like:
Blue: Shape-File as reference
What to do to get a correct GeoTIFF?
Regards
Hardy