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
refmeans 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.
byteBufferis of type
Byte&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 actually
out byte byteBuffer. It being an
outparameter makes more sense than it being
ref, but the fact it's
bytemakes 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?