当前位置: 移动技术网 > IT编程>开发语言>.net > GDAL读取属性乱码的终极解决方案(C#)

GDAL读取属性乱码的终极解决方案(C#)

2019年07月22日  | 移动技术网IT编程  | 我要评论

幕后总裁好孕妈咪,色一休,法式双叠衬衫


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);



-------------------------完--------------------------------

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网