创建描述矩形的DbGeography

Lie*_*iel 3 c# sql-server entity-framework spatial

我有一个描述矩形的两点:
东北纬度/长度和西南纬度/长度.

生成可以存储在DbGeography字段中的简单矩形实体的正确有效方法是什么?

请注意,稍后我想使用该字段来确定POINT是否在此Rectangle内.

我意识到我应该使用DbGeography.FromText(...)方法,但我不确定如何.

pso*_*usa 8

FromText方法需要WKT表示,在本例中为多边形:

像这样的东西应该做的伎俩:

DbGeography box = DbGeography.FromText(
    string.Format("POLYGON(({0} {1}, {0} {2}, {3} {2}, {3} {1}, {0} {1}))",
                         nwLongitude, 
                         nwLatitude,
                         seLatitude,
                         seLongitude), 4326);
Run Code Online (Sandbox Code Playgroud)