[postgis-devel] Should EMPTY be spatially equal to self ?

Mateusz Loskot mateusz at loskot.net
Tue Jan 17 02:18:21 PST 2012


On 17 January 2012 09:15, Paragon Corporation <lr at pcorp.us> wrote:
>
> I think the best way to resolve this is ot just do what the other spatial
> databases do assuming they all do the same.
> Just need some people to test SQL Server and Oracle.

I've done quick test using SQL Server types in CLR,
which gives EMPTY != EMPTY for all types.
The test is available here https://gist.github.com/1609500
also attached.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
-------------- next part --------------
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


More information about the postgis-devel mailing list