Search

SqlGeometry reports invalid type of WKB of POINT EMPTY by mloskot

Closed
as Won't Fix Help for as Won't Fix

1
0
Sign in
to vote
Type: Bug
ID: 537018
Opened: 2/26/2010 1:53:43 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
I inspect Well-Knon-Binary output returned by SqlGeometry.STAsBinary() method for EMPTY geometries of all the 7 geometry types as specified in OGC SFS.

WKB of EMPTY geometry for all types is reported as binary stream truncated to 9 bytes with first byte indicating endianness and the next four bytes indicating geometry type. It is exactly as defined by OGC. The remaining four bytes are set to Zero and seem to play role of a size specifier: number of points in LINESTRING or number of rings in POLYGON, etc. This form of WKB for EMPTY seems to be a convention pretty much specific to SQL Server, though it seems to be working well.

However there probably is a bug as for POINT EMPTY geometry the WKB stream consists of invalid value of type. It is 4 which denotes MULTIPOINT. It means, POINT EMPTY is implicitly translated to MULTIPOINT.

I use Microsoft SQL Server System CLR Types from Microsoft SQL Server 2008 Feature Pack, August 2008 (not Feb 2007 as selected in Version, but the one I use is missing form the list) with Visual Studio 2008. The same behaviour can be observed with the SQL Server CLR Types and Visual Studio 2010.
Details (expand)
Product Language
English

Version

SQL Server Feature Pack Feb 2007

Category

Tools (SSMS, Agent, Profiler, Migration, etc.)

Operating System

Windows 7 Professional
Operating System Language
English
Steps to Reproduce
Here is a simple test program which dumps empty geometries of all types in both WKT and WKB form:

foreach (string type in Enum.GetNames(typeof(OpenGisGeometryType)))
{
string wkt = type.ToUpper() + " EMPTY";
SqlGeometry geom = SqlGeometry.Parse(wkt);
byte[] wkb = geom.STAsBinary().Buffer;
string wkbhex = string.Join("", wkb.Select(b => b.ToString("X2")).ToArray());

Console.WriteLine("{0}\n{1} ({2} bytes)\n", wkt, wkbhex, wkb.Length);
}
Actual Results
Here is output of the test program:

POINT EMPTY
010400000000000000 (9 bytes)

LINESTRING EMPTY
010200000000000000 (9 bytes)

POLYGON EMPTY
010300000000000000 (9 bytes)

MULTIPOINT EMPTY
010400000000000000 (9 bytes)

MULTILINESTRING EMPTY
010500000000000000 (9 bytes)

MULTIPOLYGON EMPTY
010600000000000000 (9 bytes)

GEOMETRYCOLLECTION EMPTY
010700000000000000 (9 bytes)
Expected Results
I would expect that POINT EMPTY is reported as follows:

POINT EMPTY
010100000000000000 (9 bytes)

However, it could potentially cause serious security issues for programming languages like C or C++. Alternatively, EMPTY geometries of all types should be reported in unified form as let's say GEOMETRYCOLLECTION: 010700000000000000

Currently, some types are being casted to other types, but some types are preserved, it makes the behaviour inconsistent. The WKB:010700000000000000 for empty geometries of all types would be the most consistent approach.

Platform

X64
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 10/11/2011 at 4:19 PM
Thank you for your suggestion. Our development team for the spatial data types tells me that it is not possible to use a single value for the WKB format of any spatial data type.

For the POINT EMPTY, the WKB format does not allow empty points, so we are outputting a MULTIPOINT with zero elements.

In a MULTIPOINT EMPTY, we are stripping out empty points.

The other types likewise return empty elements.

We appreciate your feedback.
Posted by Microsoft on 4/9/2010 at 9:13 AM
Thanks for providing feedback.

This is known issue, we wanted to preserve as much data as possible for round-tripping. But we might consider changing it to get consistent behavior.
Sign in to post a workaround.