I am loading a TIFF using the following code, but the image does not appear. Is there something wrong (maybe with the World File? I downloaded the image from TerraServer and it came with the World File.
Private Sub AddRasterImage(ByVal filePath As String, ByVal OverlayKey As String) Dim worldImageLayer As GdiPlusRasterLayer = New GdiPlusRasterLayer(filePath) AddHandler (CType(worldImageLayer.ImageSource, GdiPlusRasterSource)).StreamLoading, AddressOf Image_StreamLoading worldImageLayer.UpperThreshold = Double.MaxValue worldImageLayer.LowerThreshold = 0 worldImageLayer.IsGrayscale = False
Dim ImageOverlay As LayerOverlay = New LayerOverlay() ImageOverlay.Layers.Add(OverlayKey & "Layer", worldImageLayer) WpfMap1.Overlays.Add(OverlayKey & "Overlay", ImageOverlay) WpfMap1.Overlays.MoveToBottom(WpfMap1.Overlays.IndexOf(ImageOverlay)) End Sub
Private Sub Image_StreamLoading(ByVal sender As Object, ByVal e As StreamLoadingEventArgs) If e.StreamType = "Image File" Then Dim stream As IO.Stream = New FileStream(e.AlternateStreamName, FileMode.Open, FileAccess.Read) e.AlternateStream = stream End If
If e.StreamType = "World File" Then Dim fName As String = IO.Path.GetFullPath(e.AlternateStreamName) Select Case IO.Path.GetExtension(e.AlternateStreamName).ToUpper Case ".TIF" fName = fName.Substring(0, fName.Length - 3) & "tfw" Case ".JPG" fName = fName.Substring(0, fName.Length - 3) & "jgw" End Select Dim stream As IO.Stream = New FileStream(fName, FileMode.Open, FileAccess.Read) e.AlternateStream = stream End If End Sub
The World File contains:
5.648000
0.000000
0.000000
-5.648000
573645.000000
2918226.000000
If I use:
Dim worldImageLayer As GdiPlusRasterLayer = New GdiPlusRasterLayer(filePath, New RectangleShape(-80.26173, 26.38224, -80.1914, 26.31811))
If I put a debug.print statement before both e.AlternateStream = stream in the streamloading method, I get alternating world file and image file, but still no image on the map. If I zoom in or out, I still see the alternating streaming.
Could it be the different projectons in the world file? For instance, one of my worlld files is: Geo-reference Information: Projection: Geographic Datum: WGS 84 Image Units: Meters
and the oher is: Geo-reference Information: Projection: UTM Zone 17 Datum: WGS 84 Image Units: Meters
Let me interject in the conversation very quick. I am not familiar with the streaming issue but one thing that you need to make sure is to set the MapUnit of your map correctly. If you world file contains values like 573645 for the x-coordinate of the center of the upper left pixel and 2918226 for the y-coordinate, then the MapUnit has to be in Meters. The world file itself does not contain projection information, only the coordinates for the image to be placed geographically. (en.wikipedia.org/wiki/World_file) . I just want to make sure we have that well established before trying to find the problem anywhere else.
Good catch… that is probably the problem. Now the question is, is there a way to use a world file in meters when the map is set as DecimalDegree? Or do I just have to plan on putting the rectangle in?
No, if your image is in meters, you need to have your map unit also in that unit. Only in some specific situations you can trick an image into Decimal Degrees from Meters. I suggest you look at the sample code Google Map to Geodetic so that you get a little more background on the issue. wiki.thinkgeo.com/wiki/Map_Suite_De...o_Geodetic
For your question "Do I just have to plan on putting the rectangle in?". I am not sure what you mean.
As the Val said, the image’s unit should be the same as the map unit and I think the sample project is useful for you.
For your question “Do I just have to plan on putting the rectangle in”, I guessed you talked about the extent for the map, if that, you should set the map’s current extent to the boundingbox of the image to display it.
Thanks Scott and Val. What I meant by the rectangle is that I will not use the world file, but instead just display the image using: Dim worldImageLayer As GdiPlusRasterLayer = New GdiPlusRasterLayer(filePath, New RectangleShape(-80.26173, 26.38224, -80.1914, 26.31811))
Yes, if you have the correct extent value for the image file, you don’t need to use the world file. But you need to set the extent correctly so that the image file display correctly.