As you can see in the following, the result of the geography polygon is different from the geometry polygon. What I want is the yellow square, but what I'm getting is the green square. Is there any way to achieve this?
If I create a geography polygon it returns the expected area but with curves, which I don't want. Why is the result of my geometry polygon different from my geography polygon? Is it possible to create a geometry polygon that crosses the dateline?
I know that geography polygons should be anticlockwise. I tried both clockwise and anticlockwise direction for my geometry polygon and the result was the same. How can I set the direction of the geometry polygon?
declare @maxLat varchar(50);
declare @minLong varchar(50);
declare @minLat varchar(50);
declare @maxLong varchar(50);
set @maxLat ='-17.041470974676777'
set @minLong ='107.1076781691894'
set @minLat ='-41.6281068235708'
set @maxLong='-169.2204468308106'
declare @boundingRectGeography varchar(1000)
SET @boundingRectGeography = 'POLYGON((' + @minLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @minLat + '))'
DECLARE @BoundsGeography AS Geography =GEOGRAPHY::STPolyFromText(@boundingRectGeography,4326)
select @BoundsGeography
DECLARE @boundingRectGeometry varchar(1000)
SET @boundingRectGeometry = 'POLYGON((' + @minLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @minLat + ', ' +
@maxLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @maxLat + ', ' +
@minLong + ' ' + @minLat + '))'
DECLARE @BoundsGeometry AS geometry =geometry::STPolyFromText(@boundingRectGeometry,4326)
select @BoundsGeometry
To give you some background, I have list of landmarks (latitude, longitude) that I want to load on Google Maps. Since there are too many landmarks, I cannot return all of them at once. I need to return the landmarks that are in the areas that are visible to the user, in their viewing boundary.
I'm getting north/west (maximum latitude, mininmum longitude) and south/east (minimum latitude, maximum longitude) of a Google Maps boundary and sending it to my stored procedure to return back the list of the landmarks within that boundary. However, as I explained above I have issues and I need your help.
@dotMorten
kindly looked into my issue and suggested to add +360 to my maxLong
. I added the following longitude before creating my polygon but it's not working in all scenarios like this following set of latitudes and longitudes:
set @maxLat ='69.00668202899128'
set @minLong ='158.5892594884939'
set @minLat ='-17.38989745726571'
set @maxLong='133.2767594884939'
set @maxLong=convert(VARCHAR(20), convert(float,@maxLong) +360 )