POLYGON中的EntityFramework和Spatial Search POINT

时间:2014-07-09 04:29:07

标签: linq entity-framework-5 spatial

我有一个名为Shop的实体,它有一个名为Position

的DBGeorgpraphy列

数据库中的样本商店的位置值为POINT(145.034242 -37.825519)

我正在尝试检索多边形内的所有商店。

var polygon = DbGeography.PolygonFromText(@"POLYGON((145.2898592378906 -37.66376896413059,
                                                     145.2898592378906 -37.93504877166811, 
                                                     144.7075838472656 -37.93504877166811, 
                                                     144.7075838472656 -37.66376896413059, 
                                                     145.2898592378906 -37.66376896413059))", 
                                                     4326);

var shops = db.Shops.Where(p => p.Position.Intersects(polygon));

我希望样品店能够包含在结果中,但事实并非如此。谁能开导我?

1 个答案:

答案 0 :(得分:4)

答案是以相反的方向构造多边形,即逆时针方向。

var polygon = DbGeography.PolygonFromText(@"POLYGON((145.2898592378906 -37.66376896413059,
                                                     144.7075838472656 -37.66376896413059,
                                                     144.7075838472656 -37.93504877166811,
                                                     145.2898592378906 -37.93504877166811, 
                                                     145.2898592378906 -37.66376896413059))", 
                                                     4326);