Monday, April 1, 2013

Union on two normal geometries could cause exception of invalid geometry

set @a = geometry::STGeomFromText('POLYGON ((-82.169222373340745 36.313505017518764, -82.1689948301937 36.313636231730925, -82.169144694926217 36.313896117397235, -82.169118706369773 36.313911103876308, -82.169136897806311 36.313934959107428, -82.168898345553316 36.314116873414605, -82.168906538223382 36.314127616860787, -82.169145090476377 36.31394570255361, -82.169163281912915 36.313969557770179, -82.169180794822751 36.313993915478932, -82.16893721773522 36.314169044577284, -82.168944722216111 36.314179482113104, -82.169188299303642 36.314004353014752, -82.169205812213477 36.314028710723505, -82.16922261781292 36.314053561727633, -82.168974107858958 36.314221617678413, -82.168982719915221 36.31423435259785, -82.169231229840079 36.31406629664707, -82.169248035439523 36.314091147636645, -82.169264097610721 36.314116485489649, -82.169010719168 36.314277107259841, -82.169018743181368 36.314289765025023, -82.1692721216532 36.31412914324028, -82.169288183824392 36.314154481093283, -82.169303491538884 36.314180281754275, -82.169045484974049 36.314333358881413, -82.16905147532816 36.314343455422204, -82.169309481889215 36.314190378297312, -82.1693247896037 36.314216178958304, -82.169354020094033 36.314268577232724, -82.169435400719522 36.3144245105068, -82.169937897386262 36.314055754584842, -82.16939822662971 36.313749916720553, -82.169380749954144 36.31375999476586, -82.1693754500593 36.3137530447857, -82.169368469505571 36.313758367992705, -82.169222373340745 36.313505017518764))',4269);
set @b = geometry::STGeomFromText('POLYGON ((-82.1690774135017 36.3143885305297, -82.1690774135047 36.314388530535,-82.169601396196 36.3140962256613,-82.169601396196 36.3140962256613,-82.1690774135017 36.3143885305297))',4269);

The first polygon looks like
clip_image002
The second polygon looks like
clip_image004
If conducting the union operation:

Select @a.STUnion(@b);

Here is the error message:

A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":
System.ArgumentException: 24144: This operation cannot be completed because the instance is not valid. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a geometry instance to shift slightly.
System.ArgumentException:
   at Microsoft.SqlServer.Types.SqlGeometry.ThrowIfInvalid()
   at Microsoft.SqlServer.Types.SqlGeometry.STUnion(SqlGeometry other)

No comments:

Post a Comment