从最小和最大lat/long创建多边形(矩形)。

时间:2022-04-04 20:11:18

Given a lat/lon representing a South West point and a lat/lon representing a North East point When I create a polygon Then it should work in SQL 2008...

给定一个代表西南点的lat/lon和一个代表东北点的lat/lon,当我创建一个多边形时,它应该可以在SQL 2008中使用……

Here's my SQL:

这是我的SQL:

   DECLARE @minX varchar(10) = N'49.871159'
    DECLARE @maxX varchar(10) = N'55.811741'
    DECLARE @minY varchar(10) = N'-6.379880'
    DECLARE @maxY varchar(10) = N'1.768960'

    DECLARE @boundingRect varchar(150)
    SET @boundingRect = 'POLYGON((' + @minX + ' '  + @minY + ', ' + @minX + ' ' + @maxY + ', ' + @maxX + ' ' + @maxY + ', ' + @maxX + ' ' + @minY + ', ' + @minX + ' ' + @minY + '))'
    SELECT GEOGRAPHY::Parse(@boundingRect)

But it is giving me the following error: "The specified input does not represent a valid geography instance because it exceeds a single hemisphere."

但它给了我以下错误:“指定的输入不能表示有效的地理实例,因为它超出了一个半球。”

Can anyone tell me what I'm doing wrong? The bounding rectangle in my example should be roughly covering the UK and my assumption is that I need to specify 5 points - bottom left, top left, top right, bottom right and back to the bottom left again.

有人能告诉我我做错了什么吗?我的例子中的边界矩形应该大致覆盖英国,我的假设是,我需要指定5个点——左下角,左上方,右上角,右下角,再回到左下角。

1 个解决方案

#1


5  

First off this is unrelated to you crossing the Prime Meridian in your rectangle and being in both the Eastern and Western Hemisphere. That's just a coincidence.

首先,这与你在矩形中穿越本初子午线并同时在东半球和西半球无关。这只是一个巧合。

SQL Geography uses the left-hand rule, so that as an observer walks your ring in the order provided, the inside of the shape is always to their left. For exterior rings, this means that the ring is defined in counter-clockwise order. What your original rectangle is, by this rule, is the entire world outside of the UK, which of course is more than a hemisphere. :)

SQL Geography使用左手规则,当观察者按照给定的顺序移动戒指时,形状的内部总是在左边。对于外环,这意味着环的定义是逆时针的。根据这个规则,原始矩形是指英国以外的整个世界,当然,它比一个半球还重要。:)

So just change the order of your points in the POLYGON statement, (also, I switched your X and Y values, it doesn't affect the validity of the statement, but it makes the map come out looking like a long/lat for the UK)

所以只要改变多边形语句中点的顺序(同时,我交换了你的X和Y值,它不会影响语句的有效性,但它会让地图看起来像英国的长/低)

DECLARE @minY varchar(10) = N'49.871159'
DECLARE @maxY varchar(10) = N'55.811741'
DECLARE @minX varchar(10) = N'-6.379880'
DECLARE @maxX varchar(10) = N'1.768960'

DECLARE @boundingRect varchar(150)
SET @boundingRect = 'POLYGON((' + @minX + ' '  + @minY + ', ' + 
                                                   @maxX + ' ' + @minY + ', ' + 
                                                   @maxX + ' ' + @maxY + ', ' + 
                                                   @minX + ' ' + @maxY + ', ' + 
                                                   @minX + ' ' + @minY + '))'

#1


5  

First off this is unrelated to you crossing the Prime Meridian in your rectangle and being in both the Eastern and Western Hemisphere. That's just a coincidence.

首先,这与你在矩形中穿越本初子午线并同时在东半球和西半球无关。这只是一个巧合。

SQL Geography uses the left-hand rule, so that as an observer walks your ring in the order provided, the inside of the shape is always to their left. For exterior rings, this means that the ring is defined in counter-clockwise order. What your original rectangle is, by this rule, is the entire world outside of the UK, which of course is more than a hemisphere. :)

SQL Geography使用左手规则,当观察者按照给定的顺序移动戒指时,形状的内部总是在左边。对于外环,这意味着环的定义是逆时针的。根据这个规则,原始矩形是指英国以外的整个世界,当然,它比一个半球还重要。:)

So just change the order of your points in the POLYGON statement, (also, I switched your X and Y values, it doesn't affect the validity of the statement, but it makes the map come out looking like a long/lat for the UK)

所以只要改变多边形语句中点的顺序(同时,我交换了你的X和Y值,它不会影响语句的有效性,但它会让地图看起来像英国的长/低)

DECLARE @minY varchar(10) = N'49.871159'
DECLARE @maxY varchar(10) = N'55.811741'
DECLARE @minX varchar(10) = N'-6.379880'
DECLARE @maxX varchar(10) = N'1.768960'

DECLARE @boundingRect varchar(150)
SET @boundingRect = 'POLYGON((' + @minX + ' '  + @minY + ', ' + 
                                                   @maxX + ' ' + @minY + ', ' + 
                                                   @maxX + ' ' + @maxY + ', ' + 
                                                   @minX + ' ' + @maxY + ', ' + 
                                                   @minX + ' ' + @minY + '))'