比如说,我们有一个覆盖俄罗斯领土的多边形(通过谷歌地图地理编码):
POLYGON ((19.64053 41.18535, -169.0465 41.18535, -169.0465 81.85812, 19.64053 81.85812, 19.64053 41.18535))
这个多边形与北半球和两个相对的半球相交:东半球和西半球。
让我们在西伯利亚的某个地方举个例子:
POINT (93.3252301 56.1171069)
并检查西伯利亚仍然留在俄罗斯:
var russia = DbGeography.FromText("POLYGON ((19.64053 41.18535, -169.0465 41.18535, -169.0465 81.85812, 19.64053 81.85812, 19.64053 41.18535))", 4326);
var point = DbGeography.FromText("POINT (93.3252301 56.1171069)", 4326);
var isSiberiaInRussia = russia.Intersects(point);
// isSiberiaInRussia equals false, and it's wrong.
让我们取一个仅与北半球和东半球相交的多边形。让它成为莫斯科:
POLYGON ((37.31933 55.48993, 37.94566 55.48993, 37.94566 56.00966, 37.31933 56.00966, 37.31933 55.48993))
并带走一个躺在那里的人:
POINT (37.622504899999967 55.753602)
让我们检查一下:
var moscow = DbGeography.FromText("POLYGON ((37.31933 55.48993, 37.94566 55.48993, 37.94566 56.00966, 37.31933 56.00966, 37.31933 55.48993))", 4326);
var lenin = DbGeography.FromText("POINT (37.622504899999967 55.753602)", 4326);
var isLeninLaysInMoscow = moscow.Intersects(lenin);
// He's still there...
那么,有没有办法进行满足以下条件的地理命中测试:
- 与 LINQ 兼容
- 兼容 EF Code First