Yesterday's blog used the gdal and OGR libraries to write a small demo of reading images and vectors with C. I forgot to test the Chinese path. I tested it today and found that the Chinese path is not supported. As shown in:
This problem is very strange. In my self-compiled gdal library, I have modified the gdal source code and set utf8 to No. How can this problem still occur? In order to verify that my gdallibrary does not support Chinese characters, use the gdalinfo.exetool to perform the verification. In the command line, enter gdalinfo.exe F: \ data \ testdata \ 6-image mosaic \ PS mosaic. IMG ", and then press enter to find that the image information is normally read, as shown in, it seems that the problem is not in the gdal library, it is estimated that the default encoding of C # is caused.
Next, let's look at the C # source code encoding. After finding a lot of code and converting the file name to utf8, the result is still not good. I wrote the conversion function myself (of course, I found a lot of information to write it out, C # cainiao ). I don't know if the code is posted, right:
private string ConvertString2UTF8(string strSrc) { string strTemp = strSrc; byte[] utf8bytes = System.Text.Encoding.Default.GetBytes(strTemp); byte[] utf8bytes2 = System.Text.Encoding.Convert(System.Text.Encoding.Default, System.Text.Encoding.UTF8, utf8bytes); strTemp = System.Text.Encoding.Default.GetString(utf8bytes2); return strTemp; }
If it turns around, it still doesn't work. This is depressing. Then check the C # source code of the default save encoding, found that is the UTF-8 code (view the source code, you can in Vs, open the source code first, then there is an advanced save option under the File menu. Click it to view the current encoding or modify the current encoding ), is C # The default file name obtained is the UTF-8 encoding? Therefore, a gdal. setconfigoption ("gdal_filename_is_utf8 ",
"Yes"); [Note: When compiling gdal, I set the attribute of gdal_filename_is_utf8 to No. To keep the original format, set it to yes later, I feel that all of my previous work is in vain... ...]. Okay, save, compile, run, and complete. The Chinese path is finally recognized ...... Screenshot ...... Tears and tears ......
Test another Vector file to see if it is correct, as shown below:
Through the above verification, is it possible to think so, C # encoding is the default UTF-8, so when using gdal, do not need to modify the original code can be used !? Although this view does not have enough evidence to prove that it is correct, it provides a little idea to open the Chinese path using gdal. Hope to help you.