<div>Hi All,</div><div> </div><div>Recently I am trying to write float type data into a raster using the function named WriteRaster in GDAL. However, I found that the data written into the image does not make sense.</div><div>
 </div><div>I tried to track down the issue from the very beginning, I found that the values predicted by the non-GDAL part are correct which ranges from 0.0 to 1000.0. However, the values written into the image seems not right. I "info"ed some pixels in ArcGIS, and found that some of the values are correct, but some are incredibly large (> 1,000,000,000) or -0.0. </div>
<div> </div><div>Beneath are the two function I created using C# to wrap up the create raster and write data to raster operations. Would you please review the code and let me know if you find anything wired? The dataType I passed in the following function is DataType.GDT_Float64. </div>
<div> </div><div>       /// <summary><br>        /// Function of CreateImage<br>        /// </summary><br>        /// <param name="width">the width of the image</param><br>        /// <param name="height">the height of the image</param><br>
        /// <param name="band">the band number of the image</param><br>        /// <param name="dataType">the dataType of the image</param><br>        /// <param name="fileName">the filepath of the image</param><br>
        /// <param name="Projection">the projection of the image</param><br>        /// <param name="geotrans">the extent of the image</param><br>        /// <returns>true if the file is created successfully, false otherwise</returns><br>
        public bool CreateImage(int width, int height, int band, OSGeo.GDAL.DataType dataType, string fileName, string Projection, double[] geotrans)<br>        {<br>            try<br>            {<br>                OSGeo.GDAL.Gdal.AllRegister();<br>
                OSGeo.GDAL.Driver poDriver = OSGeo.GDAL.Gdal.GetDriverByName("GTiff");<br>                if (System.IO.Path.GetExtension(fileName) == ".img")<br>                    poDriver = OSGeo.GDAL.Gdal.GetDriverByName("HFA");<br>
                OSGeo.GDAL.Dataset poDstDs = poDriver.Create(fileName, width, height, band, dataType, null);<br>                poDstDs.SetProjection(Projection);<br>                poDstDs.SetGeoTransform(geotrans);<br>                //****Added by ZLu on 08/03/2012****<br>
                poDstDs.Dispose();<br>                return true;<br>            }<br>            catch<br>            {<br>                return false;<br>            }<br>        }</div><div> </div><div>       /// <summary><br>
        /// Function of  WriteData2File<br>        /// </summary><br>        /// <param name="LCx">the column index of left corner</param><br>        /// <param name="LCy">the row index of left corner</param><br>
        /// <param name="width">the width of the rectangle</param><br>        /// <param name="height">the length of the rectangle</param><br>        /// <param name="fileName">the fileName where the data will be saved</param><br>
        /// <returns>true, if the data is added correctly, false otherwise.</returns><br>        public bool WriteData2File(int LCx, int LCy, int width, int height, int band, double[] Data, string fileName)<br>
        {<br>            OSGeo.GDAL.Driver imgDriver = OSGeo.GDAL.Gdal.GetDriverByName("GTiff");<br>            string extension = System.IO.Path.GetExtension(fileName);<br>            if (extension == ".img")<br>
                imgDriver = OSGeo.GDAL.Gdal.GetDriverByName("HFA");<br>            if (imgDriver == null)<br>                throw new Exception("The file type is not supported!");<br>            OSGeo.GDAL.Dataset ds = OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_Update);<br>
            int[] bandMap = new int[] { 1, 1, 1};<br>            try<br>            {<br>                ds.WriteRaster(LCx, LCy, width, height, Data, width, height, 1, bandMap, 1, 1, 1);<br>                //ds.WriteRaster(LCx, LCy, width, height, Data, width, height, band, 0, 0, 0);<br>
                ds.Dispose();<br>                return true;<br>            }<br>            catch<br>            {<br>                return false;<br>            }<br>        }</div><div> </div><div> </div><div>Thank you so much and wish you have a nice weekend.</div>
<div> </div><div>Zhenyu<br clear="all"><br>-- <br></div><div>Zhenyu Lu</div>
<div>SUNY-ESF</div><br>