Roy
Roy

Reputation: 1518

Is this SQL Server 2012 "exceeds single hemisphere" error actually an SRID error?

I'm trying to insert a polygon into a Geography type field in SQL Server 2012.

UPDATE tblProjects
SET tblProjects.Boundary = geography::STGeomFromText( 'POLYGON ((-93.30388806760311 27.994401411046173, -94.62224744260311 33.37641235124676, -79.70281384885311 31.80289258670676, -93.30388806760311 27.994401411046173))',4326)
WHERE tblProjects.ProjectID = 1;

I'm getting the following error despite the fact my polygon is in a single hemisphere:

Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
Microsoft.SqlServer.Types.GLArgumentException: 24205: The specified input does not represent a valid geography instance because it exceeds a single hemisphere. Each geography instance must fit inside a single hemisphere. A common reason for this error is that a polygon has the wrong ring orientation. To create a larger than hemisphere geography instance, upgrade the version of SQL Server and change the database compatibility level to at least 110.
Microsoft.SqlServer.Types.GLArgumentException: 
   at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoData& g, Double eccentricity, Boolean forceKatmai)
   at Microsoft.SqlServer.Types.SqlGeography.IsValidExpensive(Boolean forceKatmai)
   at Microsoft.SqlServer.Types.SqlGeography..ctor(GeoData g, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

enter image description here

I'm assuming this is an error associated with the Spatial Reference ID as the following returns NULL:

SELECT distinct Boundary.STSrid AS SRID
FROM dbo.tblProjects;

Am I correct in this assumption? How do I go about setting the SRID? My attempt returns an error:

UPDATE dbo.tblProjects
SET Boundary.STSrid = 4326;

Error:

Msg 5302, Level 16, State 1, Line 1
Mutator 'STSrid' on 'Boundary' cannot be called on a null value.

Upvotes: 1

Views: 1079

Answers (1)

Roy
Roy

Reputation: 1518

So it appears that the Ring Orientation is indeed the issue. Apparently the output from my web mapper had the vertices in the opposite order that SQL Server wants them in. I changed the order of the second and third vertices (this first and last are always identical to ensure the shape is a complete polygon) as suggested here and the UPDATE statement went through without any issue.

Now the fun part of figuring out how to solve this issue programmatically.

Upvotes: 2

Related Questions