ThinkGeo.com    |     Documentation    |     Premium Support

RasterLayer not drawn correct on zoomlevel

Hello,


we use our own raster layer class based on your MultiGeoRasterLayer-Demo to display Tif-WorldFile. We have implemented this layer in an web service. This means we draw the map in the web service and send the image back to client where it is drawn on the canvas.


Sometimes we recognize that the raster layer is not drawn when we zoom in or out although we show the same map extent. We debugged our raster layer class and noticed that code works correct.


We detect the layers inside bounding box, open them with GDIPlusRasterLayer, draw them on GDIPlusGeoCanvas and send image back to client. But sometimes we can detect that the image GDIPlusGeoCanvas has drawn is not correct.


I have attached the images drawn by GDIPlusGeoCanvas where you can see that  image for Zoomlevel13 is not correct.


Please let me know if you need additional information.


Thanks Thomas


-------


PS


I noticed that DrawCore() is called twice via MapControl if I change map extent e.g. pan to left. Is this correct?



1846-Canvas.zip (22.4 KB)

Thomas, 
  
 Thanks for your post and questions. 
  
 So basically your problem is that in the server side which use the GdiPlusGeoCanvas to draw directly sometimes did not draw the image correctly. I doubt if the following drawing procedures are applied correctly in the server side. 
 gdiPlusRasterCanvas.BeginDrawing; 
 gdiPlusRasterCanvas.Draw; 
 gdiPlusRasterCanvas.Flush; 
 gdiPlusRasterCanvas.EndDrawing; 
  
 About the twice or more times when Panning, I think that is correct, because we will draw the map when new tiles comes up on panning, which will make the map control much more responsive.  We can change this behavior by set all the overlay to non base overlays. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Hello Yale,


can you take a look on our server side code. There are two methods  to draw the map. Maybe there is an bug. But why occurs this error only on drawing the image for zoomlevel13?
Public Function getLayerImage(ByVal dblBBULX As Double, ByVal dblBBULY As Double, _
                                     ByVal dblBBLRX As Double, ByVal dblBBLRY As Double, _
                                     ByVal lngImageWidth As Integer, ByVal lngImageHeight As Integer, _
                                     ByVal lngID_Layer As Int64) As Byte()


    Dim ocNettroLayer As cNettroLayer = Nothing
    Dim ocNettroRasterLayer As cNettroRasterLayer
    Dim oBoundingBox As ThinkGeo.MapSuite.Core.RectangleShape
    Dim oGdiPlusGeoCanvas As ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas
    Dim oGeoImage As ThinkGeo.MapSuite.Core.GeoImage
    Dim bytArray(-1) As Byte

    Try

      oBoundingBox = New ThinkGeo.MapSuite.Core.RectangleShape(New ThinkGeo.MapSuite.Core.PointShape(dblBBULX, dblBBULY), _
                                                               New ThinkGeo.MapSuite.Core.PointShape(dblBBLRX, dblBBLRY))


      If Me.ermittleLayer(lngID_Layer, ocNettroLayer) Then

        oGdiPlusGeoCanvas = New ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas
        oGeoImage = ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas.CreateGeoImage(lngImageWidth, lngImageHeight)

        SyncLock ocNettroLayer

          Try

            oGdiPlusGeoCanvas.BeginDrawing(oGeoImage, oBoundingBox, ThinkGeo.MapSuite.Core.GeographyUnit.Meter)
            ocNettroRasterLayer = DirectCast(ocNettroLayer, cNettroRasterLayer)
            ocNettroRasterLayer.zeichneKartenAusschnitt(oGdiPlusGeoCanvas) 'Draws the World-Files ont the Canvas

          Finally
            If oGdiPlusGeoCanvas.IsDrawing Then
              oGdiPlusGeoCanvas.EndDrawing()
            End If
          End Try

        End SyncLock

        bytArray = ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas.ConvertGeoImageToMemoryStream(oGeoImage).ToArray


        'Code zum Testen ob Karte richtig gezeichnet wurde
        'Dim oStream As System.IO.Stream
        'Dim oImage As System.Drawing.Bitmap = Nothing

        'Try
        '  oStream = New System.IO.MemoryStream(bytArray)
        '  oImage = New System.Drawing.Bitmap(oStream)
        '  oImage.Save("c:\Canvas_Zoomlevel13.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

        'Catch ex As Exception
        'Finally
        '  oStream.Close()
        '  oImage.Dispose()
        'End Try

      End If

    Catch ex As Exception
      With New Nettropolis.Shared2.cErrorLogging
        .logError(ex, bolThrowException:=True, bolShowError:=False)
      End With
    Finally
      getLayerImage = bytArray
    End Try
  End Function


  Public Sub zeichneKartenAusschnitt(ByRef oCanvas As ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas)

    Dim oEnvelope As GisSharpBlog.NetTopologySuite.Geometries.Envelope
    Dim strRowIndexDokumentArrayList As System.Collections.ArrayList
    Dim oGdiPlusRasterLayer As ThinkGeo.MapSuite.Core.GdiPlusRasterLayer = Nothing
    Dim oGeoImage As ThinkGeo.MapSuite.Core.GeoImage
    Dim oCenterPoint As ThinkGeo.MapSuite.Core.PointShape
    Dim oCenterPointScreen As ThinkGeo.MapSuite.Core.ScreenPointF
    Dim extent As ThinkGeo.MapSuite.Core.RectangleShape
    Dim strPfad As String = ""
    Dim intersectionShape As ThinkGeo.MapSuite.Core.RectangleShape = Nothing

    Try

      oEnvelope = New GisSharpBlog.NetTopologySuite.Geometries.Envelope(oCanvas.CurrentWorldExtent.UpperLeftPoint.X, _
                                                                        oCanvas.CurrentWorldExtent.LowerRightPoint.X, _
                                                                        oCanvas.CurrentWorldExtent.UpperLeftPoint.Y, _
                                                                        oCanvas.CurrentWorldExtent.LowerRightPoint.Y)

      If Not m_oSTRtree Is Nothing Then

        strRowIndexDokumentArrayList = m_oSTRtree.Query(oEnvelope)
        If strRowIndexDokumentArrayList.Count > 0 Then

          For Each strRowIndexDokument As String In strRowIndexDokumentArrayList

            'oGdiPlusRasterLayer.UpperThreshold = m_dblUpperThreshold
            'oGdiPlusRasterLayer.LowerThreshold = m_dblLowerThreshold

            If Me.Kartendatei.ermittleKartendateiCachePfad(Convert.ToInt32(strRowIndexDokument), strPfad) Then

              Try

                oGdiPlusRasterLayer = New ThinkGeo.MapSuite.Core.GdiPlusRasterLayer(strPfad)
                oGdiPlusRasterLayer.Open()
                extent = oGdiPlusRasterLayer.GetBoundingBox()
                oGeoImage = oGdiPlusRasterLayer.ImageSource.GetImage(oCanvas.CurrentWorldExtent, CInt(Math.Round(oCanvas.Width)), CInt(Math.Round(oCanvas.Height)))

              Finally
                If oGdiPlusRasterLayer.IsOpen Then
                  oGdiPlusRasterLayer.Close()
                End If
              End Try

              intersectionShape = extent.GetIntersection(oCanvas.CurrentWorldExtent).GetBoundingBox()
              oCenterPoint = intersectionShape.GetCenterPoint()
              oCenterPointScreen = ThinkGeo.MapSuite.Core.ExtentHelper.ToScreenCoordinate(oCanvas.CurrentWorldExtent, oCenterPoint, oCanvas.Width, oCanvas.Height)

              oCanvas.DrawScreenImage(oGeoImage, oCenterPointScreen.X, oCenterPointScreen.Y, oGeoImage.GetWidth + 2, oGeoImage.GetHeight + 2, _
                                     ThinkGeo.MapSuite.Core.DrawingLevel.LevelOne, 0.0, 0.0, 0.0)

              oGeoImage.Close()

            End If

          Next

        End If
      End If

    Catch ex As Exception
      With New Nettropolis.Shared2.cErrorLogging
        .logError(ex, bolThrowException:=True, bolShowError:=False)
      End With
    Finally
    End Try

  End Sub



Thomas, 
  
 Thanks for your reply. 
  
 Could you give more information about this? For example, could you try to figure out the parameters passed in when an empty image expected to return? I could not find very obvious error on your code except missing some Flush before EndDrawing. 
  
 Is it possible to make a small application with this problem exists for us to recreate it? That would be very helpful. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Hello Yale,


I created a small sample application where you can see the drawing error when you zoom to scale 144187,448.


How can I upload my sample. It's about 65MB because of the tif-world-file.


Thanks


Thomas



Thomas, 
  
 Thanks for your post and reply. 
  
 I think the 65 MB should be too large to upload via the discussion form or email, so could you contact our support to see whether he can provide you a port to upload it, when you send mail to him, please make sure let him know that this is expected to forward to Yale. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Hello Yale,


just want to ask if you have got my sample application I have uploaded to your ftp server in the customer area.


Thomas



Thomas, 
   
 Thanks for your reply.  
   
 Yes, I have downloaded this sample and I have replied you in the ticket (2608). I will do more investigations based on your reply on the ticket. 
   
 Any more questions just feel free to let me know. 
   
 Thanks. 
   
 Yale