Skip to content

Instantly share code, notes, and snippets.

@mloskot
Created January 14, 2012 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloskot/1609500 to your computer and use it in GitHub Desktop.
Save mloskot/1609500 to your computer and use it in GitHub Desktop.
Check equality of EMPTY geometries using SqlGeometry from SQL Server CLR Types
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SqlServer.Types;
namespace csharp
{
class Program
{
static void Main(string[] args)
{
foreach (string type in
Enum.GetNames(typeof(OpenGisGeometryType)))
{
string wkt = type.ToUpper() + " EMPTY";
SqlGeometry geom1 = SqlGeometry.Parse(wkt);
SqlGeometry geom2 = SqlGeometry.Parse(wkt);
byte[] wkb1 = geom1.STAsBinary().Buffer;
string wkbhex1 = string.Join("", wkb1.Select(b => b.ToString("X2")).ToArray());
byte[] wkb2 = geom2.STAsBinary().Buffer;
string wkbhex2 = string.Join("", wkb2.Select(b => b.ToString("X2")).ToArray());
bool b1 = geom1.Equals(geom2);
bool b2 = geom2.Equals(geom1);
Console.WriteLine("{0} => {1}.Equals({2}) == {3}", wkt, wkbhex1, wkbhex2, b1);
Console.WriteLine("{0} => {1}.Equals({2}) == {3}\n", wkt, wkbhex2, wkbhex1, b2);
}
}
}
}
#if OUTPUT
POINT EMPTY => 010400000000000000.Equals(010400000000000000) == False
POINT EMPTY => 010400000000000000.Equals(010400000000000000) == False
LINESTRING EMPTY => 010200000000000000.Equals(010200000000000000) == False
LINESTRING EMPTY => 010200000000000000.Equals(010200000000000000) == False
POLYGON EMPTY => 010300000000000000.Equals(010300000000000000) == False
POLYGON EMPTY => 010300000000000000.Equals(010300000000000000) == False
MULTIPOINT EMPTY => 010400000000000000.Equals(010400000000000000) == False
MULTIPOINT EMPTY => 010400000000000000.Equals(010400000000000000) == False
MULTILINESTRING EMPTY => 010500000000000000.Equals(010500000000000000) == False
MULTILINESTRING EMPTY => 010500000000000000.Equals(010500000000000000) == False
MULTIPOLYGON EMPTY => 010600000000000000.Equals(010600000000000000) == False
MULTIPOLYGON EMPTY => 010600000000000000.Equals(010600000000000000) == False
GEOMETRYCOLLECTION EMPTY => 010700000000000000.Equals(010700000000000000) == False
GEOMETRYCOLLECTION EMPTY => 010700000000000000.Equals(010700000000000000) == False
CIRCULARSTRING EMPTY => 010800000000000000.Equals(010800000000000000) == False
CIRCULARSTRING EMPTY => 010800000000000000.Equals(010800000000000000) == False
COMPOUNDCURVE EMPTY => 010900000000000000.Equals(010900000000000000) == False
COMPOUNDCURVE EMPTY => 010900000000000000.Equals(010900000000000000) == False
CURVEPOLYGON EMPTY => 010A00000000000000.Equals(010A00000000000000) == False
CURVEPOLYGON EMPTY => 010A00000000000000.Equals(010A00000000000000) == False
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment