I want to find the shortest distance between two SqlGeography polygon. I know there is a method ShortestLineTo
(https://msdn.microsoft.com/en-us/library/ff929252.aspx) but it gives empty string while doing so.
Can anyone suggest me some alternate way to do so?
相关问题
- Sorting 3 numbers without branching [closed]
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Graphics.DrawImage() - Throws out of memory except
- Difference between Types.INTEGER and Types.NULL in
You should define a
GEOGRAPHY
in Counter Clockwise order. If you define it CW, it will be all the world except the region you are defining:@G1: point order is CCW so @G1 is a polygon containing
POINT(2,2)
@G2: point order is CCW so @G2 is a polygon containing
POINT(44.5,45.5)
@G3: point order is CW so @G3 is a polygon containing the entire world except the @G2 polygon. It also contains the @G1 polygon, so the shortest distance between @G1 and @G3 doesn't have any meaning.
Toggle Between CW and CCW geometries
Using the
ReorientObject()
method, you can toggle between CW and CCW geographies. So if you try:The result would be
GEOMETRYCOLLECTION EMPTY
because they contain the same region. So they intersect and the result ofShortestLineTo
returns aLINESTRING EMPTY
because they intersect each other.One more point
You can check if a polygon contains too large of a region by checking the
EnvelopeAngle
so you are made aware of mistakenly defined geographies.As shown in the picture,
EnvelopeAngle=180
means that polygon contains a very large region of the world.Use ShortestLineTo