I have some data in my SQL Server 2012 database which are stored as Geometry with SRID 3857. I can see the spatial result without any problem in the SQL Server Spatial Result tab, but when I try to show my polygons on the bing map as a report, I get the following error and could not find any similar problem on the web. It would be great if anybody can advise.
Do I need to do any projection here?
I can see the Geography option is available but it is not easy to convert geometry to geography as I get the following error when I followed this approach:
(1 row(s) affected)
Msg 6522, Level 16, State 1, Line 8
A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
My code
DECLARE @geog GEOGRAPHY;
DECLARE @geom GEOMETRY;
SET @geom = GEOMETRY::STGeomFromText('POLYGON ((19445540.829353392 -4426302.2038580161, 19445501.954769585 -4426286.5532862339, 19445502.954769585 -4426287.5532862339, 19445540.829353392 -4426302.2038580161))', 3857);
SET @geom = @geom.MakeValid() --Force to valid geometry
SET @geom = @geom.STUnion(@geom.STStartPoint()); --Forces the correct the
geometry ring orientation
select @geom
SET @geog = GEOGRAPHY::STGeomFromText(@geom.STAsText(),3857)
SELECT @geog.STArea();