According to specification WKB format, each polygon in multipolygon has its endiannes and object type (polygon), but the implementation of WkbReader seems to ignore this fact. It assumes these two fields does not exist and reads number of rings straight away, so actual polygon data is garbage (ring count, coordinates...)
This quick test seems to fix the issue (and I guess there could also be a problem with other multi* objects):
private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions)
{
var pointsCount = (int)reader.ReadUInt32();
var polygons = new List();
for (var i = 0; i < pointsCount; i++)
{
reader.ReadBytes(1); // dump byteOrder from stream
reader.ReadUInt32(); // dump wkbType from stream
polygons.Add(ReadPolygon(reader, dimensions));
}
return new MultiPolygon(polygons);
}
According to specification WKB format, each polygon in multipolygon has its endiannes and object type (polygon), but the implementation of WkbReader seems to ignore this fact. It assumes these two fields does not exist and reads number of rings straight away, so actual polygon data is garbage (ring count, coordinates...)
http://edndoc.esri.com/arcsde/9.0/general_topics/wkb_representation.htm
WKBPolygon { byte byteOrder; uint32 wkbType; // 3 uint32 numRings; LinearRing rings[numRings]; }
wkbMultiPolygon {
byte byteOrder;
uint32 wkbType; // 6 uint32 num_wkbPolygons; WKBPolygon wkbPolygons[num_wkbPolygons]; }
I'm using data from here http://www.naturalearthdata.com/downloads/ (SQLite database)
This quick test seems to fix the issue (and I guess there could also be a problem with other multi* objects):
private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions) { var pointsCount = (int)reader.ReadUInt32(); var polygons = new List();
for (var i = 0; i < pointsCount; i++)
{
reader.ReadBytes(1); // dump byteOrder from stream
reader.ReadUInt32(); // dump wkbType from stream
polygons.Add(ReadPolygon(reader, dimensions));
}
return new MultiPolygon(polygons);
}
Thanks!
Regards, Mladen