0

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.

enter image description here

Do I need to do any projection here? enter image description 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();
Mohsen Sichani
  • 1,002
  • 12
  • 33
  • Thank you marc_c for making it better – Mohsen Sichani Jul 20 '17 at 09:55
  • Does any body know why this question has been replicated in http://answers.elteacher.info/questions/post/1927508/report-builder-and-ssrs-error-the-bing-map-layer-cannot-be-display-because-the-coordinate-system-of-the-viewport-is-set-to-planar-ask-question.html What is the relation between Stackoverflow and elteacher? I never posted this question elsewhere! – Mohsen Sichani Jul 20 '17 at 10:30
  • 1
    Based on the error message, I'd say it's having a problem because you're storing your data as geometry instead of geography. – Ben Thul Jul 20 '17 at 14:16
  • Not sure if I can convert polygons as Geography, but will try it – Mohsen Sichani Jul 20 '17 at 18:48
  • Added more info @BenThul in the question – Mohsen Sichani Jul 20 '17 at 20:18
  • Can you post an example of one of your polygons? In order to render a map, the polygon is going to have to conform to the normal rules for latitude and longitude. The error you've posted suggests that at least one of them doesn't conform. – Ben Thul Jul 20 '17 at 20:21
  • Thank you Ben. Added to the question. Yes, values are not in the range, but these data work very well with Geoserver, Leaflet, ArcGis, and other Geospatial tools – Mohsen Sichani Jul 20 '17 at 20:26
  • 1
    And you're able to display those points on a map in those tools? I'm genuinely curious how it would be able to do that if the latitude is not in the range of [-90, 90]. – Ben Thul Jul 20 '17 at 20:44
  • Yes, 100 percent. Please refer to my earlier question available at https://gis.stackexchange.com/questions/244725/show-google-coordinates-in-leaflet-with-wms-geoserver It is done by defining a bbox – Mohsen Sichani Jul 20 '17 at 20:49
  • @BenThul, Things are getting clearer now with the qestions you are asking:). For showing the results on google map , I wrote this code https://stackoverflow.com/questions/44556520/change-projection-in-mssql-for-web-mapping-leaflet-openlayer-openstreetmaps-g/44577666#44577666 to enable the transformation,! Sql Server cannot do the projection alone, So I need to convert these polygons to lat/lng by an external library. If this is the case, Are you aware of any faster approach? – Mohsen Sichani Jul 20 '17 at 21:19

0 Answers0