GDAL Android库,创建shp,如果字段属性需要中文,网上的解决方法都是
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8");
测试发现,没有作用。
public void SetField(int id, String value) { ogrJNI.Feature_SetField__SWIG_0(this.swigCPtr, this, id, value); } public void SetField(String name, String value) { ogrJNI.Feature_SetField__SWIG_1(this.swigCPtr, this, name, value); }
为什么会乱码,编码不对。
如果直接使用SetField没几个能对得,所以转换思路,从编码方式入手。
解决思路——>SetFieldBinaryFromHexString
Feature.SetFieldBinaryFromHexString(1,Until.str2HexStr("测试","GBK"));
new String(oFeature.GetFieldAsBinary(iField),"GBK") ;
以下是所有用到的方法
1.这两句加上,不然不能用中文路径
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8");
2.String