Centre latitude & longitude of a geography polygon region in sql server
geospatial, sql, sql-server
Solution
You can use the `EnvelopeCenter()` method of the `geography` type.
DECLARE @polyString as varchar(max);
SET @polyString = 'POLYGON((' + @eastAsString + ' ' + @northAsString +',' + @westAsString + ' ' + @northAsString + ',' + @westAsString + ' '+@southAsString +','+ @eastAsString + ' ' + @southAsString +',' +@eastAsString +' ' +@northAsString +'))';
DECLARE @g geography;
SET @g = geography::STPolyFromText(@polyString, 4326)
SELECT @g.EnvelopeCenter().ToString()
It would be helpful to define what exactly you mean by center of the polygon, because there are different ways of defining it.
Problem
I have a geographic polygon created as follows ``` DECLARE @polyString as varchar(max); SET @polyString = 'POLYGON((' + @eastAsString + ' ' + @northAsString +',' + @westAsString + ' ' + @northAsString + ',' + @westAsString + ' '+@southAsString +','+ @eastAsString + ' ' + @southAsString +',' +@eastAsString +' ' +@northAsString +'))'; DECLARE @g geography; SET @g = geography::STPolyFromText(@polyString, 4326) ``` I would like to find the centre lat/long of the polygon? Is this possible inside sql server?