I am trying to write a C# program in the environment of VS2017, using .NET 4.6.1, and the library is MAPWINGIS 5.3. After saving a shapefile using the syntax sf.SafeAS(), I noticed that the encoding of this shapefile seen in QGIS is ISO 8859-1.
Because the strings within the file contain Traditional Chinese characters, I need to save the Shapefile file in UTF-8 encoding.
I found on the forum that encoding can be specified using GlobalSettings, but I cannot find the association between Shapefile and GlobalSettings in the examples. Could someone please tell me how to achieve this? thank you!
// point shapefile, has 2 fields and 5 instances
var sf = new Shapefile();
bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
// add field
int nameFieldIndex = sf.EditAddField("名稱", FieldType.STRING_FIELD, 15, 18);
int numFieldIndex = sf.EditAddField("點號", FieldType.STRING_FIELD, 15, 18);
Shape shp = new Shape();
shp.Create(ShpfileType.SHP_POINT);
// create random coordinates for 5 instances
for (int i = 0; i < 5; i++)
{
var pnt = new MapWinGIS.Point();
pnt.x = 121 + i * 2;
pnt.y = 23 + i * 2;
shp.InsertPoint(pnt, ref i);
sf.EditInsertShape(shp, ref i);
sf.EditCellValue(nameFieldIndex, i, "武嶺點"+ i );
sf.EditCellValue(numFieldIndex, i, "T0001");
}
sf.SaveAs(TextBox1.Text + @"\" + file.Name + ".shp",null);