Opened 9 years ago

Closed 5 years ago

#6168 closed defect (wontfix)

GDAL Raster Attribute Table: GDALRATSetValueAsString() how to save Chinese characters (c#)?

Reported by: Drasius Owned by: tamas
Priority: normal Milestone: closed_because_of_github_migration
Component: CSharpBindings Version: 1.11.1
Severity: normal Keywords: c#, RAT, GDAL, GDALRATSetValueAsString
Cc: tamas


I need help with GDAL. The string value with Chinese symbols is not readed/saved correctly (C#).

For SAVING grid value we using:

private static extern void GDALRATSetValueAsString(IntPtr handle, int row, int field, [In][MarshalAs(UnmanagedType.LPStr)] string value);

method (c#) to save string value, it seems that this method saves string as ANSI string.


private static extern IntPtr GDALRATGetValueAsString(IntPtr handle, int row, int field);

In. Example my string "银行Flamwood C2" There is for methods to get value by pointer (use in GDALRATGetValueAsString metho):

var pointer = GDALRATGetValueAsString(GDALRasterAttributeTableH, row, field);

a) var b = Marshal.PtrToStringUni(pointer); value: "㼿汆浡潷摯䌠2"

b) var a = Marshal.PtrToStringAnsi(pointer); value: "??Flamwood C2"

c) var c = Marshal.PtrToStringAuto(pointer); value: "㼿汆浡潷摯䌠2"

d) var d = Marshal.PtrToStringBSTR(pointer); Throws an error out of memory.

Q: So how I can get Unicode string with was saved (so I can get using this Marshal.PtrToStringUni(pointer)) or most likely how to save the Unicode string to GDALRAT (GDAL RAT - GDAL Raster Attribute Table)?

GDAL version: 1.11.1

I tried to set CharSet = CharSet.Unicode but id does not helped, still get not correct string:

[DllImport(GdalWrapper.GdalDLL, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)] 
private static extern void GDALRATSetValueAsString(IntPtr handle, int row, int field, [In][MarshalAs(UnmanagedType.LPStr)] string value);

Also you can find this question in

Change History (4)

comment:1 by Jukka Rahkonen, 9 years ago

You should send your question to gdal-dev mailing list first instead of creating a bug report. Mailing list has also more readers. When it comes to your issue, unfortunately I can't help but let's hope someone else can.

comment:2 by Even Rouault, 9 years ago

Cc: tamas added
Component: GDAL_RasterCSharpBindings
Owner: changed from warmerdam to tamas

comment:4 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to if it is not already reported there.

Note: See TracTickets for help on using tickets.