ThinkGeo.com    |     Documentation    |     Premium Support

WPF GeoTiff Example

Hello,

My project are required to use the map in TIff format. Someone can share me any example that required GeoTiff in WPF.

Best regards and thank you.

Hi Mohamad,

To support Tiff format data, you have two choices with ThinkGeo:

  1. With GeoTiffRasterLayer, here is one post already mentioned that:
    GeoTiffRasterLayer
  2. With NativeImageRasterLayer, here is one sample in GitHub:
    https://github.com/ThinkGeo/StreamLoadingForNativeImageSample-ForWinForms

You can easy to tell the difference for the two class with its API.

If you need any more information, please feel free to let us know that.

Thanks
Mark

Hi Mark,

I have a portion of raster map in Tiff format and it cant display on the both method that you share. Sorry I still new to this. How to determine the geography unit for the map?

Hi Mohamad_Fathin,

You can get the information from your data provider.

If you hadn’t get the information there, please try to “Open” the tiff layer, then “GetBoundingBox” to see what’s its default bounding box. If the value of X is between -180 and 180, that’s maybe decimal degree, if it’s a bigger number it should be meter.

Wish that’s helpful.

Regards,

Ethan

Hi Ethan,

I try the code from the example that been shared. When i run the code it appear only white blank only. Below is the code that i use to display the raster map. That only one of total eight part of the raster map.

Thank you and best regards,

public MainWindow()
{
InitializeComponent();
}

    private void Map_Loaded(object sender, RoutedEventArgs e)
    {
        Map1.MapUnit = GeographyUnit.Meter;

        LayerOverlay myOverlay = new LayerOverlay();


        GeoTiffRasterLayer tiffLayer = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\GeotiffEx\GeotiffEx\4257.tif");
        myOverlay.Layers.Add(tiffLayer);
        tiffLayer.Open();
        Map1.CurrentExtent = tiffLayer.GetBoundingBox();
        tiffLayer.Close();

    }


}

Hi Mohamad,

If it only shows the 1/8 of your tiff file, which means the default value of bounding box in your file is incorrect.

You can add the event of ExtentChanged in map, and then zoom&pan on map to make it shows all the shapes, then record current extent and use it as your initialize CurrentExtent value.

Regards,

Ethan

Hi Ethan

Sorry wrong information. It does not display anything. Only white blank space. No map appear on the display when I run.
Can you help regarding this. Below is the raster map that i need to display.

https://www.sendspace.com/file/8agklw

Thank you and best regards

Hi Mohamad,

It looks your link need to create account and login to download, but I cannot do that here.

Could you please share your file via some other famous netdisk for example GoogleDrive?

Regards,

Ethan

Hi Ethan

Sorry for the for the hassle. This link for GoogleDrive.

Thank you and best regard.

Hi Mohamad,

It looks your data is correct, I double check your code and found you forget add the overlay into map.

map.Overlays.Add(myOverlay);

It will works now:

Regards,

Ethan

Hi Ethan,

Thank you very much. Sorry i missed that code. Did you have any idea how can i merge the raster map? The one that i share is only one part.

Thank you and best regards.

Hi Mohamad,

I don’t know how you want to merge your data, if that’s a group of data files, I think you can just create many layers and add them into map, they will shows on map at the same time.

Regards,

Ethan

Hi Ethan,

I want one part of raster map combine with other part to become a big raster map. Just like a mosaic or tiles.

Thank you and best regards

Hi Mohamad,

We can render them on same map but it’s “looks like” merge but not the data file level merge.

And whether they can looks like a entire map is decided by the bounding box of each part, if the bounding box is exact it will looks like a entire map.

Please try to render them by different layer and view the result, you can add all layers into same overlay.

Regards,

Ethan

Hi Ethan

I add layer just like u said and it works. Image attach is the sample i do. Why it slow to reload the map when I zoom?

Thank you and best regards,

Hi Mohamad,

I think your data is big and load need time, so I think you can try to open cache for the overlay and it will get better performance.

Regards,

Ethan

Hi Ethan,

May i know how to open cache for the overlay? Did I need to use the open() and close() for every layer. Below is my code that i use to display the raster map.

Thank you and best regards

        Map1.MapUnit = GeographyUnit.Meter;
        LayerOverlay myOverlay = new LayerOverlay();
        Map1.Overlays.Add(myOverlay);
       
        

        GeoTiffRasterLayer tiffLayer1 = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\RasterMapViewer\RasterMapViewer\RasterMap\4257.tif");
        myOverlay.Layers.Add(tiffLayer1);       
        tiffLayer1.Open();
        Map1.CurrentExtent = tiffLayer1.GetBoundingBox();
        tiffLayer1.Close();
  

        GeoTiffRasterLayer tiffLayer2 = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\RasterMapViewer\RasterMapViewer\RasterMap\4258.tif");
        myOverlay.Layers.Add(tiffLayer2);
        tiffLayer2.Open();
        Map1.CurrentExtent = tiffLayer2.GetBoundingBox();
        tiffLayer2.Close();

        GeoTiffRasterLayer tiffLayer3 = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\RasterMapViewer\RasterMapViewer\RasterMap\4259.tif");
        myOverlay.Layers.Add(tiffLayer3);
        tiffLayer2.Open();
        Map1.CurrentExtent = tiffLayer2.GetBoundingBox();
        tiffLayer2.Close();

        GeoTiffRasterLayer tiffLayer4 = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\RasterMapViewer\RasterMapViewer\RasterMap\4260.tif");
        myOverlay.Layers.Add(tiffLayer4);
        tiffLayer4.Open();
        Map1.CurrentExtent = tiffLayer4.GetBoundingBox();
        tiffLayer4.Close();

        GeoTiffRasterLayer tiffLayer5 = new GeoTiffRasterLayer(@"c:\users\user\documents\visual studio 2012\Projects\RasterMapViewer\RasterMapViewer\RasterMap\4357.tif");
        myOverlay.Layers.Add(tiffLayer5);
        tiffLayer5.Open();
        Map1.CurrentExtent = tiffLayer5.GetBoundingBox();
        tiffLayer5.Close();

Hi Mohamad,

You can open cache like this:

myOverlay.TileCache = new FileBitmapTileCache(“YourPath”);

For open and close you can did that or not, please don’t worry because it only be called once.

Regards,

Ethan

Hi Ethan

Thank you for the solution. From my previous code did you have any idea how can I import the map in bundle. I mean i don’t need to write every line of code for the every part of raster map tile.

Thank you and best regards,

Hi Mohamad,

If your layers don’t need set custom parameter, you can loop the files in System.IO.Directory.GetFiles and create layer for each file, then add them into map.

Wish that’s helpful.

Regards,

Ethan