创建椭圆地理表示
Create Ellipse Geography Representation
我希望在 SQL Server 2008 R2 中创建一个表示椭圆的空间对象。
我有点坐标、最小值和长轴值。
我能找到的最接近的内置函数是 STBuffer,它在该点周围创建了一个缓冲半径,例如:
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.360 47.656)', 4326);
SELECT @g.STBuffer(5);
我错过了什么吗?这看起来很基本。
我真的不想创建一组多边形坐标来表示这个形状 - 这看起来太过分了。
提前致谢。
这是不可能的。我通过在 C# 中创建 WKT Polygon 字符串表示形式解决了这个问题。
公式总结如下:
var step = 2*Math.PI/40; // creates 40 points (1 for each "step")
var radians = 5.868;
var semiMajMetres = 400;
var semiMinMetres = 200;
var latMetres = latVal*110575; // converts degree value to metres value
var lonMetres = lonVal*111303; // assumes you have variables with these known values
for(double theta = 0; theta <= 2 * Math.PI; theta += step)
{
var lon = lonMetres + semiMajMetres * Math.Cos(theta) * Math.Cos(radians) - semiMinMetres * Math.Sin(theta) * Math.Sin(radians);
var lat = latMetres + semiMajMetres * Math.Cos(theta) * Math.Sin(radians) + semiMinMetres * Math.Sin(theta) * Math.Cos(radians);
lat /= 110575; // convert metres back to degrees
lon /= 111303;
// Create your POLYGON string with these values in format POLYGON((lon lat, lon lat, lon lat, lon lat))
// Note that the last coordinate set MUST be identical to the first coordinate set - confirm this and rectify the last coordinate double precision, if required
}
现在创建地理对象:
DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON(([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue]))', 4326);
SELECT @g;
我希望在 SQL Server 2008 R2 中创建一个表示椭圆的空间对象。
我有点坐标、最小值和长轴值。
我能找到的最接近的内置函数是 STBuffer,它在该点周围创建了一个缓冲半径,例如:
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.360 47.656)', 4326);
SELECT @g.STBuffer(5);
我错过了什么吗?这看起来很基本。
我真的不想创建一组多边形坐标来表示这个形状 - 这看起来太过分了。
提前致谢。
这是不可能的。我通过在 C# 中创建 WKT Polygon 字符串表示形式解决了这个问题。
公式总结如下:
var step = 2*Math.PI/40; // creates 40 points (1 for each "step")
var radians = 5.868;
var semiMajMetres = 400;
var semiMinMetres = 200;
var latMetres = latVal*110575; // converts degree value to metres value
var lonMetres = lonVal*111303; // assumes you have variables with these known values
for(double theta = 0; theta <= 2 * Math.PI; theta += step)
{
var lon = lonMetres + semiMajMetres * Math.Cos(theta) * Math.Cos(radians) - semiMinMetres * Math.Sin(theta) * Math.Sin(radians);
var lat = latMetres + semiMajMetres * Math.Cos(theta) * Math.Sin(radians) + semiMinMetres * Math.Sin(theta) * Math.Cos(radians);
lat /= 110575; // convert metres back to degrees
lon /= 111303;
// Create your POLYGON string with these values in format POLYGON((lon lat, lon lat, lon lat, lon lat))
// Note that the last coordinate set MUST be identical to the first coordinate set - confirm this and rectify the last coordinate double precision, if required
}
现在创建地理对象:
DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON(([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue], POINT([lonValue] [latValue]))', 4326);
SELECT @g;