SQL Server Developer Center > SQL Server Forums > SQL Server Spatial > How to get a hemisphere with specified point as the center?
Ask a questionAsk a question
 

AnswerHow to get a hemisphere with specified point as the center?

  • Friday, October 09, 2009 8:01 PMwimpy1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Imagine looking at a round globe.  You can only see one "hemisphere" and the center point would be the middle of the visible area. The other hemisphere would not be visible because it would be on the "back" of the globe relative to your observation point.

    Is there a way to create a SQL2008 geography polygon object that corresponds to the "visible" side, centered on a specified lat/long?

Answers

  • Saturday, October 10, 2009 6:59 AMtanoshimiAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi there wimpy,

    I think that the reason why you think the results look a bit funny is that p3 is not the north pole - it's the point (0,0), which lies on the equator and the prime meridian. When you buffer p3 by a distance equal to approximately quarter the circumference of the earth, your results are therefore as follows:


    If you wanted to create a polygon representing the north pole, then you want to buffer the point at (90,0) instead:


    A couple of things to remember:
     - WKT syntax lists coordinate in longitude - latitude order. However, the parameters to the Point() method are latitude, longitude, SRID. Therefore the north pole is geography::Point(90, 0, 4326)
     - No geography polygon can exceed a single hemisphere, if you attempt to create a polygon exceeding this you'll get a NULL result. (This is not a limit of STBuffer(), but of any method that creates a geography instance - you can't STUnion()  two geography instances if the result would exceed this, for instance)
     - The EnvelopeAngle() method will return the greatest angle between any point in a geography instance and the centre of that geography instance. Since the geography cannot cover more than half the surface of the earth, the maximum allowed value of EnvelopeAngle() is 90. In your case, you've currently got 89.32. To get as close to covering a whole hemisphere, you can reduce the 75,000 adjustment down a bit until you get the value as close to 90 as possible.
    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked As Answer bywimpy1 Saturday, October 10, 2009 11:31 AM
    •  

All Replies

  • Friday, October 09, 2009 9:54 PMwimpy1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Trying a couple hacks raise a few additional questions.

    Thinking that it might be possible to trick STBuffer, I tried to get the distance from two points on opposite sides of the earth and though half the distance would approximate a hemisphere.  It looks like STBuffer has some internal max distance which when exceeded generates a NULL geography.

    Subtracting some arbitrary amounts, I was able to produce a polygon.  I then thought I'd check the results and use a point on the north pole as the center.  I was guessing that buffering a point on the north pole would produce a polygon with vertices having relatively consistent latitudes and longitudes wrapping around the globe, but got some results that look funny (might be just goofy behavior when at pole)

     

    private void cmdHemi_Click(object sender, EventArgs e)

    {

     

    SqlGeography p1 = SqlGeography.Point(0, 90, 4326);

     

    SqlGeography p2 = SqlGeography.Point(0, -90, 4326);

     

    double dist = p1.STDistance(p2).Value;

     

    double halfDist = dist/2.0 - 75000;

     

    SqlGeography hemi = p1.STBuffer(halfDist);

     

    Debug.WriteLine(hemi);

     

    SqlGeography p3 = SqlGeography.Point(0, 0, 4326);

     

    double len = 9926965.7291203216;

     

    SqlGeography hemiFromNorthPole = p3.STBuffer(len);

     

    Debug.WriteLine(hemiFromNorthPole);

    }

    hemiFromNorthPole produces a polygon with the following vertices
    -89.111226497412773 -1.578758245028375,
     -89.107055828517375 -7.8937895850538862,
     -89.09692763529921 -14.208833155754391,
     -89.079833528534891 -20.523889610929352,
     -89.054013862878 -26.838959135021479,
     -89.016633739746268 -33.154029648867635,
     -88.963238800311217 -39.469080616725385,
     -88.886671159044127 -45.784067350302692,
     -88.774876996003215 -52.098913205796173,
     -88.6061316798865 -58.413487794534227,
     -88.336976087180076 -64.727523072600036,
     -87.866204875046179 -71.040423931278113,
     -86.890937062638244 -77.350400898644466,
     -83.907599574034393 -83.648628586934308,
     0 -89.32992645071117,
     83.907599574034393 -83.648628586934308,
     86.890937062638244 -77.350400898644466,
     87.866204875046179 -71.040423931278113,
     88.336976087180076 -64.727523072600036,
     88.6061316798865 -58.413487794534227,
     88.774876996003215 -52.098913205796173,
     88.886671159044127 -45.784067350302692,
     88.963238800311217 -39.469080616725385,
     89.016633739746268 -33.154029648867635,
     89.054013862878 -26.838959135021479,
     89.079833528534891 -20.523889610929352,
     89.09692763529921 -14.208833155754391,
     89.107055828517375 -7.8937895850538862,
     89.111226497412773 -1.578758245028375,
     89.1098443797248 4.73627282349566,
     89.102783988314286 11.051310997697657,
     89.089340970089822 17.366359477562543,
     89.068161990829168 23.681422011308783,
     89.036999133286741 29.996494867132263,
     88.992302652071885 36.311561332973582,
     88.928453044086737 42.626585148797446,
     88.836221623421125 48.941514638404378,
     88.699599077228982 55.25624644394108,
     88.4883298086856 61.570599696224242,
     88.137629876318428 67.884179232538742,
     87.479440447905475 74.19599794441703,
     85.8997757626468 80.502446892999828,
     78.002151822054046 86.771728325369523,
     -78.002151822054046 86.771728325369523,
     -85.8997757626468 80.502446892999828,
     -87.479440447905475 74.19599794441703,
     -88.137629876318428 67.884179232538742,
     -88.4883298086856 61.570599696224242,
     -88.699599077228982 55.25624644394108,
     -88.836221623421125 48.941514638404378,
     -88.928453044086737 42.626585148797446,
     -88.992302652071885 36.311561332973582,
     -89.036999133286741 29.996494867132263,
     -89.068161990829168 23.681422011308783,
     -89.089340970089822 17.366359477562543,
     -89.102783988314286 11.051310997697657,
     -89.1098443797248 4.73627282349566,
     -89.111226497412773 -1.578758245028375

  • Saturday, October 10, 2009 6:59 AMtanoshimiAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi there wimpy,

    I think that the reason why you think the results look a bit funny is that p3 is not the north pole - it's the point (0,0), which lies on the equator and the prime meridian. When you buffer p3 by a distance equal to approximately quarter the circumference of the earth, your results are therefore as follows:


    If you wanted to create a polygon representing the north pole, then you want to buffer the point at (90,0) instead:


    A couple of things to remember:
     - WKT syntax lists coordinate in longitude - latitude order. However, the parameters to the Point() method are latitude, longitude, SRID. Therefore the north pole is geography::Point(90, 0, 4326)
     - No geography polygon can exceed a single hemisphere, if you attempt to create a polygon exceeding this you'll get a NULL result. (This is not a limit of STBuffer(), but of any method that creates a geography instance - you can't STUnion()  two geography instances if the result would exceed this, for instance)
     - The EnvelopeAngle() method will return the greatest angle between any point in a geography instance and the centre of that geography instance. Since the geography cannot cover more than half the surface of the earth, the maximum allowed value of EnvelopeAngle() is 90. In your case, you've currently got 89.32. To get as close to covering a whole hemisphere, you can reduce the 75,000 adjustment down a bit until you get the value as close to 90 as possible.
    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked As Answer bywimpy1 Saturday, October 10, 2009 11:31 AM
    •  
  • Saturday, October 10, 2009 11:31 AMwimpy1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    As Homer Simpson would say - "DOH!"  Thanks for spotting my typo on the north pole and the info in EnvelopeAngle.   I had not yet messed with EnvelopeAngle, but that will be helpful.

    Too much coding an not enough sleep, I should have thought to do the check in TSQL rather than C# since using the spatial results map makes my mistake apparent...