【发布时间】:2022-01-18 15:11:11
【问题描述】:
所有,我正在为我的项目使用 NetTopologySuite/Entity Asp Core。我想为“searchArea”创建一个半径为 1000 米的半径,当我运行应用程序时,它给了我一个错误: System.ArgumentException:写入 SQL Server 地理值时,多边形的外壳必须逆时针方向。
public IActionResult Structures()
{
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var searchAreCoordinate = new NetTopologySuite.Geometries.Coordinate(-1.3190967394026893, 51.748851810406954); // Not sure if long-lat or lat-long.
var searchArea = geometryFactory.CreatePoint(searchAreCoordinate).Buffer(1000); // To me, this is 1000 meters because the SRID is WGS84.
var nearestStructures = _context.Structure
.OrderBy(s=>s.Coordinates.Distance(searchArea))
// .Where (s=>s.Coordinates.Intersects(searchArea)) // This is why i want to buffer the searchArea to get the result from this intersetion
.Take(10).ToList();
return View(nearestStructures);
// return View(_context.Structure.ToList());
}
我的观点
@model IEnumerable<Structures>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(Model=>Model.Id)
</th>
<th>
@Html.DisplayNameFor(Model=>Model.gml_id)
</th>
<th>
@Html.DisplayNameFor(Model=>Model.structure)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(Model=>item.Id)
</td>
<td>
@Html.DisplayFor(Model=>item.gml_id)
</td>
<td>
@Html.DisplayFor(Model=>item.structure)
</td>
</tr>
}
</tbody>
</table>
ps:我可以使用 SQL Spatial 实现此查询,如下所示:我知道不同的变量名称但相同的概念 p2:2 我的 SQL 表中的数据是地理
declare @meters int = 0.5/ 0.0006213712 select @meters as meters
declare @vehicle geography= geography::Point(51.748851810406954,-1.3190967394026893,4326).STBuffer(@meters) select @vehicle as Vehicle_Geo
select Id,gml_id,Coordinates,Long,Lat,structure from [dbo].[Structure] where @vehicle.STIntersects(Coordinates) =1
【问题讨论】:
标签: sql entity-framework asp.net-core geojson nettopologysuite