GDAL读取属性乱码的终极解决方案(C#)
程序员文章站
2022-05-18 16:26:08
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);
-------------------------完--------------------------------
上一篇: 被空姐给涮了
下一篇: 酱牛肉减肥可以吃吗,酱牛肉热量有多高