0

Whenever I am loading the chart into mapinfo using MapXtreme the basemap is getting converted. Because of which the chart is not coming in the right place. Can you please check my code what I am doing wrong.

            Bitmap bmp = CreateChartTIF(path);

            GdalConfiguration.TryConfiguration();


            String wktProj = null;
            String tmpPath = @"E:\@@MapInfo_1\tmp.bmp";
            int a = Convert.ToInt16(rectBounds.Left);
            int b = Convert.ToInt16(rectBounds.Top);

            bmp.Save(tmpPath, ImageFormat.Bmp);
            System.IO.MemoryStream mem = new System.IO.MemoryStream();
            mem.Flush();

            String[] options = null;
            Gdal.AllRegister();
            OSGeo.GDAL.Driver srcDrv = Gdal.GetDriverByName("GTiff");
            Dataset srcDs = Gdal.Open(tmpPath, Access.GA_ReadOnly);
            Dataset dstDs = srcDrv.CreateCopy(@"E:\@@MapInfo_1\Output\2-0.tif", srcDs, 0, options, null, null);

            Osr.GetWellKnownGeogCSAsWKT("WGS84", out wktProj);
            dstDs.SetProjection(wktProj);

            double minx = rectBounds.Left;
            double miny = rectBounds.Bottom;


            double maxx = rectBounds.Right;
            double maxy = rectBounds.Top;


            double mapWidth = Math.Abs(minx - maxx);
            double mapHeight = Math.Abs(maxy - miny);

            double pixel1 = mapWidth / bmp.Width;
            double pixel2 = mapHeight / bmp.Height;



            //Top Left x, w-r pixel resln, 0, Top Letf y, 0, n-s pixel resln
            double[] geoTransfo = new double[] { minx, pixel1, 0, maxy, 0, pixel2 * (-1) };
            //double[] geoTransfo = new double[] { minx, mapWidth / bmp.Width, 0, maxy, 0, (mapHeight / bmp.Height) * (-1) };

            dstDs.SetGeoTransform(geoTransfo);

            dstDs.FlushCache();
            dstDs.Dispose();
            srcDs.Dispose();
            srcDrv.Dispose();
            bmp.Dispose();

            RasterProcessing.Convert(@"E:\@@MapInfo_1\Output\2-0.tif", "E:\\@@MapInfo_1\\Jonathan_Test.tif", "MI_GeoTiff_IMG");

            // File.Delete(tmpPath);
            string get1 = @"E:\@@MapInfo_1\Jonathan_Test.TAB";
            MapBasic.CallMapBasicSubroutine("CustomHandler", get1);

The screenshot of my result as :

Screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.