GDAL读取属性乱码的终极解决方案(C#)
程序员文章站
2022-12-09 23:38:27
OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "");OSGeo.GDAL.Gdal.AllRegister();OS... ......
osgeo.gdal.gdal.setconfigoption("gdal_filename_is_utf8", "yes"); osgeo.gdal.gdal.setconfigoption("shape_encoding", ""); osgeo.gdal.gdal.allregister(); osgeo.ogr.ogr.registerall();
[dllimport("gdal300.dll", entrypoint = "ogr_f_getfieldasstring", callingconvention = callingconvention.cdecl)] public extern static system.intptr ogr_f_getfieldasstring(handleref handle, int index); [dllimport("gdal300.dll", entrypoint = "ogr_f_getfieldasbinary", callingconvention = callingconvention.cdecl)] public extern static system.intptr ogr_f_getfieldasbinary(handleref handle, int index, out int bytecount);
string fieldname = pfielddefn.getname(); int fieldindex = pfeaturedefn.getfieldindex(fieldname); //intptr pintptr = ogr_f_getfieldasstring(osgeo.ogr.feature.getcptr(pfeature), fieldindex); int bytecount =0; //intptr a = count; intptr pintptr = ogr_f_getfieldasbinary(osgeo.ogr.feature.getcptr(pfeature), fieldindex, out bytecount); byte[] bytearray = new byte[bytecount]; marshal.copy(pintptr,bytearray, 0, bytecount); console.writeline(bytecount); // marshal.ptrtostringansi(pintptr) // console.writeline(pfeature.getfieldasstring(i)); string str = system.text.encoding.default.getstring(bytearray); // utf8encoding utf8 = new utf8encoding();
// string str = utf8.getstring(bytearray); console.writeline(str);
-------------------------完--------------------------------
上一篇: 女人也是如此
下一篇: 基于C# 调用百度AI 人脸识别