ThinkGeo.com    |     Documentation    |     Premium Support

Projecting TIFF

Hey,

I have some troubles assigning projection converter to GeoTiffRasterLayer. Please see the following code:

var layer = new GeoTiffRasterLayer("UQ5111R_RVK_1.tif", "UQ5111R_RVK_1.tfw");

var converter = new ProjectionConverter(3067, 3857);
converter.Open();

layer.ImageSource.ProjectionConverter = converter;

return layer;

If I leave the converter out raster is displayed on the map. When converter is as it is, map view shows the following error message:

This function relies on ThinkGeo.UnmanagedProj.nupkg. Please install this package first. Or this function is not supported on current platform.

But I think I have that and maybe some unnecessary dependencies, too (Win10, VS2017, .NET Framework 4.8)

deps

TIF and TFW files can be found zipped here https://drive.google.com/file/d/1QbbLKLvEaQPuTvg58NqIHl4BJ1AURL09/view?usp=sharing

Versions I’m having (x64)

ThinkGeo.Core.13.0.0-beta219
ThinkGeo.Dependency.Gdal.12.2.5
ThinkGeo.Gdal.13.0.0-beta213
ThinkGeo.UI.Wpf.13.0.0-beta250
ThinkGeo.UnmanagedGeoTiff.13.0.0-beta211
ThinkGeo.UnmanagedProj.13.0.0-beta209

Thanks Mikko,
Your code looks good. Just one line need change

var converter = new UnmanagedProjectionConverter(3067, 3857);

Thanks

Frank

Hey Frank,

I do not understand what is the difference between ProjectionConverter and UnmanagedProjectionConverter. Even so, changing to unmanaged as suggested throws error upon instantiation.

TypeInitializationException
The type initializer for ThinkGeo.Core.UnmanagedProjectionConverter threw an exception
at ThinkGeo.Core.UnmanagedProjectionConverter..ctor(Int32 internalSrid, Int32 externalSrid)

Also, when trying to open a TAB files like so (that works perfectly fine in QGIS)

var layer = new TabFeatureLayer("some.tab", FileAccess.Read)
{
    DrawingQuality = DrawingQuality.Default,
    RequireIndex = false
};

I’ll always end up with map drawn exception of “The TAB file(s) can not be read due to an unsupported format”.

Also, any way to open MIF files? I have tried to open files using OgrFeatureLayer but using the following

var layer = new OgrFeatureLayer(filePath, @"ID")

Always gives drawn error that I should get “MapSuiteDependency-Fdo” in order to use this. But again, I think I have that :frowning:

ogr

Thanks
For the raster image file such as geotif. We have to use UnmanagedProjectionConverter. Here is the the sample code to re-project geotiff.

private void MapView_Loaded(object sender, RoutedEventArgs e)
{
// It is important to set the map unit first to either feet, meters or decimal degrees.
mapView.MapUnit = GeographyUnit.Meter;

        // Create a new overlay that will hold our new layer and add it to the map.
        LayerOverlay layerOverlay = new LayerOverlay();
        mapView.Overlays.Add(layerOverlay);

        // Create the new layer and dd the layer to the overlay we created earlier.
        GeoTiffRasterLayer geoTiffRasterLayer = new GeoTiffRasterLayer(@"C:\Users\FrankFu\Downloads\RVK_1.tif", @"C:\Users\FrankFu\Downloads\R_RVK_1.tfw");
        layerOverlay.Layers.Add(geoTiffRasterLayer);
        geoTiffRasterLayer.Open();

        var converter = new UnmanagedProjectionConverter(3067, 3857);
        converter.Open();

        geoTiffRasterLayer.ImageSource.ProjectionConverter = converter;


       
        // Set the map view current extent to a slightly zoomed in area of the image.
        mapView.CurrentExtent = geoTiffRasterLayer.GetBoundingBox();

        // Refresh the map.
        mapView.Refresh();
    }

For the TAB file. Could you send a sample file to support@thinkgeo.com. We could look into more detail.

Thanks

Frank

Thanks Frank,

Still this line here

Throws that type initializer exception. I’ll put up a sample project to verify this.

Edit: Of course the sample I made works just fine. I made sure I have same (and no unnecessary) dependencies in my actual project and in sample. But for some reason only sqlite dll from win-x64/native directory is included in the build/bin folders. So maybe it’s just something wrong how my solution is set up :frowning: .

Also whole “gdaldata” folder is missing from bin.

I have sent the TAB file to your support email.

Thanks Mikko,
You need use the NuGet manager to add ThinkGeo library. It will auto copy the dependency files to the target folder. Otherwise you may miss some dlls.

I can reproduce the tab file not support issue. We are looking into it.

Thanks

Frank

Thanks Mikko,
We have fixed the tab data load issue. Could you get the latest mapsuite v12 beta version and try again.

Thanks

Frank

Thanks Frank,

That was super fast and now TAB file seems to open just fine! One problem remains, it does not follow default styles set for the layer (I have set points/lines/areas all to red). Same features as Shape appears red.

Do you have anything to share on when GeoPDF support will be added. Last time I emailed support about it it was planned for H1. Also, any near future plans for KML and MapInfo MIF?

Thanks Mikko,
The style works good for me . I modified the how do I sample.

   private void MapView_Loaded(object sender, RoutedEventArgs e)
        {
            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.Meter;

            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service and add it to the map.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);
            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Create a new overlay that will hold our new layer and add it to the map.
            LayerOverlay cityboundaryOverlay = new LayerOverlay();
            mapView.Overlays.Add(cityboundaryOverlay);

            // Create the new layer and set the projection as the data is in srid 2276 and our background is srid 3857 (spherical mercator).
            TabFeatureLayer cityBoundaryLayer = new TabFeatureLayer(@"E:\Tickets\Mikko\ok-tab\ok-tab.tab");
            TabFeatureLayer.BuildIndexFile(cityBoundaryLayer.TabPathFilename, BuildIndexMode.DoNotRebuild);
            cityBoundaryLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(3067, 3857);

            // Add the layer to the overlay we created earlier.
            cityboundaryOverlay.Layers.Add("City Boundary", cityBoundaryLayer);

            // Set this so we can use our own styles as opposed to the styles in the file.
            cityBoundaryLayer.StylingType = TabStylingType.StandardStyling;

            // Create an Area style on zoom level 1 and then apply it to all zoom levels up to 20.
            cityBoundaryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColors.Red,3, true);
            cityBoundaryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Open the layer and set the map view current extent to the bounding box of the layer.  
            cityBoundaryLayer.Open();
            mapView.CurrentExtent = cityBoundaryLayer.GetBoundingBox();

            // Refresh the map.
            mapView.Refresh();
        }

We are working on the GeoPDF and KML layer. We don’t have the near future plan for the MIF so far. I will talk with product team see if we will support MIF near future.

Thanks

Frank

Thanks for the example, I didn’t even know to look for “StylingType” property. Good to know about upcoming format support, too!

Yet another question. Some time ago you made a change so that layer’s projection property (for at least shape files) will be populated once the layer is opened. This helped us set up the projection converters.

Is this the case with all layer types, like rasters and tabs?

This only for the files which allow specify the projection file such as shape file. You can specify a prj file to it. Some raster also allow you specify the projection file. But the tab file not allow specify the projection file. So for the Tab file you need need manual set cityBoundaryLayer.Projection = ???

Thanks

Frank