ArcObjects provides an interface named IWkb
for obtaining a WKB representation of a geometry. Generally, you can cast a geometry object to it:
// WKB representation of POLYGON((0 0,1 0,1 1,0 1,0 0))
byte[] wkb = Convert.FromBase64String("AQMAAAABAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAAAAAAAAAAAAAAAA");
IGeometry g;
int bytesRead;
IGeometryFactory factory = new GeometryEnvironmentClass(wkb, out g, out bytesRead);
System.Diagnostics.Debug.WriteLine(g);
// Output: System.__ComObject
System.Diagnostics.Debug.WriteLine((IWkb)g);
// Output: System.__ComObject
System.Diagnostics.Debug.WriteLine("Yes, the cast is valid");
// Just verifies we got past the cast without error.
However, the signature of IWkb.ExportToWkb
doesn't seem to make sense. The docs show takes two parameters:
ref int byteCountInOut
ref Byte& byteBuffer
There are three things that don't make any sense:
- I know
ref
means that it takes an incoming value and might modify that value to also use for output, but sending input for these variables doesn't make sense; I'm trying to get output from them. byteBuffer
is of typeByte&
according to the docs, but that trailing&
doesn't appear to be valid C# syntax.- When I look at the generated metadata for the method in Visual Studio, it shows that
byteBuffer
's declaration is actuallyout byte byteBuffer
. It being anout
parameter makes more sense than it beingref
, but the fact it'sbyte
makes even less sense. A WKB consists of many bytes, so it needs to be some data type that allows for that.
How is this method supposed to be used? Do I need to use some kind of loop to get one byte at a time; if so, how? Is there a better interface for getting the WKB form of a geometry?