wiki:DevWikiEmptyGeometry

Version 10 (modified by robe, 15 years ago) ( diff )

--

The semantics of NULL are well defined for us already in SQL standards. However, in the world of Geometry / Geography we have another entity which is not quite NULL nor quite fully defined: the empty geometry. Empty geometries can be created with things like intersection calls that have have no intersection, e.g. ST_Intersect('POINT(0 0)', 'POINT(1 1)') == POINT EMPTY. So, in the presence of empty, how should functions behave?

  • ST_Union(geometry, empty) == geometry
SQL Server 2008 geometry
   SELECT Geometry::STGeomFromText('POINT(1 2)',4326).STUnion(Geometry::STGeomFromText('POLYGON EMPTY',4326))
     => POINT (1 2)
   
SQL Server 2008 geography 
  SELECT (Geography::STGeomFromText('POINT(1 2)',4326).STUnion(Geography::STGeomFromText('POLYGON EMPTY',4326))).STAsText() 
    => POINT(1 2)

  • ST_Union(empty, empty) == empty
     SQL Server 2008 Geometry
       SELECT (Geometry::STGeomFromText('POLYGON EMPTY',4326).STUnion(Geometry::STGeomFromText('POLYGON EMPTY',4326))).STAsText() 
         => GEOMETRYCOLLECTION EMPTY
     SQL Server 2008 Geography
        SELECT (Geography::STGeomFromText('POLYGON EMPTY',4326).STUnion(Geography::STGeomFromText('POLYGON EMPTY',4326))).STAsText() 
          => GEOMETRYCOLLECTION EMPTY
       
    
  • ST_Difference(geometry, empty) == geometry
  • ST_Difference(empty, geometry) == empty
  • ST_Distance(geometry, empty) == NULL
  • ST_DWithin(geometry, empty, tolerance) == FALSE
  • ST_Contains(geometry, empty) == FALSE
SQL Server 2008 Geometry
SELECT (Geometry::STGeomFromText('POINT(1 3)',4326).STContains(Geometry::STGeomFromText('POLYGON EMPTY',4326))) 
  => 0
  • ??? ST_Contains(empty, empty) == FALSE
SQL Server 2008 Geometry
 SELECT (Geometry::STGeomFromText('POLYGON EMPTY',4326).STContains(Geometry::STGeomFromText('POLYGON EMPTY',4326)))
  => 0

  • ST_Intersects(geometry, empty) == FALSE
SQL Server 2008 Geometry
  SELECT (Geometry::STGeomFromText('POINT(1 3)',4326).STIntersects(Geometry::STGeomFromText('POLYGON EMPTY',4326))) 
  => 0
  • ??? ST_Intersects(empty, empty) == FALSE
    SQL Server 2008 Geometry
      SELECT (Geometry::STGeomFromText('POLYGON EMPTY',4326).STIntersects(Geometry::STGeomFromText('POLYGON EMPTY',4326))) 
        => 0
    
  • ??? ST_Disjoint(empty, empty) == FALSE
SQL Server 2008 Geometry
 SELECT (Geometry::STGeomFromText('POLYGON EMPTY',4326).STDisjoint(Geometry::STGeomFromText('POLYGON EMPTY',4326)))
  => 1
  • ??? ST_Disjoint(geometry, empty) == FALSE
    SQL Server 2008 Geometry
     SELECT (Geometry::STGeomFromText('POINT(1 3)',4326).STDisjoint(Geometry::STGeomFromText('POLYGON EMPTY',4326)))
      => 1
    
  • ST_IsSimple(empty) == TRUE
SQL Server 2008 Geometry
   SELECT Geometry::STGeomFromText('POLYGON EMPTY',4326).STIsSimple() 
     => 1
  • ST_IsValid(empty) == TRUE
SQL Server 2008 Geometry
  SELECT Geometry::STGeomFromText('POLYGON EMPTY',4326).STIsValid()
   => 1

Note: It might make sense to try to maintain the geometric truisms when specifying the semantics around empty - ie. things like:

  • intersects( A, B ) => !disjoint( A, B )
  • A == B => intersects( A, B )
  • contains( A, B ) && contains( B, A ) => A == B

If we don't maintain these we will probably need to complicate logical comparisons with special cases for empty - it may be the case that this is necessary, but it would be nice if it just 'came out in the wash'.

This suggests to me that perhaps:

  • ST_Intersects( empty, empty ) == TRUE
  • ST_Disjoint( empty, empty ) == FALSE
  • ST_Distance( empty, empty) == 0
  • ST_DWithin( empty, empty, tolerance) == true

Hmmm.. perhaps this isn't even possible generally, as:

  • intersects( A, B ) => intersection( A, B ) != empty

but I think that we certainly want:

  • intersection( empty, empty) == empty
Note: See TracWiki for help on using the wiki.